5
5
6
6
sq3 = ffilib .open ("libsqlite3" )
7
7
8
+ # int sqlite3_open(
9
+ # const char *filename, /* Database filename (UTF-8) */
10
+ # sqlite3 **ppDb /* OUT: SQLite db handle */
11
+ # );
8
12
sqlite3_open = sq3 .func ("i" , "sqlite3_open" , "sp" )
9
13
# int sqlite3_config(int, ...);
10
14
sqlite3_config = sq3 .func ("i" , "sqlite3_config" , "ii" )
17
21
# sqlite3_stmt **ppStmt, /* OUT: Statement handle */
18
22
# const char **pzTail /* OUT: Pointer to unused portion of zSql */
19
23
# );
20
- sqlite3_prepare = sq3 .func ("i" , "sqlite3_prepare " , "psipp" )
24
+ sqlite3_prepare = sq3 .func ("i" , "sqlite3_prepare_v2 " , "psipp" )
21
25
# int sqlite3_finalize(sqlite3_stmt *pStmt);
22
26
sqlite3_finalize = sq3 .func ("i" , "sqlite3_finalize" , "p" )
23
27
# int sqlite3_step(sqlite3_stmt*);
26
30
sqlite3_column_count = sq3 .func ("i" , "sqlite3_column_count" , "p" )
27
31
# int sqlite3_column_type(sqlite3_stmt*, int iCol);
28
32
sqlite3_column_type = sq3 .func ("i" , "sqlite3_column_type" , "pi" )
33
+ # int sqlite3_column_int(sqlite3_stmt*, int iCol);
29
34
sqlite3_column_int = sq3 .func ("i" , "sqlite3_column_int" , "pi" )
30
- # using "d" return type gives wrong results
35
+ # double sqlite3_column_double(sqlite3_stmt*, int iCol);
31
36
sqlite3_column_double = sq3 .func ("d" , "sqlite3_column_double" , "pi" )
37
+ # const unsigned char *sqlite3_column_text(sqlite3_stmt*, int iCol);
32
38
sqlite3_column_text = sq3 .func ("s" , "sqlite3_column_text" , "pi" )
33
39
# sqlite3_int64 sqlite3_last_insert_rowid(sqlite3*);
34
- # TODO: should return long int
35
- sqlite3_last_insert_rowid = sq3 .func ("i" , "sqlite3_last_insert_rowid" , "p" )
40
+ sqlite3_last_insert_rowid = sq3 .func ("l" , "sqlite3_last_insert_rowid" , "p" )
36
41
# const char *sqlite3_errmsg(sqlite3*);
37
42
sqlite3_errmsg = sq3 .func ("s" , "sqlite3_errmsg" , "p" )
38
43
39
- # Too recent
40
- ##const char *sqlite3_errstr(int);
41
- # sqlite3_errstr = sq3.func("s", "sqlite3_errstr", "i")
42
-
43
44
44
45
SQLITE_OK = 0
45
46
SQLITE_ERROR = 1
@@ -96,18 +97,17 @@ def execute(self, sql, params=None):
96
97
if params :
97
98
params = [quote (v ) for v in params ]
98
99
sql = sql % tuple (params )
99
- print (sql )
100
100
101
101
stmnt_ptr = bytes (get_ptr_size ())
102
102
res = sqlite3_prepare (self .h , sql , - 1 , stmnt_ptr , None )
103
103
check_error (self .h , res )
104
104
self .stmnt = int .from_bytes (stmnt_ptr , sys .byteorder )
105
105
self .num_cols = sqlite3_column_count (self .stmnt )
106
106
107
- # If it's not select, actually execute it here
108
- # num_cols == 0 for statements which don't return data (=> modify it)
109
107
if not self .num_cols :
110
108
v = self .fetchone ()
109
+ # If it's not select, actually execute it here
110
+ # num_cols == 0 for statements which don't return data (=> modify it)
111
111
assert v is None
112
112
self .lastrowid = sqlite3_last_insert_rowid (self .h )
113
113
@@ -119,7 +119,6 @@ def make_row(self):
119
119
res = []
120
120
for i in range (self .num_cols ):
121
121
t = sqlite3_column_type (self .stmnt , i )
122
- # print("type", t)
123
122
if t == SQLITE_INTEGER :
124
123
res .append (sqlite3_column_int (self .stmnt , i ))
125
124
elif t == SQLITE_FLOAT :
@@ -132,7 +131,6 @@ def make_row(self):
132
131
133
132
def fetchone (self ):
134
133
res = sqlite3_step (self .stmnt )
135
- # print("step:", res)
136
134
if res == SQLITE_DONE :
137
135
return None
138
136
if res == SQLITE_ROW :
0 commit comments