@@ -130,6 +130,9 @@ func (db *Database) SetEventHandler(handler ErrorHandler) {
130130// Exec executes an SQL statement on a new connection
131131func (db * Database ) Exec (ctx context.Context , sql string , args ... interface {}) (int64 , error ) {
132132 ct , err := db .pool .Exec (ctx , sql , args ... )
133+ if err != nil {
134+ err = newError (err , "unable to execute command" )
135+ }
133136 return ct .RowsAffected (), db .processError (err )
134137}
135138
@@ -145,7 +148,7 @@ func (db *Database) Exec(ctx context.Context, sql string, args ...interface{}) (
145148// 3. To avoid overflows on high uint64 values, store them in NUMERIC(24,0) fields.
146149// 4. For time-only fields, date is set to Jan 1, 2000 by PGX in time.Time variables.
147150func (db * Database ) QueryRow (ctx context.Context , sql string , args ... interface {}) Row {
148- return rowGetter {
151+ return & rowGetter {
149152 db : db ,
150153 row : db .pool .QueryRow (ctx , sql , args ... ),
151154 }
@@ -154,7 +157,10 @@ func (db *Database) QueryRow(ctx context.Context, sql string, args ...interface{
154157// QueryRows executes a SQL query on a new connection
155158func (db * Database ) QueryRows (ctx context.Context , sql string , args ... interface {}) Rows {
156159 rows , err := db .pool .Query (ctx , sql , args ... )
157- return rowsGetter {
160+ if err != nil {
161+ err = newError (err , "unable to scan row" )
162+ }
163+ return & rowsGetter {
158164 db : db ,
159165 ctx : ctx ,
160166 rows : rows ,
@@ -168,11 +174,14 @@ func (db *Database) Copy(ctx context.Context, tableName string, columnNames []st
168174 ctx ,
169175 pgx.Identifier {tableName },
170176 columnNames ,
171- copyWithCallback {
177+ & copyWithCallback {
172178 ctx : ctx ,
173179 callback : callback ,
174180 },
175181 )
182+ if err != nil {
183+ err = newError (err , "unable to execute command" )
184+ }
176185
177186 // Done
178187 return n , db .processError (err )
0 commit comments