diff --git a/statement.go b/statement.go index aff5162f..79d1594e 100644 --- a/statement.go +++ b/statement.go @@ -176,21 +176,6 @@ func (s *Stmt) bindInterval(val Interval, n int) (returnState, error) { return returnState(state), nil } -func (s *Stmt) bindDecimal(val Decimal, n int) (returnState, error) { - v, err := hugeIntFromNative(val.Value) - if err != nil { - return stateError, err - } - - decimal := C.duckdb_decimal{ - width: C.uint8_t(val.Width), - scale: C.uint8_t(val.Scale), - value: v, - } - state := C.duckdb_bind_decimal(*s.stmt, C.idx_t(n+1), decimal) - return returnState(state), nil -} - func (s *Stmt) bindTimestamp(val driver.NamedValue, t Type, n int) (returnState, error) { ts, err := getCTimestamp(t, val.Value) if err != nil { @@ -250,10 +235,9 @@ func (s *Stmt) bindComplexValue(val driver.NamedValue, n int) (returnState, erro TYPE_ARRAY, TYPE_ENUM: // FIXME: for timestamps: distinguish between timestamp[_s|ms|ns] once available. // FIXME: for other types: duckdb_param_logical_type once available, then create duckdb_value + duckdb_bind_value + // FIXME: for other types: implement NamedValueChecker to support custom data types. name := typeToStringMap[t] return stateError, addIndexToError(unsupportedTypeError(name), n+1) - case TYPE_UUID: - // TODO: need to create value? } return stateError, addIndexToError(unsupportedTypeError(unknownTypeErrMsg), n+1) } @@ -281,7 +265,9 @@ func (s *Stmt) bindValue(val driver.NamedValue, n int) (returnState, error) { case *big.Int: return s.bindHugeint(v, n) case Decimal: - return s.bindDecimal(v, n) + // FIXME: implement NamedValueChecker to support custom data types. + name := typeToStringMap[TYPE_DECIMAL] + return stateError, addIndexToError(unsupportedTypeError(name), n+1) case uint8: state := C.duckdb_bind_uint8(*s.stmt, C.idx_t(n+1), C.uint8_t(v)) return returnState(state), nil diff --git a/types.go b/types.go index 8805702e..7b434e2d 100644 --- a/types.go +++ b/types.go @@ -65,11 +65,11 @@ func (u *UUID) String() string { // The value is computed as: upper * 2^64 + lower func hugeIntToUUID(hi C.duckdb_hugeint) []byte { - var uuid [uuid_length]byte - // We need to flip the sign bit of the signed hugeint to transform it to UUID bytes - binary.BigEndian.PutUint64(uuid[:8], uint64(hi.upper)^1<<63) - binary.BigEndian.PutUint64(uuid[8:], uint64(hi.lower)) - return uuid[:] + // Flip the sign bit of the signed hugeint to transform it to UUID bytes. + var val [uuid_length]byte + binary.BigEndian.PutUint64(val[:8], uint64(hi.upper)^1<<63) + binary.BigEndian.PutUint64(val[8:], uint64(hi.lower)) + return val[:] } func uuidToHugeInt(uuid UUID) C.duckdb_hugeint { diff --git a/types_test.go b/types_test.go index 21b1a006..adeb2c46 100644 --- a/types_test.go +++ b/types_test.go @@ -444,28 +444,6 @@ func TestDecimal(t *testing.T) { } }) - t.Run("Bind and INSERT a DECIMAL into a table", func(t *testing.T) { - _, err := db.Exec(`CREATE TABLE tbl (d1 DECIMAL(5, 2), d2 DECIMAL(22, 3))`) - require.NoError(t, err) - - bigNumber, success := new(big.Int).SetString("1234567890123456789234", 10) - require.Equal(t, true, success) - d1 := Decimal{Value: big.NewInt(-12345), Width: 5, Scale: 2} - d2 := Decimal{Value: bigNumber, Width: 22, Scale: 3} - - _, err = db.Exec(`INSERT INTO tbl VALUES (?, ?)`, d1, d2) - require.NoError(t, err) - - var res Decimal - err = db.QueryRow(`SELECT d1 FROM tbl`).Scan(&res) - require.NoError(t, err) - compareDecimal(t, d1, res) - - err = db.QueryRow(`SELECT d2 FROM tbl`).Scan(&res) - require.NoError(t, err) - compareDecimal(t, d2, res) - }) - require.NoError(t, db.Close()) }