Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uint64 issues #60

Closed
Drabuna opened this issue Feb 16, 2021 · 3 comments · May be fixed by #61
Closed

uint64 issues #60

Drabuna opened this issue Feb 16, 2021 · 3 comments · May be fixed by #61

Comments

@Drabuna
Copy link

Drabuna commented Feb 16, 2021

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?

@ypresto
Copy link

ypresto commented Mar 31, 2021

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 go-sql-driver/mysql#1090 it is already implemented. So you can fix the issue by updating mysql driver.

@simukti
Copy link
Owner

simukti commented May 5, 2021

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.

@ypresto
Copy link

ypresto commented May 6, 2021

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.

@Drabuna Drabuna closed this as completed Mar 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants