|
|
@ -26,8 +26,19 @@ type Query struct { |
|
|
|
page int |
|
|
|
page_size int |
|
|
|
stmt *sql.Stmt |
|
|
|
conn *sql.DB |
|
|
|
} |
|
|
|
|
|
|
|
func NewQuery() *Query { |
|
|
|
return &Query{ |
|
|
|
conn: DB, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
func (this *Query) Conn(conn *sql.DB) *Query { |
|
|
|
this.conn = conn |
|
|
|
return this |
|
|
|
} |
|
|
|
func (this *Query) Db(dbname string) *Query { |
|
|
|
this.dbname = dbname |
|
|
|
return this |
|
|
@ -183,7 +194,11 @@ func (this *Query) QueryStmt() error { |
|
|
|
return errors.New("参数错误,条件值错误") |
|
|
|
} |
|
|
|
|
|
|
|
stmt, err = DB.Prepare(sql) |
|
|
|
if this.conn == nil { |
|
|
|
this.conn = DB |
|
|
|
} |
|
|
|
|
|
|
|
stmt, err = this.conn.Prepare(sql) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
return err |
|
|
@ -226,7 +241,11 @@ func (this *Query) UpdateStmt() error { |
|
|
|
return errors.New("参数错误,条件值错误") |
|
|
|
} |
|
|
|
|
|
|
|
stmt, err = DB.Prepare(sql) |
|
|
|
if this.conn == nil { |
|
|
|
this.conn = DB |
|
|
|
} |
|
|
|
|
|
|
|
stmt, err = this.conn.Prepare(sql) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
return err |
|
|
@ -264,7 +283,11 @@ func (this *Query) CreateStmt() error { |
|
|
|
return errors.New("参数错误,条件值错误") |
|
|
|
} |
|
|
|
|
|
|
|
stmt, err = DB.Prepare(sql) |
|
|
|
if this.conn == nil { |
|
|
|
this.conn = DB |
|
|
|
} |
|
|
|
|
|
|
|
stmt, err = this.conn.Prepare(sql) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
return err |
|
|
@ -312,7 +335,11 @@ func (this *Query) DeleteStmt() error { |
|
|
|
return errors.New("参数错误,条件值错误") |
|
|
|
} |
|
|
|
|
|
|
|
stmt, err = DB.Prepare(sql) |
|
|
|
if this.conn == nil { |
|
|
|
this.conn = DB |
|
|
|
} |
|
|
|
|
|
|
|
stmt, err = this.conn.Prepare(sql) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|