This commit is contained in:
Mike Schwörer 2022-12-21 15:41:41 +01:00
parent e3b8d2cc0f
commit d4994b8c8d
Signed by: Mikescher
GPG Key ID: D3C7172E0A70F8CF
3 changed files with 12 additions and 10 deletions

View File

@ -38,7 +38,7 @@ func (db *database) AddListener(listener Listener) {
func (db *database) Exec(ctx context.Context, sqlstr string, prep PP) (sql.Result, error) { func (db *database) Exec(ctx context.Context, sqlstr string, prep PP) (sql.Result, error) {
origsql := sqlstr origsql := sqlstr
for _, v := range db.lstr { for _, v := range db.lstr {
err := v.PreExec(nil, &sqlstr, &prep) err := v.PreExec(ctx, nil, &sqlstr, &prep)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -59,7 +59,7 @@ func (db *database) Exec(ctx context.Context, sqlstr string, prep PP) (sql.Resul
func (db *database) Query(ctx context.Context, sqlstr string, prep PP) (*sqlx.Rows, error) { func (db *database) Query(ctx context.Context, sqlstr string, prep PP) (*sqlx.Rows, error) {
origsql := sqlstr origsql := sqlstr
for _, v := range db.lstr { for _, v := range db.lstr {
err := v.PreQuery(nil, &sqlstr, &prep) err := v.PreQuery(ctx, nil, &sqlstr, &prep)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -79,7 +79,7 @@ func (db *database) Query(ctx context.Context, sqlstr string, prep PP) (*sqlx.Ro
func (db *database) Ping(ctx context.Context) error { func (db *database) Ping(ctx context.Context) error {
for _, v := range db.lstr { for _, v := range db.lstr {
err := v.PrePing() err := v.PrePing(ctx)
if err != nil { if err != nil {
return err return err
} }
@ -104,7 +104,7 @@ func (db *database) BeginTransaction(ctx context.Context, iso sql.IsolationLevel
db.lock.Unlock() db.lock.Unlock()
for _, v := range db.lstr { for _, v := range db.lstr {
err := v.PreTxBegin(txid) err := v.PreTxBegin(ctx, txid)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -1,12 +1,14 @@
package sq package sq
import "context"
type Listener interface { type Listener interface {
PrePing() error PrePing(ctx context.Context) error
PreTxBegin(txid uint16) error PreTxBegin(ctx context.Context, txid uint16) error
PreTxCommit(txid uint16) error PreTxCommit(txid uint16) error
PreTxRollback(txid uint16) error PreTxRollback(txid uint16) error
PreQuery(txID *uint16, sql *string, params *PP) error PreQuery(ctx context.Context, txID *uint16, sql *string, params *PP) error
PreExec(txID *uint16, sql *string, params *PP) error PreExec(ctx context.Context, txID *uint16, sql *string, params *PP) error
PostPing(result error) PostPing(result error)
PostTxBegin(txid uint16, result error) PostTxBegin(txid uint16, result error)

View File

@ -65,7 +65,7 @@ func (tx *transaction) Commit() error {
func (tx *transaction) Exec(ctx context.Context, sqlstr string, prep PP) (sql.Result, error) { func (tx *transaction) Exec(ctx context.Context, sqlstr string, prep PP) (sql.Result, error) {
origsql := sqlstr origsql := sqlstr
for _, v := range tx.lstr { for _, v := range tx.lstr {
err := v.PreExec(langext.Ptr(tx.id), &sqlstr, &prep) err := v.PreExec(ctx, langext.Ptr(tx.id), &sqlstr, &prep)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -86,7 +86,7 @@ func (tx *transaction) Exec(ctx context.Context, sqlstr string, prep PP) (sql.Re
func (tx *transaction) Query(ctx context.Context, sqlstr string, prep PP) (*sqlx.Rows, error) { func (tx *transaction) Query(ctx context.Context, sqlstr string, prep PP) (*sqlx.Rows, error) {
origsql := sqlstr origsql := sqlstr
for _, v := range tx.lstr { for _, v := range tx.lstr {
err := v.PreQuery(langext.Ptr(tx.id), &sqlstr, &prep) err := v.PreQuery(ctx, langext.Ptr(tx.id), &sqlstr, &prep)
if err != nil { if err != nil {
return nil, err return nil, err
} }