|
|
@ -353,6 +353,49 @@ func (this *TxQuery) CreateStmt() error { |
|
|
|
return nil |
|
|
|
} |
|
|
|
|
|
|
|
// 拼批量插入sql
|
|
|
|
func (this *TxQuery) CreateAllStmt() error { |
|
|
|
|
|
|
|
if this.dbname == "" && this.table == "" { |
|
|
|
return errors.New("参数错误,没有数据表") |
|
|
|
} |
|
|
|
|
|
|
|
dbName := getTableName(this.dbname, this.table) |
|
|
|
|
|
|
|
var sql string |
|
|
|
|
|
|
|
sql = helper.StringJoin("insert into ", dbName, " (", strings.Join(this.data, " , ")+")") |
|
|
|
if len(this.value) == 0 { |
|
|
|
return errors.New("参数错误,条件值错误") |
|
|
|
} |
|
|
|
var valueSql = []string{} |
|
|
|
var dataSql = []string{} |
|
|
|
for i := 0; i < len(this.data); i++ { |
|
|
|
dataSql = append(valueSql, "?") |
|
|
|
} |
|
|
|
dataSqlText := "(" + strings.Join(dataSql, " , ") + ")" |
|
|
|
for i := 0; i < len(this.value); i++ { |
|
|
|
valueSql = append(valueSql, dataSqlText) |
|
|
|
} |
|
|
|
sql = sql + " " + strings.Join(valueSql, " , ") |
|
|
|
if this.debug { |
|
|
|
log.Println("insert sql:", sql, this.value) |
|
|
|
} |
|
|
|
if this.debug { |
|
|
|
log.Println("insert sql:", sql, this.value) |
|
|
|
} |
|
|
|
|
|
|
|
stmt, err = this.tx.Prepare(sql) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
|
|
|
|
this.stmt = stmt |
|
|
|
|
|
|
|
return nil |
|
|
|
} |
|
|
|
|
|
|
|
// 拼删除sql
|
|
|
|
func (this *TxQuery) DeleteStmt() error { |
|
|
|
|
|
|
@ -477,6 +520,20 @@ func (this *TxQuery) Create() (int64, error) { |
|
|
|
return StmtForInsertExec(this.stmt, this.value) |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 执行批量写入 |
|
|
|
* return is_insert error |
|
|
|
*/ |
|
|
|
func (this *TxQuery) CreateAll() (int64, error) { |
|
|
|
|
|
|
|
err := this.CreateAllStmt() |
|
|
|
if err != nil { |
|
|
|
return 0, err |
|
|
|
} |
|
|
|
|
|
|
|
return StmtForInsertExec(this.stmt, this.value) |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 提交 |
|
|
|
*/ |
|
|
|