jmoiron / sqlx

general purpose extensions to golang's database/sql
http://jmoiron.github.io/sqlx/
MIT License
16.08k stars 1.08k forks source link

calling NamedQuery with update/delete statement instead of select will cause connection not to be returned to pool #893

Open adambezecny opened 1 year ago

adambezecny commented 1 year ago

when calling db.NamedQuery with update/delete statement, e.g.:

query := `INSERT INTO dummy_table(league_id, subscriber_id, messaging_type) 
          VALUES (:league_id, :subscriber_id, :messaging_type)`
if _, err := db.NamedQuery(query, s); err != nil {
      ...
    }

connection is not returned into pool leading ultimately to pool exhaustion. The correct way is to call db.NamedExec instead. The problem is API is not preventing one from calling inappropriate method (NamedQuery) with update/delete. This leads to very tricky and hard to troubleshoot errors. Could this be documented in method comments and ideally somehow prevented in runtime (e.g. trowing fatal error when calling NamedQuery with update/delete)?

Vyacheslav1557 commented 3 months ago

What about rows.Close() ?