forked from iamacarpet/go-sqlite3-win64
-
Notifications
You must be signed in to change notification settings - Fork 1
/
sqlite3_raw.go
executable file
·321 lines (281 loc) · 7.77 KB
/
sqlite3_raw.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
// +build windows
// Copyright (C) 2016 Samuel Melrose <[email protected]>.
//
// Based on work by Yasuhiro Matsumoto <[email protected]>
// https://github.com/mattn/go-sqlite3
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file.
package sqlite3
import (
"unsafe"
)
func sqlite3_libversion() string {
msgPtr, _, _ := dll_sqlite3_libversion.Call()
if msgPtr == uintptr(0) {
return "Unknown"
}
return BytePtrToString((*byte)(unsafe.Pointer(msgPtr)))
}
func sqlite3_libversion_number() int {
intPtr, _, _ := dll_sqlite3_libversion_number.Call()
if intPtr == uintptr(0) {
return 0
}
return int(intPtr)
}
func sqlite3_sourceid() string {
msgPtr, _, _ := dll_sqlite3_sourceid.Call()
if msgPtr == uintptr(0) {
return "Unknown"
}
return BytePtrToString((*byte)(unsafe.Pointer(msgPtr)))
}
func sqlite3_errstr(code int) (msg string) {
msgPtr, _, _ := dll_sqlite3_errstr.Call(uintptr(code))
if msgPtr == uintptr(0) {
return "Unknown Error"
}
return BytePtrToString((*byte)(unsafe.Pointer(msgPtr)))
}
func sqlite3_errcode(db sqlite3) (code int) {
retInt, _, _ := dll_sqlite3_errcode.Call(uintptr(db))
return int(retInt)
}
func sqlite3_extended_errcode(db sqlite3) (code int) {
retInt, _, _ := dll_sqlite3_extended_errcode.Call(uintptr(db))
return int(retInt)
}
func sqlite3_errmsg(db sqlite3) (msg string) {
msgPtr, _, _ := dll_sqlite3_errmsg.Call(uintptr(db))
if msgPtr == uintptr(0) {
return "Unknown Error"
}
return BytePtrToString((*byte)(unsafe.Pointer(msgPtr)))
}
func sqlite3_threadsafe() int {
intPtr, _, _ := dll_sqlite3_threadsafe.Call()
return int(intPtr)
}
func sqlite3_open_v2(filename string, ppDb *sqlite3, flags int, zVfs string) int {
var fn uintptr
if len(filename) > 0 {
var tfn = []byte(filename)
fn = uintptr(unsafe.Pointer(&tfn[0]))
} else {
fn = uintptr(0)
}
var vfs uintptr
if len(zVfs) > 0 {
var tvfs = []byte(zVfs)
vfs = uintptr(unsafe.Pointer(&tvfs[0]))
} else {
vfs = uintptr(0)
}
retInt, _, _ := dll_sqlite3_open_v2.Call(
fn,
uintptr(unsafe.Pointer(ppDb)),
uintptr(flags),
vfs,
)
return int(retInt)
}
func sqlite3_busy_timeout(db sqlite3, busyTimeout int) int {
retInt, _, _ := dll_sqlite3_busy_timeout.Call(uintptr(db), uintptr(busyTimeout))
return int(retInt)
}
func sqlite3_close_v2(db sqlite3) int {
retInt, _, _ := dll_sqlite3_close_v2.Call(uintptr(db))
return int(retInt)
}
func sqlite3_prepare_v2(db sqlite3, zSql string) (retCode int, stmtHandle sqlite3_stmt, tail string) {
var sql = []byte(zSql + "\x00")
var handle uintptr
var thandle uintptr
retInt, _, _ := dll_sqlite3_prepare_v2.Call(
uintptr(db),
uintptr(unsafe.Pointer(&sql[0])),
uintptr(SQLITE_TRANSIENT),
uintptr(unsafe.Pointer(&handle)),
uintptr(unsafe.Pointer(&thandle)),
)
return int(retInt), sqlite3_stmt(handle), BytePtrToString((*byte)(unsafe.Pointer(thandle)))
}
func sqlite3_get_autocommit(db sqlite3) int {
retInt, _, _ := dll_sqlite3_get_autocommit.Call(uintptr(db))
return int(retInt)
}
func sqlite3_finalize(stmt sqlite3_stmt) int {
retInt, _, _ := dll_sqlite3_finalize.Call(uintptr(stmt))
return int(retInt)
}
func sqlite3_bind_parameter_count(stmt sqlite3_stmt) int {
retInt, _, _ := dll_sqlite3_bind_parameter_count.Call(uintptr(stmt))
return int(retInt)
}
func sqlite3_bind_parameter_index(stmt sqlite3_stmt, name string) int {
var pName = []byte(name)
retInt, _, _ := dll_sqlite3_bind_parameter_index.Call(
uintptr(stmt),
uintptr(unsafe.Pointer(&pName[0])),
)
return int(retInt)
}
func sqlite3_reset(stmt sqlite3_stmt) int {
retInt, _, _ := dll_sqlite3_reset.Call(uintptr(stmt))
return int(retInt)
}
func sqlite3_bind_null(stmt sqlite3_stmt, ord int) int {
retInt, _, _ := dll_sqlite3_bind_null.Call(
uintptr(stmt),
uintptr(ord),
)
return int(retInt)
}
func sqlite3_bind_text(stmt sqlite3_stmt, ord int, data string) int {
var b []byte
if len(data) == 0 {
b = []byte{0}
} else {
b = []byte(data)
}
retInt, _, _ := dll_sqlite3_bind_text.Call(
uintptr(stmt),
uintptr(ord),
uintptr(unsafe.Pointer(&b[0])),
uintptr(len(data)),
uintptr(SQLITE_TRANSIENT),
)
return int(retInt)
}
func sqlite3_bind_int64(stmt sqlite3_stmt, ord int, data int64) int {
retInt, _, _ := dll_sqlite3_bind_int64.Call(
uintptr(stmt),
uintptr(ord),
uintptr(data),
)
return int(retInt)
}
func sqlite3_bind_int(stmt sqlite3_stmt, ord int, data int) int {
retInt, _, _ := dll_sqlite3_bind_int.Call(
uintptr(stmt),
uintptr(ord),
uintptr(data),
)
return int(retInt)
}
func sqlite3_bind_double(stmt sqlite3_stmt, ord int, data float64) int {
retInt, _, _ := dll_sqlite3_bind_double.Call(
uintptr(stmt),
uintptr(ord),
uintptr(data),
)
return int(retInt)
}
func sqlite3_bind_blob(stmt sqlite3_stmt, ord int, data []byte) int {
var pData uintptr
if len(data) == 0 {
pData = 0
} else {
pData = uintptr(unsafe.Pointer(&data[0]))
}
retInt, _, _ := dll_sqlite3_bind_blob.Call(
uintptr(stmt),
uintptr(ord),
pData,
uintptr(len(data)),
uintptr(SQLITE_TRANSIENT),
)
return int(retInt)
}
func sqlite3_column_count(stmt sqlite3_stmt) int {
retInt, _, _ := dll_sqlite3_column_count.Call(uintptr(stmt))
return int(retInt)
}
func sqlite3_column_name(stmt sqlite3_stmt, index int) string {
msgPtr, _, _ := dll_sqlite3_column_name.Call(
uintptr(stmt),
uintptr(index),
)
return BytePtrToString((*byte)(unsafe.Pointer(msgPtr)))
}
func sqlite3_interrupt(db sqlite3) {
dll_sqlite3_interrupt.Call(uintptr(db))
}
func sqlite3_clear_bindings(stmt sqlite3_stmt) {
dll_sqlite3_clear_bindings.Call(uintptr(stmt))
}
func sqlite3_step(stmt sqlite3_stmt, rowid *int64, changes *int64) int {
stmtPtr := uintptr(stmt)
retInt, _, _ := dll_sqlite3_step.Call(stmtPtr)
db, _, _ := dll_sqlite3_db_handle.Call(stmtPtr)
retRowid, _, _ := dll_sqlite3_last_insert_rowid.Call(db)
retChanges, _, _ := dll_sqlite3_changes.Call(db)
*rowid = int64(retRowid)
*changes = int64(retChanges)
return int(retInt)
}
func sqlite3_column_decltype(stmt sqlite3_stmt, index int) string {
msgPtr, _, _ := dll_sqlite3_column_decltype.Call(
uintptr(stmt),
uintptr(index),
)
if msgPtr == uintptr(0) {
return ""
}
return BytePtrToString((*byte)(unsafe.Pointer(msgPtr)))
}
func sqlite3_column_type(stmt sqlite3_stmt, index int) int {
retInt, _, _ := dll_sqlite3_column_type.Call(
uintptr(stmt),
uintptr(index),
)
return int(retInt)
}
func sqlite3_column_int64(stmt sqlite3_stmt, index int) int64 {
intPtr, _, _ := dll_sqlite3_column_int64.Call(
uintptr(stmt),
uintptr(index),
)
return int64(intPtr)
}
func sqlite3_column_double(stmt sqlite3_stmt, index int) float64 {
intPtr, _, _ := dll_sqlite3_column_double.Call(
uintptr(stmt),
uintptr(index),
)
return float64(intPtr)
}
func sqlite3_column_bytes(stmt sqlite3_stmt, index int) int {
intPtr, _, _ := dll_sqlite3_column_bytes.Call(
uintptr(stmt),
uintptr(index),
)
return int(intPtr)
}
func sqlite3_column_blob(stmt sqlite3_stmt, index int) []byte {
bytesPtr, _, _ := dll_sqlite3_column_blob.Call(
uintptr(stmt),
uintptr(index),
)
n := sqlite3_column_bytes(stmt, index)
if n == 0 {
return []byte{}
}
slice := make([]byte, n)
copy(slice[:], (*[1 << 30]byte)(unsafe.Pointer(bytesPtr))[0:n])
return slice
}
func sqlite3_column_text(stmt sqlite3_stmt, index int) string {
bytesPtr, _, _ := dll_sqlite3_column_text.Call(
uintptr(stmt),
uintptr(index),
)
n := sqlite3_column_bytes(stmt, index)
if n == 0 {
return ``
}
slice := make([]byte, n)
copy(slice[:], (*[1 << 30]byte)(unsafe.Pointer(bytesPtr))[0:n])
return string(slice)
}