sqldb-logger icon indicating copy to clipboard operation
sqldb-logger copied to clipboard

uint64 issues

Open Drabuna opened this issue 5 years ago • 3 comments

Hi, I'm trying to use this together with sqlx and have discovered a weird issue - when trying to insert uint64 value I get a: error: sql: converting argument $1 type: driver ColumnConverter error converted uint64 to unsupported type uint64

The moment I remove sqldb-logger (by setting c.loggingEnabled = false), the issue goes away and everything works fine.

Here some details on how I init the connection:

import (
	"context"
	"database/sql"
	_ "github.com/go-sql-driver/mysql"
	"github.com/jmoiron/sqlx"
	sqldblogger "github.com/simukti/sqldb-logger"
)

func init(c *Config) {
    dsn := c.MysqlConnectionString()

    sqlDb, err := sql.Open("mysql", dsn)
    if err != nil {
        return err
    }
    if c.loggingEnabled {
        sqlDb = sqldblogger.OpenDriver(dsn, sqlDb.Driver(), logger, sqldblogger.WithMinimumLevel(c.logLevel))
    }

    db := sqlx.NewDb(sqlDb, "mysql")
}

And then later I would run something like:

func (s *Store) CreateAccount(context context.Context, accountId uint64, email string, username string) (bool, error) {
	query := "INSERT INTO accounts (id, email, username, status, created_at, updated_at) VALUES (?, ?, ?, ?, NOW(), NOW())"
	res, err := s.db.ExecContext(context, query, accountId, email, username, constants.AccountActive)
	if err != nil {
		return false, err
	}
    return true, nil
}

And the CreateAccount will return an error specified above.

Thoughts, ideas?

Drabuna avatar Feb 16 '21 16:02 Drabuna

It is because current version of this library does not use NamedValueChecker implemented on connection (and only use statement's one). #61 is fix for that. But in https://github.com/go-sql-driver/mysql/pull/1090 it is already implemented. So you can fix the issue by updating mysql driver.

ypresto avatar Mar 31 '21 19:03 ypresto

But in go-sql-driver/mysql#1090 it is already implemented. So you can fix the issue by updating mysql driver.

Hi @ypresto thanks for investigating it.

I'd suggest @Drabuna to update Go MySQL driver to the newer version if that's possible and see if that's solve the problem. Because sqldb-logger log interaction with *sql.DB as-is.

simukti avatar May 05 '21 15:05 simukti

Because sqldb-logger log interaction with *sql.DB as-is.

To my understanding, this is sqldb-logger's side issue: the cause of this issue is that sqldb-logger's logic is different from how golang sql package works. (mentioned in #61) Also there is no guarantee that every statements of every db packages implements NamedValueChecker (like mysql package). So updating to latest mysql package is only just a workaround for it.

ypresto avatar May 06 '21 05:05 ypresto