Browse Source

添加子查询

master
zhenghaorong 2 years ago
parent
commit
4f6940cc58
2 changed files with 36 additions and 10 deletions
  1. +17
    -5
      chain.go
  2. +19
    -5
      transaction_chain.go

+ 17
- 5
chain.go View File

@ -154,11 +154,10 @@ func (this *Query) Clean() *Query {
return this return this
} }
// 拼查询sql
func (this *Query) QueryStmt() error {
//构造子查询
func (this *Query) BuildSelectSql() (map[string]interface{}, error) {
if this.dbname == "" && this.table == "" { if this.dbname == "" && this.table == "" {
return errors.New("参数错误,没有数据表")
return nil, errors.New("参数错误,没有数据表")
} }
table := getTableName(this.dbname, this.table, this.dbtype) table := getTableName(this.dbname, this.table, this.dbtype)
@ -237,9 +236,22 @@ func (this *Query) QueryStmt() error {
} }
} }
if condition_len != len(this.value) { if condition_len != len(this.value) {
return errors.New("参数错误,条件值错误")
return nil, errors.New("参数错误,条件值错误")
} }
return map[string]interface{}{
"sql": sql,
"value": this.value,
}, nil
}
// 拼查询sql
func (this *Query) QueryStmt() error {
res := map[string]interface{}{}
res, err = this.BuildSelectSql()
if err != nil {
return err
}
sql := helper.ToStr(res["sql"])
if this.conn == nil { if this.conn == nil {
this.conn = DB this.conn = DB
} }


+ 19
- 5
transaction_chain.go View File

@ -155,11 +155,10 @@ func (this *TxQuery) Clean() *TxQuery {
return this return this
} }
// 拼查询sql
func (this *TxQuery) QueryStmt() error {
//构造子查询
func (this *TxQuery) BuildSelectSql() (map[string]interface{}, error) {
if this.dbname == "" && this.table == "" { if this.dbname == "" && this.table == "" {
return errors.New("参数错误,没有数据表")
return nil, errors.New("参数错误,没有数据表")
} }
table := getTableName(this.dbname, this.table) table := getTableName(this.dbname, this.table)
@ -238,8 +237,23 @@ func (this *TxQuery) QueryStmt() error {
} }
} }
if condition_len != len(this.value) { if condition_len != len(this.value) {
return errors.New("参数错误,条件值错误")
return nil, errors.New("参数错误,条件值错误")
}
return map[string]interface{}{
"sql": sql,
"value": this.value,
}, nil
}
// 拼查询sql
func (this *TxQuery) QueryStmt() error {
res := map[string]interface{}{}
res, err = this.BuildSelectSql()
if err != nil {
return err
} }
sql := helper.ToStr(res["sql"])
stmt, err = this.tx.Prepare(sql + " FOR UPDATE") stmt, err = this.tx.Prepare(sql + " FOR UPDATE")


Loading…
Cancel
Save