|
@ -23,6 +23,7 @@ type TxQuery struct { |
|
|
join [][]string //[["tablea as a","a.id=b.id","left"]]
|
|
|
join [][]string //[["tablea as a","a.id=b.id","left"]]
|
|
|
data []string |
|
|
data []string |
|
|
value []interface{} |
|
|
value []interface{} |
|
|
|
|
|
save_data []map[string]interface{} |
|
|
orderby string |
|
|
orderby string |
|
|
groupby string |
|
|
groupby string |
|
|
page int |
|
|
page int |
|
@ -117,6 +118,14 @@ func (this *TxQuery) Value(value interface{}) *TxQuery { |
|
|
this.value = append(this.value, value) |
|
|
this.value = append(this.value, value) |
|
|
return this |
|
|
return this |
|
|
} |
|
|
} |
|
|
|
|
|
func (this *TxQuery) saveData(value map[string]interface{}) *TxQuery { |
|
|
|
|
|
this.save_data = append(this.save_data, value) |
|
|
|
|
|
return this |
|
|
|
|
|
} |
|
|
|
|
|
func (this *TxQuery) saveDatas(value []map[string]interface{}) *TxQuery { |
|
|
|
|
|
this.save_data = append(this.save_data, value...) |
|
|
|
|
|
return this |
|
|
|
|
|
} |
|
|
func (this *TxQuery) Values(values []interface{}) *TxQuery { |
|
|
func (this *TxQuery) Values(values []interface{}) *TxQuery { |
|
|
this.value = append(this.value, values...) |
|
|
this.value = append(this.value, values...) |
|
|
return this |
|
|
return this |
|
@ -363,24 +372,43 @@ func (this *TxQuery) CreateAllStmt() error { |
|
|
dbName := getTableName(this.dbname, this.table) |
|
|
dbName := getTableName(this.dbname, this.table) |
|
|
|
|
|
|
|
|
var sql string |
|
|
var sql string |
|
|
|
|
|
var dataSql = []string{} |
|
|
|
|
|
var valSql = []string{} |
|
|
|
|
|
if len(this.save_data) > 0 { |
|
|
|
|
|
this.data = []string{} |
|
|
|
|
|
this.value = []interface{}{} |
|
|
|
|
|
for i, datum := range this.save_data { |
|
|
|
|
|
for s, v := range datum { |
|
|
|
|
|
if i == 0 { |
|
|
|
|
|
this.data = append(this.data, s) |
|
|
|
|
|
dataSql = append(dataSql, "?") |
|
|
|
|
|
} |
|
|
|
|
|
this.value = append(this.value, v) |
|
|
|
|
|
} |
|
|
|
|
|
valSql = append(valSql, "("+strings.Join(dataSql, " , ")+")") |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
for i := 0; i < len(this.data); i++ { |
|
|
|
|
|
dataSql = append(dataSql, "?") |
|
|
|
|
|
} |
|
|
|
|
|
valSql = append(valSql, "("+strings.Join(dataSql, " , ")+")") |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
sql = helper.StringJoin("insert into ", dbName, " (", strings.Join(this.data, " , ")+")") |
|
|
|
|
|
|
|
|
if len(this.data) == 0 { |
|
|
|
|
|
return errors.New("参数错误,没有数据表") |
|
|
|
|
|
} |
|
|
if len(this.value) == 0 { |
|
|
if len(this.value) == 0 { |
|
|
return errors.New("参数错误,条件值错误") |
|
|
return errors.New("参数错误,条件值错误") |
|
|
} |
|
|
} |
|
|
var valueSql = []string{} |
|
|
|
|
|
var dataSql = []string{} |
|
|
|
|
|
for i := 0; i < len(this.data); i++ { |
|
|
|
|
|
dataSql = append(valueSql, "?") |
|
|
|
|
|
|
|
|
setText := " values " |
|
|
|
|
|
if len(valSql) > 1 { |
|
|
|
|
|
setText = " value " |
|
|
} |
|
|
} |
|
|
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) |
|
|
|
|
|
|
|
|
sql = helper.StringJoin("insert into ", dbName, " (", strings.Join(this.data, " , "), ")", setText, strings.Join(valSql, ",")) |
|
|
|
|
|
if len(this.value) == 0 { |
|
|
|
|
|
return errors.New("参数错误,条件值错误") |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if this.debug { |
|
|
if this.debug { |
|
|
log.Println("insert sql:", sql, this.value) |
|
|
log.Println("insert sql:", sql, this.value) |
|
|
} |
|
|
} |
|
|