Merge pull request #1403 from dxbjavid/bind-text64-length
bind via sqlite3_bind_text64/blob64 to avoid 32-bit length truncation
This commit is contained in:
18
sqlite3.go
18
sqlite3.go
@@ -69,13 +69,13 @@ _sqlite3_open_v2(const char *filename, sqlite3 **ppDb, int flags, const char *zV
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
_sqlite3_bind_text(sqlite3_stmt *stmt, int n, char *p, int np) {
|
_sqlite3_bind_text(sqlite3_stmt *stmt, int n, char *p, sqlite3_uint64 np) {
|
||||||
return sqlite3_bind_text(stmt, n, p, np, SQLITE_TRANSIENT);
|
return sqlite3_bind_text64(stmt, n, p, np, SQLITE_TRANSIENT, SQLITE_UTF8);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
_sqlite3_bind_blob(sqlite3_stmt *stmt, int n, void *p, int np) {
|
_sqlite3_bind_blob(sqlite3_stmt *stmt, int n, void *p, sqlite3_uint64 np) {
|
||||||
return sqlite3_bind_blob(stmt, n, p, np, SQLITE_TRANSIENT);
|
return sqlite3_bind_blob64(stmt, n, p, np, SQLITE_TRANSIENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@@ -2180,9 +2180,9 @@ var placeHolder = []byte{0}
|
|||||||
|
|
||||||
func bindText(s *C.sqlite3_stmt, n C.int, v string) C.int {
|
func bindText(s *C.sqlite3_stmt, n C.int, v string) C.int {
|
||||||
if len(v) == 0 {
|
if len(v) == 0 {
|
||||||
return C._sqlite3_bind_text(s, n, (*C.char)(unsafe.Pointer(&placeHolder[0])), C.int(0))
|
return C._sqlite3_bind_text(s, n, (*C.char)(unsafe.Pointer(&placeHolder[0])), C.sqlite3_uint64(0))
|
||||||
}
|
}
|
||||||
return C._sqlite3_bind_text(s, n, (*C.char)(unsafe.Pointer(unsafe.StringData(v))), C.int(len(v)))
|
return C._sqlite3_bind_text(s, n, (*C.char)(unsafe.Pointer(unsafe.StringData(v))), C.sqlite3_uint64(len(v)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func bindValue(s *C.sqlite3_stmt, n C.int, value driver.Value) C.int {
|
func bindValue(s *C.sqlite3_stmt, n C.int, value driver.Value) C.int {
|
||||||
@@ -2208,14 +2208,14 @@ func bindValue(s *C.sqlite3_stmt, n C.int, value driver.Value) C.int {
|
|||||||
if ln == 0 {
|
if ln == 0 {
|
||||||
v = placeHolder
|
v = placeHolder
|
||||||
}
|
}
|
||||||
return C._sqlite3_bind_blob(s, n, unsafe.Pointer(&v[0]), C.int(ln))
|
return C._sqlite3_bind_blob(s, n, unsafe.Pointer(&v[0]), C.sqlite3_uint64(ln))
|
||||||
case time.Time:
|
case time.Time:
|
||||||
var buf [64]byte
|
var buf [64]byte
|
||||||
b := v.AppendFormat(buf[:0], SQLiteTimestampFormats[0])
|
b := v.AppendFormat(buf[:0], SQLiteTimestampFormats[0])
|
||||||
if len(b) == 0 {
|
if len(b) == 0 {
|
||||||
return C._sqlite3_bind_text(s, n, (*C.char)(unsafe.Pointer(&placeHolder[0])), C.int(0))
|
return C._sqlite3_bind_text(s, n, (*C.char)(unsafe.Pointer(&placeHolder[0])), C.sqlite3_uint64(0))
|
||||||
}
|
}
|
||||||
return C._sqlite3_bind_text(s, n, (*C.char)(unsafe.Pointer(&b[0])), C.int(len(b)))
|
return C._sqlite3_bind_text(s, n, (*C.char)(unsafe.Pointer(&b[0])), C.sqlite3_uint64(len(b)))
|
||||||
default:
|
default:
|
||||||
return C.SQLITE_MISUSE
|
return C.SQLITE_MISUSE
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user