Commit 3107a54d authored by gwenn's avatar gwenn

Improve call to sqlite3_bind_text.

parent 740da6cc
......@@ -18,7 +18,7 @@ package sqlite
// #define SQLITE_TRANSIENT ((sqlite3_destructor_type)-1)
static inline int my_bind_text(sqlite3_stmt *stmt, int pidx, const char *data, int data_len) {
return sqlite3_bind_text(stmt, pidx, data, data_len, SQLITE_TRANSIENT);
return sqlite3_bind_text(stmt, pidx, data, data_len, free);
}
static inline int my_bind_empty_text(sqlite3_stmt *stmt, int pidx) {
return sqlite3_bind_text(stmt, pidx, "", 0, SQLITE_STATIC);
......@@ -357,8 +357,7 @@ func (s *Stmt) BindByIndex(index int, value interface{}) error {
if i64 && len(value) > math.MaxInt32 {
return s.specificError("string too big: %d at index %d", len(value), index)
}
cs, l := cstring(value)
rv = C.my_bind_text(s.stmt, i, cs, l)
rv = C.my_bind_text(s.stmt, i, C.CString(value), C.int(len(value)))
}
case int:
if i64 {
......@@ -393,8 +392,8 @@ func (s *Stmt) BindByIndex(index int, value interface{}) error {
} else if s.c.DefaultTimeLayout == "" {
rv = C.sqlite3_bind_int64(s.stmt, i, C.sqlite3_int64(value.Unix()))
} else {
cs, l := cstring(value.Format(s.c.DefaultTimeLayout))
rv = C.my_bind_text(s.stmt, i, cs, l)
v := value.Format(s.c.DefaultTimeLayout)
rv = C.my_bind_text(s.stmt, i, C.CString(v), C.int(len(v)))
}
case ZeroBlobLength:
rv = C.sqlite3_bind_zeroblob(s.stmt, i, C.int(value))
......@@ -419,8 +418,8 @@ func (s *Stmt) BindReflect(index int, value interface{}) error {
v := reflect.ValueOf(value)
switch v.Kind() {
case reflect.String:
cs, l := cstring(v.String())
rv = C.my_bind_text(s.stmt, i, cs, l)
vs := v.String() // TODO NullIfEmptyString
rv = C.my_bind_text(s.stmt, i, C.CString(vs), C.int(len(vs)))
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
rv = C.sqlite3_bind_int64(s.stmt, i, C.sqlite3_int64(v.Int()))
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment