Skip to content

uint64 not supported, despite underlying driver (go-sql-driver/mysql) supporting them #59

@sheepda

Description

@sheepda

Hi!

sqlhooks seems to be relying on the default driver.DefaultParameterConverter as the driver.ValueConverter instead of the underlying driver's implementation leading to discrepancies in type support.

One such example is go-sql-driver/mysql which supports using uint64 to write to a BIGINT UNSIGNED column. But when wrapped with sqlhooks, trying to INSERT a uint64 outside of int64 range into a BIGINT UNSIGNED column causes an error: sql: converting argument $1 type: uint64 values with high bit set are not supported. The error comes from database/sql/driver/types.go:265.

Here's a test case that should pass when added to sqlhooks_mysql_test.go:

func TestMySQLUint64(t *testing.T) {
	dsn := os.Getenv("SQLHOOKS_MYSQL_DSN")
	if dsn == "" {
		t.Skipf("SQLHOOKS_MYSQL_DSN not set")
	}

	setUpMySQL(t, dsn)

	withHooks := newSuite(t, &mysql.MySQLDriver{}, dsn).db
	withoutHooks, err := sql.Open("mysql", dsn)
	require.NoError(t, err)
	require.NoError(t, withoutHooks.Ping())

	dbs := []struct {
		db   *sql.DB
		name string
	}{{db: withoutHooks, name: "withoutHooks"}, {db: withHooks, name: "withHooks"}}

	_, err = withoutHooks.Exec("DROP TABLE IF EXISTS large")
	require.NoError(t, err)
	_, err = withoutHooks.Exec("CREATE TABLE large(id INT AUTO_INCREMENT PRIMARY KEY, v BIGINT UNSIGNED)")
	require.NoError(t, err)

	maxInt64 := uint64(1)<<63 - 1
	for _, i := range dbs {
		_, err = i.db.Exec("INSERT INTO large(v) VALUES(?)", maxInt64)
		assert.NoError(t, err, "db = %s", i.name)
		_, err = i.db.Exec("INSERT INTO large(v) VALUES(?)", maxInt64+1)
		assert.NoError(t, err, "db = %s", i.name)
	}
}

But instead it fails with:

=== RUN   TestMySQLUint64
    sqlhooks_mysql_test.go:87: 
        	Error Trace:	sqlhooks_mysql_test.go:87
        	Error:      	Received unexpected error:
        	            	sql: converting argument $1 type: uint64 values with high bit set are not supported
        	Test:       	TestMySQLUint64
        	Messages:   	db = withHooks
--- FAIL: TestMySQLUint64 (1.61s)
FAIL
FAIL	github.com/qustavo/sqlhooks/v2	1.868s
FAIL

Thank you for your open source work! It's greatly appreciated!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions