|
@@ -244,7 +244,8 @@ func (d *DB) Rollback() (err error) {
|
|
|
|
|
|
// TransExec trans execute with named args
|
|
// TransExec trans execute with named args
|
|
func (d *DB) TransExec(query string, args interface{}) (LastInsertId, RowsAffected int64, err error) {
|
|
func (d *DB) TransExec(query string, args interface{}) (LastInsertId, RowsAffected int64, err error) {
|
|
- if rs, err := d.tx.NamedExec(query, args); err == nil {
|
|
|
|
|
|
+ var rs sql.Result
|
|
|
|
+ if rs, err = d.tx.NamedExec(query, args); err == nil {
|
|
RowsAffected, _ = rs.RowsAffected()
|
|
RowsAffected, _ = rs.RowsAffected()
|
|
LastInsertId, _ = rs.LastInsertId()
|
|
LastInsertId, _ = rs.LastInsertId()
|
|
}
|
|
}
|
|
@@ -253,7 +254,8 @@ func (d *DB) TransExec(query string, args interface{}) (LastInsertId, RowsAffect
|
|
|
|
|
|
// TransExec trans execute with named args
|
|
// TransExec trans execute with named args
|
|
func (d *DB) TransExecContext(ctx context.Context, query string, args interface{}) (LastInsertId, RowsAffected int64, err error) {
|
|
func (d *DB) TransExecContext(ctx context.Context, query string, args interface{}) (LastInsertId, RowsAffected int64, err error) {
|
|
- if rs, err := d.tx.NamedExecContext(ctx, query, args); err == nil {
|
|
|
|
|
|
+ var rs sql.Result
|
|
|
|
+ if rs, err = d.tx.NamedExecContext(ctx, query, args); err == nil {
|
|
RowsAffected, _ = rs.RowsAffected()
|
|
RowsAffected, _ = rs.RowsAffected()
|
|
LastInsertId, _ = rs.LastInsertId()
|
|
LastInsertId, _ = rs.LastInsertId()
|
|
}
|
|
}
|
|
@@ -278,7 +280,8 @@ func (d *DB) TransUpdate(query string, args interface{}) (reply Reply) {
|
|
|
|
|
|
// TransRow trans get row
|
|
// TransRow trans get row
|
|
func (d *DB) TransRow(dest interface{}, query string, args interface{}) (err error) {
|
|
func (d *DB) TransRow(dest interface{}, query string, args interface{}) (err error) {
|
|
- nstmt, err := d.tx.PrepareNamed(query)
|
|
|
|
|
|
+ nstmt := new(sqlx.NamedStmt)
|
|
|
|
+ nstmt, err = d.tx.PrepareNamed(query)
|
|
if err != nil {
|
|
if err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
@@ -290,183 +293,189 @@ func (d *DB) TransRow(dest interface{}, query string, args interface{}) (err err
|
|
}
|
|
}
|
|
|
|
|
|
// Select select
|
|
// Select select
|
|
-func (d *DB) Select(dest interface{}, query string, args ...interface{}) error {
|
|
|
|
- err := d.Connect()
|
|
|
|
|
|
+func (d *DB) Select(dest interface{}, query string, args ...interface{}) (err error) {
|
|
|
|
+ err = d.Connect()
|
|
if err != nil {
|
|
if err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
defer d.Close()
|
|
defer d.Close()
|
|
|
|
|
|
err = d.conn.Select(dest, query, args...)
|
|
err = d.conn.Select(dest, query, args...)
|
|
-
|
|
|
|
- return err
|
|
|
|
|
|
+ return
|
|
}
|
|
}
|
|
|
|
|
|
// SelectContext select
|
|
// SelectContext select
|
|
-func (d *DB) SelectContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error {
|
|
|
|
- err := d.ConnectContext(ctx)
|
|
|
|
|
|
+func (d *DB) SelectContext(ctx context.Context, dest interface{}, query string, args ...interface{}) (err error) {
|
|
|
|
+ err = d.ConnectContext(ctx)
|
|
if err != nil {
|
|
if err != nil {
|
|
- return err
|
|
|
|
|
|
+ return
|
|
}
|
|
}
|
|
defer d.Close()
|
|
defer d.Close()
|
|
|
|
|
|
err = d.conn.SelectContext(ctx, dest, query, args...)
|
|
err = d.conn.SelectContext(ctx, dest, query, args...)
|
|
-
|
|
|
|
- return err
|
|
|
|
|
|
+ return
|
|
}
|
|
}
|
|
|
|
|
|
// Query get rows with named args, Query executes a query that returns rows, typically a SELECT. The args are for any placeholder parameters in the query.
|
|
// Query get rows with named args, Query executes a query that returns rows, typically a SELECT. The args are for any placeholder parameters in the query.
|
|
-func (d *DB) Query(dest interface{}, query string, args interface{}) error {
|
|
|
|
- err := d.Connect()
|
|
|
|
|
|
+func (d *DB) Query(dest interface{}, query string, args interface{}) (err error) {
|
|
|
|
+ err = d.Connect()
|
|
if err != nil {
|
|
if err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
defer d.Close()
|
|
defer d.Close()
|
|
|
|
|
|
- nstmt, err := d.conn.PrepareNamed(query)
|
|
|
|
|
|
+ nstmt := new(sqlx.NamedStmt)
|
|
|
|
+ nstmt, err = d.conn.PrepareNamed(query)
|
|
if err != nil {
|
|
if err != nil {
|
|
- return err
|
|
|
|
|
|
+ return
|
|
}
|
|
}
|
|
defer nstmt.Close()
|
|
defer nstmt.Close()
|
|
|
|
|
|
err = nstmt.Select(dest, args)
|
|
err = nstmt.Select(dest, args)
|
|
-
|
|
|
|
- return err
|
|
|
|
|
|
+ return
|
|
}
|
|
}
|
|
|
|
|
|
// QueryContext get rows with named args, QueryContext executes a query that returns rows, typically a SELECT. The args are for any placeholder parameters in the query.
|
|
// QueryContext get rows with named args, QueryContext executes a query that returns rows, typically a SELECT. The args are for any placeholder parameters in the query.
|
|
-func (d *DB) QueryContext(ctx context.Context, dest interface{}, query string, args interface{}) error {
|
|
|
|
- err := d.ConnectContext(ctx)
|
|
|
|
|
|
+func (d *DB) QueryContext(ctx context.Context, dest interface{}, query string, args interface{}) (err error) {
|
|
|
|
+ err = d.ConnectContext(ctx)
|
|
if err != nil {
|
|
if err != nil {
|
|
- return err
|
|
|
|
|
|
+ return
|
|
}
|
|
}
|
|
defer d.Close()
|
|
defer d.Close()
|
|
|
|
|
|
- nstmt, err := d.conn.PrepareNamedContext(ctx, query)
|
|
|
|
|
|
+ nstmt := new(sqlx.NamedStmt)
|
|
|
|
+ nstmt, err = d.conn.PrepareNamedContext(ctx, query)
|
|
if err != nil {
|
|
if err != nil {
|
|
- return err
|
|
|
|
|
|
+ return
|
|
}
|
|
}
|
|
defer nstmt.Close()
|
|
defer nstmt.Close()
|
|
|
|
|
|
err = nstmt.SelectContext(ctx, dest, args)
|
|
err = nstmt.SelectContext(ctx, dest, args)
|
|
-
|
|
|
|
- return err
|
|
|
|
|
|
+ return
|
|
}
|
|
}
|
|
|
|
|
|
// Rows get rows with named args
|
|
// Rows get rows with named args
|
|
-func (d *DB) Rows(dest interface{}, query string, args interface{}) error {
|
|
|
|
- err := d.Connect()
|
|
|
|
|
|
+func (d *DB) Rows(dest interface{}, query string, args interface{}) (err error) {
|
|
|
|
+ err = d.Connect()
|
|
if err != nil {
|
|
if err != nil {
|
|
- return err
|
|
|
|
|
|
+ return
|
|
}
|
|
}
|
|
defer d.Close()
|
|
defer d.Close()
|
|
|
|
|
|
- nstmt, err := d.conn.PrepareNamed(query)
|
|
|
|
|
|
+ nstmt := new(sqlx.NamedStmt)
|
|
|
|
+ nstmt, err = d.conn.PrepareNamed(query)
|
|
if err != nil {
|
|
if err != nil {
|
|
- return err
|
|
|
|
|
|
+ return
|
|
}
|
|
}
|
|
defer nstmt.Close()
|
|
defer nstmt.Close()
|
|
|
|
|
|
err = nstmt.Select(dest, args)
|
|
err = nstmt.Select(dest, args)
|
|
-
|
|
|
|
- return err
|
|
|
|
|
|
+ return
|
|
}
|
|
}
|
|
|
|
|
|
// RowsContext get rows with named args
|
|
// RowsContext get rows with named args
|
|
-func (d *DB) RowsContext(ctx context.Context, dest interface{}, query string, args interface{}) error {
|
|
|
|
- err := d.ConnectContext(ctx)
|
|
|
|
|
|
+func (d *DB) RowsContext(ctx context.Context, dest interface{}, query string, args interface{}) (err error) {
|
|
|
|
+ err = d.ConnectContext(ctx)
|
|
if err != nil {
|
|
if err != nil {
|
|
- return err
|
|
|
|
|
|
+ return
|
|
}
|
|
}
|
|
defer d.Close()
|
|
defer d.Close()
|
|
|
|
|
|
- nstmt, err := d.conn.PrepareNamedContext(ctx, query)
|
|
|
|
|
|
+ nstmt := new(sqlx.NamedStmt)
|
|
|
|
+ nstmt, err = d.conn.PrepareNamedContext(ctx, query)
|
|
if err != nil {
|
|
if err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
defer nstmt.Close()
|
|
defer nstmt.Close()
|
|
|
|
|
|
err = nstmt.SelectContext(ctx, dest, args)
|
|
err = nstmt.SelectContext(ctx, dest, args)
|
|
-
|
|
|
|
- return err
|
|
|
|
|
|
+ return
|
|
}
|
|
}
|
|
|
|
|
|
// QueryRow get row, QueryRow executes a query that is expected to return at most one row.
|
|
// QueryRow get row, QueryRow executes a query that is expected to return at most one row.
|
|
-func (d *DB) QueryRow(dest interface{}, query string, args ...interface{}) error {
|
|
|
|
- err := d.Connect()
|
|
|
|
|
|
+func (d *DB) QueryRow(dest interface{}, query string, args ...interface{}) (err error) {
|
|
|
|
+ err = d.Connect()
|
|
if err != nil {
|
|
if err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
defer d.Close()
|
|
defer d.Close()
|
|
|
|
|
|
- return d.conn.Get(dest, query, args...)
|
|
|
|
|
|
+ err = d.conn.Get(dest, query, args...)
|
|
|
|
+ return
|
|
}
|
|
}
|
|
|
|
|
|
// QueryRowContext get row, QueryRowContext executes a query that is expected to return at most one row.
|
|
// QueryRowContext get row, QueryRowContext executes a query that is expected to return at most one row.
|
|
-func (d *DB) QueryRowContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error {
|
|
|
|
- err := d.ConnectContext(ctx)
|
|
|
|
|
|
+func (d *DB) QueryRowContext(ctx context.Context, dest interface{}, query string, args ...interface{}) (err error) {
|
|
|
|
+ err = d.ConnectContext(ctx)
|
|
if err != nil {
|
|
if err != nil {
|
|
- return err
|
|
|
|
|
|
+ return
|
|
}
|
|
}
|
|
defer d.Close()
|
|
defer d.Close()
|
|
|
|
|
|
- return d.conn.GetContext(ctx, dest, query, args...)
|
|
|
|
|
|
+ err = d.conn.GetContext(ctx, dest, query, args...)
|
|
|
|
+ return
|
|
}
|
|
}
|
|
|
|
|
|
// Get get row, QueryRow executes a query that is expected to return at most one row.
|
|
// Get get row, QueryRow executes a query that is expected to return at most one row.
|
|
-func (d *DB) Get(dest interface{}, query string, args ...interface{}) error {
|
|
|
|
- err := d.Connect()
|
|
|
|
|
|
+func (d *DB) Get(dest interface{}, query string, args ...interface{}) (err error) {
|
|
|
|
+ err = d.Connect()
|
|
if err != nil {
|
|
if err != nil {
|
|
- return err
|
|
|
|
|
|
+ return
|
|
}
|
|
}
|
|
defer d.Close()
|
|
defer d.Close()
|
|
|
|
|
|
- return d.conn.Get(dest, query, args...)
|
|
|
|
|
|
+ err = d.conn.Get(dest, query, args...)
|
|
|
|
+ return
|
|
}
|
|
}
|
|
|
|
|
|
// GetContext get
|
|
// GetContext get
|
|
-func (d *DB) GetContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error {
|
|
|
|
- err := d.ConnectContext(ctx)
|
|
|
|
|
|
+func (d *DB) GetContext(ctx context.Context, dest interface{}, query string, args ...interface{}) (err error) {
|
|
|
|
+ err = d.ConnectContext(ctx)
|
|
if err != nil {
|
|
if err != nil {
|
|
- return err
|
|
|
|
|
|
+ return
|
|
}
|
|
}
|
|
defer d.Close()
|
|
defer d.Close()
|
|
|
|
|
|
- return d.conn.GetContext(ctx, dest, query, args...)
|
|
|
|
|
|
+ err = d.conn.GetContext(ctx, dest, query, args...)
|
|
|
|
+ return
|
|
}
|
|
}
|
|
|
|
|
|
// Row get row with named args
|
|
// Row get row with named args
|
|
-func (d *DB) Row(dest interface{}, query string, args interface{}) error {
|
|
|
|
- err := d.Connect()
|
|
|
|
|
|
+func (d *DB) Row(dest interface{}, query string, args interface{}) (err error) {
|
|
|
|
+ err = d.Connect()
|
|
if err != nil {
|
|
if err != nil {
|
|
- return err
|
|
|
|
|
|
+ return
|
|
}
|
|
}
|
|
defer d.Close()
|
|
defer d.Close()
|
|
|
|
|
|
- nstmt, err := d.conn.PrepareNamed(query)
|
|
|
|
|
|
+ nstmt := new(sqlx.NamedStmt)
|
|
|
|
+ nstmt, err = d.conn.PrepareNamed(query)
|
|
if err != nil {
|
|
if err != nil {
|
|
- return err
|
|
|
|
|
|
+ return
|
|
}
|
|
}
|
|
defer nstmt.Close()
|
|
defer nstmt.Close()
|
|
|
|
|
|
- return nstmt.Get(dest, args)
|
|
|
|
|
|
+ err = nstmt.Get(dest, args)
|
|
|
|
+ return
|
|
}
|
|
}
|
|
|
|
|
|
// RowContext get row with named args
|
|
// RowContext get row with named args
|
|
-func (d *DB) RowContext(ctx context.Context, dest interface{}, query string, args interface{}) error {
|
|
|
|
- err := d.ConnectContext(ctx)
|
|
|
|
|
|
+func (d *DB) RowContext(ctx context.Context, dest interface{}, query string, args interface{}) (err error) {
|
|
|
|
+ err = d.ConnectContext(ctx)
|
|
if err != nil {
|
|
if err != nil {
|
|
- return err
|
|
|
|
|
|
+ return
|
|
}
|
|
}
|
|
defer d.Close()
|
|
defer d.Close()
|
|
|
|
|
|
- nstmt, err := d.conn.PrepareNamedContext(ctx, query)
|
|
|
|
|
|
+ nstmt := new(sqlx.NamedStmt)
|
|
|
|
+ nstmt, err = d.conn.PrepareNamedContext(ctx, query)
|
|
if err != nil {
|
|
if err != nil {
|
|
- return err
|
|
|
|
|
|
+ return
|
|
}
|
|
}
|
|
defer nstmt.Close()
|
|
defer nstmt.Close()
|
|
|
|
|
|
- return nstmt.GetContext(ctx, dest, args)
|
|
|
|
|
|
+ err = nstmt.GetContext(ctx, dest, args)
|
|
|
|
+ return
|
|
}
|
|
}
|
|
|
|
|
|
// InsertReply insert and return DbReply
|
|
// InsertReply insert and return DbReply
|
|
@@ -521,6 +530,7 @@ func (d *DB) Insert(query string, args interface{}) (LastInsertId, RowsAffected
|
|
return
|
|
return
|
|
}
|
|
}
|
|
defer d.Close()
|
|
defer d.Close()
|
|
|
|
+
|
|
var rs sql.Result
|
|
var rs sql.Result
|
|
if rs, err = d.conn.NamedExec(query, args); err == nil {
|
|
if rs, err = d.conn.NamedExec(query, args); err == nil {
|
|
LastInsertId, _ = rs.LastInsertId()
|
|
LastInsertId, _ = rs.LastInsertId()
|
|
@@ -536,6 +546,7 @@ func (d *DB) InsertContext(ctx context.Context, query string, args interface{})
|
|
return
|
|
return
|
|
}
|
|
}
|
|
defer d.Close()
|
|
defer d.Close()
|
|
|
|
+
|
|
var rs sql.Result
|
|
var rs sql.Result
|
|
if rs, err = d.conn.NamedExecContext(ctx, query, args); err == nil {
|
|
if rs, err = d.conn.NamedExecContext(ctx, query, args); err == nil {
|
|
LastInsertId, _ = rs.LastInsertId()
|
|
LastInsertId, _ = rs.LastInsertId()
|
|
@@ -581,6 +592,7 @@ func (d *DB) Exec(query string, args ...interface{}) (LastInsertId, RowsAffected
|
|
return
|
|
return
|
|
}
|
|
}
|
|
defer d.Close()
|
|
defer d.Close()
|
|
|
|
+
|
|
var rs sql.Result
|
|
var rs sql.Result
|
|
if rs, err = d.conn.Exec(query, args...); err == nil {
|
|
if rs, err = d.conn.Exec(query, args...); err == nil {
|
|
LastInsertId, _ = rs.LastInsertId()
|
|
LastInsertId, _ = rs.LastInsertId()
|
|
@@ -596,6 +608,7 @@ func (d *DB) ExecContext(ctx context.Context, query string, args ...interface{})
|
|
return
|
|
return
|
|
}
|
|
}
|
|
defer d.Close()
|
|
defer d.Close()
|
|
|
|
+
|
|
var rs sql.Result
|
|
var rs sql.Result
|
|
if rs, err = d.conn.ExecContext(ctx, query, args...); err == nil {
|
|
if rs, err = d.conn.ExecContext(ctx, query, args...); err == nil {
|
|
LastInsertId, _ = rs.LastInsertId()
|
|
LastInsertId, _ = rs.LastInsertId()
|
|
@@ -611,6 +624,7 @@ func (d *DB) NamedExec(query string, args interface{}) (LastInsertId, RowsAffect
|
|
return
|
|
return
|
|
}
|
|
}
|
|
defer d.Close()
|
|
defer d.Close()
|
|
|
|
+
|
|
var rs sql.Result
|
|
var rs sql.Result
|
|
if rs, err = d.conn.NamedExec(query, args); err == nil {
|
|
if rs, err = d.conn.NamedExec(query, args); err == nil {
|
|
LastInsertId, _ = rs.LastInsertId()
|
|
LastInsertId, _ = rs.LastInsertId()
|
|
@@ -626,6 +640,7 @@ func (d *DB) NamedExecContext(ctx context.Context, query string, args interface{
|
|
return
|
|
return
|
|
}
|
|
}
|
|
defer d.Close()
|
|
defer d.Close()
|
|
|
|
+
|
|
var rs sql.Result
|
|
var rs sql.Result
|
|
if rs, err = d.conn.NamedExecContext(ctx, query, args); err == nil {
|
|
if rs, err = d.conn.NamedExecContext(ctx, query, args); err == nil {
|
|
LastInsertId, _ = rs.LastInsertId()
|
|
LastInsertId, _ = rs.LastInsertId()
|
|
@@ -656,7 +671,8 @@ func (t *Tx) Rollback() error {
|
|
|
|
|
|
// NamedExec executes a query that doesn't return rows. For example: an INSERT and UPDATE. with named args
|
|
// NamedExec executes a query that doesn't return rows. For example: an INSERT and UPDATE. with named args
|
|
func (t *Tx) NamedExec(query string, args interface{}) (LastInsertId, RowsAffected int64, err error) {
|
|
func (t *Tx) NamedExec(query string, args interface{}) (LastInsertId, RowsAffected int64, err error) {
|
|
- if rs, err := t.tx.NamedExec(query, args); err == nil {
|
|
|
|
|
|
+ var rs sql.Result
|
|
|
|
+ if rs, err = t.tx.NamedExec(query, args); err == nil {
|
|
RowsAffected, _ = rs.RowsAffected()
|
|
RowsAffected, _ = rs.RowsAffected()
|
|
LastInsertId, _ = rs.LastInsertId()
|
|
LastInsertId, _ = rs.LastInsertId()
|
|
}
|
|
}
|
|
@@ -665,7 +681,8 @@ func (t *Tx) NamedExec(query string, args interface{}) (LastInsertId, RowsAffect
|
|
|
|
|
|
// NamedExecContext executes a query that doesn't return rows. For example: an INSERT and UPDATE. with named args
|
|
// NamedExecContext executes a query that doesn't return rows. For example: an INSERT and UPDATE. with named args
|
|
func (t *Tx) NamedExecContext(ctx context.Context, query string, args interface{}) (LastInsertId, RowsAffected int64, err error) {
|
|
func (t *Tx) NamedExecContext(ctx context.Context, query string, args interface{}) (LastInsertId, RowsAffected int64, err error) {
|
|
- if rs, err := t.tx.NamedExecContext(ctx, query, args); err == nil {
|
|
|
|
|
|
+ var rs sql.Result
|
|
|
|
+ if rs, err = t.tx.NamedExecContext(ctx, query, args); err == nil {
|
|
RowsAffected, _ = rs.RowsAffected()
|
|
RowsAffected, _ = rs.RowsAffected()
|
|
LastInsertId, _ = rs.LastInsertId()
|
|
LastInsertId, _ = rs.LastInsertId()
|
|
}
|
|
}
|
|
@@ -674,7 +691,8 @@ func (t *Tx) NamedExecContext(ctx context.Context, query string, args interface{
|
|
|
|
|
|
// Exec executes a query that doesn't return rows. For example: an INSERT and UPDATE.
|
|
// Exec executes a query that doesn't return rows. For example: an INSERT and UPDATE.
|
|
func (t *Tx) Exec(query string, args ...interface{}) (LastInsertId, RowsAffected int64, err error) {
|
|
func (t *Tx) Exec(query string, args ...interface{}) (LastInsertId, RowsAffected int64, err error) {
|
|
- if rs, err := t.tx.Exec(query, args...); err == nil {
|
|
|
|
|
|
+ var rs sql.Result
|
|
|
|
+ if rs, err = t.tx.Exec(query, args...); err == nil {
|
|
RowsAffected, _ = rs.RowsAffected()
|
|
RowsAffected, _ = rs.RowsAffected()
|
|
LastInsertId, _ = rs.LastInsertId()
|
|
LastInsertId, _ = rs.LastInsertId()
|
|
}
|
|
}
|
|
@@ -683,7 +701,8 @@ func (t *Tx) Exec(query string, args ...interface{}) (LastInsertId, RowsAffected
|
|
|
|
|
|
// ExecContext executes a query that doesn't return rows. For example: an INSERT and UPDATE.
|
|
// ExecContext executes a query that doesn't return rows. For example: an INSERT and UPDATE.
|
|
func (t *Tx) ExecContext(ctx context.Context, query string, args ...interface{}) (LastInsertId, RowsAffected int64, err error) {
|
|
func (t *Tx) ExecContext(ctx context.Context, query string, args ...interface{}) (LastInsertId, RowsAffected int64, err error) {
|
|
- if rs, err := t.tx.ExecContext(ctx, query, args...); err == nil {
|
|
|
|
|
|
+ var rs sql.Result
|
|
|
|
+ if rs, err = t.tx.ExecContext(ctx, query, args...); err == nil {
|
|
RowsAffected, _ = rs.RowsAffected()
|
|
RowsAffected, _ = rs.RowsAffected()
|
|
LastInsertId, _ = rs.LastInsertId()
|
|
LastInsertId, _ = rs.LastInsertId()
|
|
}
|
|
}
|
|
@@ -692,7 +711,8 @@ func (t *Tx) ExecContext(ctx context.Context, query string, args ...interface{})
|
|
|
|
|
|
// Query executes a query that returns rows, typically a SELECT. with named args
|
|
// Query executes a query that returns rows, typically a SELECT. with named args
|
|
func (t *Tx) Query(dest interface{}, query string, args interface{}) (err error) {
|
|
func (t *Tx) Query(dest interface{}, query string, args interface{}) (err error) {
|
|
- nstmt, err := t.tx.PrepareNamed(query)
|
|
|
|
|
|
+ nstmt := new(sqlx.NamedStmt)
|
|
|
|
+ nstmt, err = t.tx.PrepareNamed(query)
|
|
if err != nil {
|
|
if err != nil {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
@@ -704,7 +724,8 @@ func (t *Tx) Query(dest interface{}, query string, args interface{}) (err error)
|
|
|
|
|
|
// QueryContext executes a query that returns rows, typically a SELECT. with named args
|
|
// QueryContext executes a query that returns rows, typically a SELECT. with named args
|
|
func (t *Tx) QueryContext(ctx context.Context, dest interface{}, query string, args interface{}) (err error) {
|
|
func (t *Tx) QueryContext(ctx context.Context, dest interface{}, query string, args interface{}) (err error) {
|
|
- nstmt, err := t.tx.PrepareNamedContext(ctx, query)
|
|
|
|
|
|
+ nstmt := new(sqlx.NamedStmt)
|
|
|
|
+ nstmt, err = t.tx.PrepareNamedContext(ctx, query)
|
|
if err != nil {
|
|
if err != nil {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
@@ -716,7 +737,8 @@ func (t *Tx) QueryContext(ctx context.Context, dest interface{}, query string, a
|
|
|
|
|
|
// QueryRow executes a query that returns rows, typically a SELECT. with named args
|
|
// QueryRow executes a query that returns rows, typically a SELECT. with named args
|
|
func (t *Tx) QueryRow(dest interface{}, query string, args interface{}) (err error) {
|
|
func (t *Tx) QueryRow(dest interface{}, query string, args interface{}) (err error) {
|
|
- nstmt, err := t.tx.PrepareNamed(query)
|
|
|
|
|
|
+ nstmt := new(sqlx.NamedStmt)
|
|
|
|
+ nstmt, err = t.tx.PrepareNamed(query)
|
|
if err != nil {
|
|
if err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
@@ -728,7 +750,8 @@ func (t *Tx) QueryRow(dest interface{}, query string, args interface{}) (err err
|
|
|
|
|
|
// QueryRowContext get row with named args
|
|
// QueryRowContext get row with named args
|
|
func (t *Tx) QueryRowContext(ctx context.Context, dest interface{}, query string, args interface{}) (err error) {
|
|
func (t *Tx) QueryRowContext(ctx context.Context, dest interface{}, query string, args interface{}) (err error) {
|
|
- nstmt, err := t.tx.PrepareNamedContext(ctx, query)
|
|
|
|
|
|
+ nstmt := new(sqlx.NamedStmt)
|
|
|
|
+ nstmt, err = t.tx.PrepareNamedContext(ctx, query)
|
|
if err != nil {
|
|
if err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
@@ -775,10 +798,11 @@ func Select(dest interface{}, query string, args ...interface{}) (err error) {
|
|
func Query(dest interface{}, query string, args interface{}) (err error) {
|
|
func Query(dest interface{}, query string, args interface{}) (err error) {
|
|
defaultDB.conn, err = connect()
|
|
defaultDB.conn, err = connect()
|
|
if err != nil {
|
|
if err != nil {
|
|
- return err
|
|
|
|
|
|
+ return
|
|
}
|
|
}
|
|
|
|
|
|
- nstmt, err := defaultDB.conn.PrepareNamed(query)
|
|
|
|
|
|
+ nstmt := new(sqlx.NamedStmt)
|
|
|
|
+ nstmt, err = defaultDB.conn.PrepareNamed(query)
|
|
if err != nil {
|
|
if err != nil {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
@@ -792,10 +816,11 @@ func Query(dest interface{}, query string, args interface{}) (err error) {
|
|
func QueryContext(ctx context.Context, dest interface{}, query string, args interface{}) (err error) {
|
|
func QueryContext(ctx context.Context, dest interface{}, query string, args interface{}) (err error) {
|
|
defaultDB.conn, err = connectContext(ctx)
|
|
defaultDB.conn, err = connectContext(ctx)
|
|
if err != nil {
|
|
if err != nil {
|
|
- return err
|
|
|
|
|
|
+ return
|
|
}
|
|
}
|
|
|
|
|
|
- nstmt, err := defaultDB.conn.PrepareNamedContext(ctx, query)
|
|
|
|
|
|
+ nstmt := new(sqlx.NamedStmt)
|
|
|
|
+ nstmt, err = defaultDB.conn.PrepareNamedContext(ctx, query)
|
|
if err != nil {
|
|
if err != nil {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
@@ -809,10 +834,11 @@ func QueryContext(ctx context.Context, dest interface{}, query string, args inte
|
|
func Rows(dest interface{}, query string, args interface{}) (err error) {
|
|
func Rows(dest interface{}, query string, args interface{}) (err error) {
|
|
defaultDB.conn, err = connect()
|
|
defaultDB.conn, err = connect()
|
|
if err != nil {
|
|
if err != nil {
|
|
- return err
|
|
|
|
|
|
+ return
|
|
}
|
|
}
|
|
|
|
|
|
- nstmt, err := defaultDB.conn.PrepareNamed(query)
|
|
|
|
|
|
+ nstmt := new(sqlx.NamedStmt)
|
|
|
|
+ nstmt, err = defaultDB.conn.PrepareNamed(query)
|
|
if err != nil {
|
|
if err != nil {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
@@ -826,10 +852,11 @@ func Rows(dest interface{}, query string, args interface{}) (err error) {
|
|
func RowsContext(ctx context.Context, dest interface{}, query string, args interface{}) (err error) {
|
|
func RowsContext(ctx context.Context, dest interface{}, query string, args interface{}) (err error) {
|
|
defaultDB.conn, err = connectContext(ctx)
|
|
defaultDB.conn, err = connectContext(ctx)
|
|
if err != nil {
|
|
if err != nil {
|
|
- return err
|
|
|
|
|
|
+ return
|
|
}
|
|
}
|
|
|
|
|
|
- nstmt, err := defaultDB.conn.PrepareNamedContext(ctx, query)
|
|
|
|
|
|
+ nstmt := new(sqlx.NamedStmt)
|
|
|
|
+ nstmt, err = defaultDB.conn.PrepareNamedContext(ctx, query)
|
|
if err != nil {
|
|
if err != nil {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
@@ -857,9 +884,10 @@ func QueryRow(dest interface{}, query string, args interface{}) (err error) {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
- nstmt, err := defaultDB.conn.PrepareNamed(query)
|
|
|
|
|
|
+ nstmt := new(sqlx.NamedStmt)
|
|
|
|
+ nstmt, err = defaultDB.conn.PrepareNamed(query)
|
|
if err != nil {
|
|
if err != nil {
|
|
- return err
|
|
|
|
|
|
+ return
|
|
}
|
|
}
|
|
defer nstmt.Close()
|
|
defer nstmt.Close()
|
|
|
|
|
|
@@ -874,9 +902,10 @@ func QueryRowContext(ctx context.Context, dest interface{}, query string, args i
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
- nstmt, err := defaultDB.conn.PrepareNamedContext(ctx, query)
|
|
|
|
|
|
+ nstmt := new(sqlx.NamedStmt)
|
|
|
|
+ nstmt, err = defaultDB.conn.PrepareNamedContext(ctx, query)
|
|
if err != nil {
|
|
if err != nil {
|
|
- return err
|
|
|
|
|
|
+ return
|
|
}
|
|
}
|
|
defer nstmt.Close()
|
|
defer nstmt.Close()
|
|
|
|
|
|
@@ -891,9 +920,10 @@ func Row(dest interface{}, query string, args interface{}) (err error) {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
- nstmt, err := defaultDB.conn.PrepareNamed(query)
|
|
|
|
|
|
+ nstmt := new(sqlx.NamedStmt)
|
|
|
|
+ nstmt, err = defaultDB.conn.PrepareNamed(query)
|
|
if err != nil {
|
|
if err != nil {
|
|
- return err
|
|
|
|
|
|
+ return
|
|
}
|
|
}
|
|
defer nstmt.Close()
|
|
defer nstmt.Close()
|
|
|
|
|
|
@@ -908,9 +938,10 @@ func RowContext(ctx context.Context, dest interface{}, query string, args interf
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
- nstmt, err := defaultDB.conn.PrepareNamedContext(ctx, query)
|
|
|
|
|
|
+ nstmt := new(sqlx.NamedStmt)
|
|
|
|
+ nstmt, err = defaultDB.conn.PrepareNamedContext(ctx, query)
|
|
if err != nil {
|
|
if err != nil {
|
|
- return err
|
|
|
|
|
|
+ return
|
|
}
|
|
}
|
|
defer nstmt.Close()
|
|
defer nstmt.Close()
|
|
|
|
|