DATA-DOG / go-txdb

Immutable transaction isolated sql driver for golang
Other
667 stars 48 forks source link

postgres PrepareContext returns a nil `sql.Stmt` pointer #25

Closed tomatosource closed 5 years ago

tomatosource commented 5 years ago

Issue

I am trying to test some code that uses a prepared statement (using postgres/sqlx), small example below.

The code is running in to nil pointer exceptions stemming from a nil statement pointer.

Is this a known shortcoming of lib? If so, are there any common workarounds?

Potentially related to https://github.com/DATA-DOG/go-txdb/issues/3?

Definitely happy to contribute if I can get pointed in a direction :)

Example

func init() {
    txdb.Register("pgx", "postgres", "my connection string")
}

func NewTestDB(t *testing.T) *sqlx.DB {
    db, err := sqlx.Open("pgx", t.Name())
    if err != nil {
        t.Fatal(err)
    }
        return db
}

func TestFoo(t *testing.T) {
       db := NewTestDB(t)
       stmt, err := db.PrepareContext(ctx, pq.CopyInSchema(
             "someschema", "sometable", "somecolumn"
       ))
      // stmt is nil here, no err
}
tomatosource commented 5 years ago

Apologies - was able to reproduce without txdb - must be something else going on. Will update in future if I work it out for any future travellers.