on master help sign in
commented C code and got rid of some unwated functions
b27e414melissam
contribs/lib/SQLite3/._sqlite3.idr

Binary file not shown.

contribs/lib/SQLite3/._sqlite3api.c

Binary file not shown.

contribs/lib/SQLite3/._sqlite3api.h

Binary file not shown.

contribs/lib/SQLite3/sqlite3.idr+12−9
@@ -23,21 +23,21 @@ data DBVal = DBInt Int
23 | DBFloat Float
23 | DBFloat Float
24 | DBNull
24 | DBNull
25
25
26−
26+-- Database pointer
27data DBPointer = MkDBPointer Ptr
27data DBPointer = MkDBPointer Ptr
28−
28+-- Table pointer
29data TBPointer = MkTBPointer Ptr
29data TBPointer = MkTBPointer Ptr
30−
30+-- Statement pointer
31data StmtPtr = MkStmtPtr Ptr
31data StmtPtr = MkStmtPtr Ptr
32
32
33Table : Set
33Table : Set
34Table = List (List DBVal)
34Table = List (List DBVal)
35
35
36−
36+-- ForMap used in to_list_v1
37forM : Monad m => List a -> (a -> m b) -> m (List b)
37forM : Monad m => List a -> (a -> m b) -> m (List b)
38forM f xs = mapM xs f
38forM f xs = mapM xs f
39
39
40−
40+-- Neater error handling done using DB
41data DB a = MkDB (IO (Either String a))
41data DB a = MkDB (IO (Either String a))
42
42
43instance Monad DB where
43instance Monad DB where
@@ -275,18 +275,18 @@ get_data (MkDBPointer pointer) row col = do
275 helper ty
275 helper ty
276 where
276 where
277 get_data_type : Ptr ->Int -> Int -> IO Int
277 get_data_type : Ptr ->Int -> Int -> IO Int
278− get_data_type pointer row col =mkForeign (FFun "sqlite3_get_data_type_v2" [FPtr, FInt, FInt] FInt)pointer row col
278+ get_data_type pointer row col =mkForeign (FFun "sqlite3_get_data_type" [FPtr, FInt, FInt] FInt)pointer row col
279
279
280 get_data_val_int : Ptr -> Int -> IO Int
280 get_data_val_int : Ptr -> Int -> IO Int
281− get_data_val_int pointer col =mkForeign (FFun "sqlite3_get_val_int_v2" [FPtr,FInt] FInt)pointer col
281+ get_data_val_int pointer col =mkForeign (FFun "sqlite3_get_val_int" [FPtr,FInt] FInt)pointer col
282
282
283 get_data_val_text : Ptr -> Int -> IO String
283 get_data_val_text : Ptr -> Int -> IO String
284− get_data_val_text pointer col =mkForeign (FFun "sqlite3_get_val_text_v2" [FPtr, FInt] FString)pointer col
284+ get_data_val_text pointer col =mkForeign (FFun "sqlite3_get_val_text" [FPtr, FInt] FString)pointer col
285
285
286
286
287
287
288 get_data_val_float : Ptr -> Int -> IO Float
288 get_data_val_float : Ptr -> Int -> IO Float
289− get_data_val_float pointer col =mkForeign (FFun "sqlite3_get_float_v2" [FPtr, FInt] FFloat)pointer col
289+ get_data_val_float pointer col =mkForeign (FFun "sqlite3_get_float" [FPtr, FInt] FFloat)pointer col
290
290
291 helper : Int -> IO DBVal
291 helper : Int -> IO DBVal
292 helper 1 = do i <- get_data_val_int pointer col ; return (DBInt i)
292 helper 1 = do i <- get_data_val_int pointer col ; return (DBInt i)
@@ -316,6 +316,7 @@ strcat str1 str2 = (str1 ++ str2)
316
316
317-----------------------------------------------------------------------------
317-----------------------------------------------------------------------------
318-- | This version of toList retunrs result from get_table
318-- | This version of toList retunrs result from get_table
319+-- This could be removed if not needed in the future.
319-----------------------------------------------------------------------------
320-----------------------------------------------------------------------------
320
321
321--toList_v2 : String -> String -> DBPointer -> DB Table
322--toList_v2 : String -> String -> DBPointer -> DB Table
@@ -335,6 +336,8 @@ strcat str1 str2 = (str1 ++ str2)
335
336
336-----------------------------------------------------------------------------
337-----------------------------------------------------------------------------
337-- | These routines support binding the types supported by Idris.
338-- | These routines support binding the types supported by Idris.
339+-- These return a pointer to statement pointer since we want to allow
340+-- binding multiple values by implementing a recursive function.
338-----------------------------------------------------------------------------
341-----------------------------------------------------------------------------
339
342
340bind_int : StmtPtr -> Int -> Int -> DB StmtPtr
343bind_int : StmtPtr -> Int -> Int -> DB StmtPtr
contribs/lib/SQLite3/sqlite3api.c+150−199
@@ -11,10 +11,19 @@
11#include "sqlite3api.h"
11#include "sqlite3api.h"
12
12
13
13
14−
14+// buffer used for storing queries
15+// Used in high-level functions.
15static char sql_query_buffer[2000];
16static char sql_query_buffer[2000];
17+// array used to store the string
18+//value obtain by get_val_text
16unsigned char* array;
19unsigned char* array;
17
20
21+/*
22+ open an SQLite database file as
23+ specified by the filename argument.
24+ Returns pointer to DB struct on success
25+ Null on failure.
26+ */
18void* sqlite3_open_idr(const char *filename){
27void* sqlite3_open_idr(const char *filename){
19
28
20 sqlite3 *db;
29 sqlite3 *db;
@@ -30,26 +39,29 @@ void* sqlite3_open_idr(const char *filename){
30
39
31}
40}
32
41
42+/*
43+ Frees the resource and returns 0 on success
44+ */
33int sqlite3_close_idr(void* db){
45int sqlite3_close_idr(void* db){
34
46
35 DBinfo* dbi =(DBinfo*) db;
47 DBinfo* dbi =(DBinfo*) db;
36 int res =sqlite3_close(dbi->db_ptr);
48 int res =sqlite3_close(dbi->db_ptr);
37 if (res == SQLITE_OK){
49 if (res == SQLITE_OK){
38 free(dbi);
50 free(dbi);
39− printf("Successfuly closed the databse\n");
40 return 0;
51 return 0;
41 }
52 }
42
53
43− if(res == SQLITE_BUSY){
44− printf("SQL Busy");
45− return 5;
46− }
47−
48 else {
54 else {
49− return 1;
55+ return res;
50 }
56 }
51}
57}
52
58
59+/*
60+ SQLite wrapper around sqlite3_prepare_v2(),
61+ sqlite3_step(), and sqlite3_finalize().
62+ This version of exec cannot be used with prepare.
63+ For executing queries, must use the exec_db function.
64+ */
53int sqlite3_exec_idr(void* db, const char *sql)
65int sqlite3_exec_idr(void* db, const char *sql)
54{
66{
55
67
@@ -58,7 +70,6 @@ int sqlite3_exec_idr(void* db, const char *sql)
58 int rc;
70 int rc;
59
71
60 rc = sqlite3_exec(dbi->db_ptr,sql,NULL, NULL, &err);
72 rc = sqlite3_exec(dbi->db_ptr,sql,NULL, NULL, &err);
61− printf("%d\n", rc);
62 if (rc != SQLITE_OK && err != NULL) {
73 if (rc != SQLITE_OK && err != NULL) {
63 strncpy(dbi->buffer, err, sizeof(dbi->buffer));
74 strncpy(dbi->buffer, err, sizeof(dbi->buffer));
64 sqlite3_free(err);
75 sqlite3_free(err);
@@ -66,12 +77,22 @@ int sqlite3_exec_idr(void* db, const char *sql)
66 return rc;
77 return rc;
67}
78}
68
79
69−
80+/*
81+ Gets the error store in the buffer
82+ in the struct. Some certain functions
83+ have the feature to store errors in a buffer.
84+ */
70char* sqlite3_get_error(void* db) {
85char* sqlite3_get_error(void* db) {
71 DBinfo* dbi =(DBinfo*) db;
86 DBinfo* dbi =(DBinfo*) db;
72 return dbi->buffer;
87 return dbi->buffer;
73}
88}
74
89
90+
91+/*
92+ Compiles the query into a byte-code program
93+ Returns a pointer to the sqlite3_stmt pointer
94+ and stores it in the struct.
95+ */
75void* sqlite3_prepare_idr(void *db,const char *zSql){
96void* sqlite3_prepare_idr(void *db,const char *zSql){
76
97
77 sqlite3_stmt* stmt;
98 sqlite3_stmt* stmt;
@@ -90,6 +111,14 @@ void* sqlite3_prepare_idr(void *db,const char *zSql){
90 return dbi;
111 return dbi;
91}
112}
92
113
114+/*
115+ Another wrapper interface that is preserved
116+ for backwards compatibility.
117+ Use of this interface is not recommended.
118+ This was mainly used for testing within the
119+ library.
120+ */
121+
93void* sqlite3_get_table_idr(void* db,
122void* sqlite3_get_table_idr(void* db,
94 const char *sql){
123 const char *sql){
95
124
@@ -114,6 +143,19 @@ void* sqlite3_get_table_idr(void* db,
114
143
115}
144}
116
145
146+
147+
148+/*
149+
150+ This function executes queries.
151+ This can be used after preparing a query
152+ In case of error or library misuse
153+ it returns 1.
154+ It also calls step in order to obtain
155+ the row and column number and stores them
156+ in the struct. The row number is needed
157+ later on in get_data_type function.
158+ */
117int exec_db(void*p){
159int exec_db(void*p){
118
160
119 DBinfo* dbi =(DBinfo*) p;
161 DBinfo* dbi =(DBinfo*) p;
@@ -144,7 +186,10 @@ int exec_db(void*p){
144 return rc;
186 return rc;
145
187
146}
188}
147−
189+/*
190+ Returns row number from DB Struct
191+
192+ */
148int sqlite3_get_num_row_v2(void* p){
193int sqlite3_get_num_row_v2(void* p){
149
194
150 DBinfo* dbi =(DBinfo*) p;
195 DBinfo* dbi =(DBinfo*) p;
@@ -154,6 +199,10 @@ int sqlite3_get_num_row_v2(void* p){
154
199
155}
200}
156
201
202+/*
203+
204+ Returns column number from DB Struct
205+ */
157int sqlite3_get_num_col_v2(void* p){
206int sqlite3_get_num_col_v2(void* p){
158
207
159 DBinfo* dbi =(DBinfo*) p;
208 DBinfo* dbi =(DBinfo*) p;
@@ -162,7 +211,15 @@ int sqlite3_get_num_col_v2(void* p){
162
211
163}
212}
164
213
165−
214+/*
215+
216+ Another way of obtaining row number
217+ Thought this function gets the value
218+ from Table struct. The value is stored
219+ in the struct after calling get_table.
220+ Using this version is not recommended
221+ unless used with get_table
222+ */
166int sqlite3_get_num_row(void* p){
223int sqlite3_get_num_row(void* p){
167
224
168 Table* tbl =(Table*) p;
225 Table* tbl =(Table*) p;
@@ -172,6 +229,16 @@ int sqlite3_get_num_row(void* p){
172
229
173}
230}
174
231
232+/*
233+
234+ Another way of obtaining column number
235+ Thought this function gets the value
236+ from Table struct. The value is stored
237+ in the struct after calling get_table.
238+ Using this version is not recommended
239+ unless used with get_table
240+ */
241+
175int sqlite3_get_num_col(void* p){
242int sqlite3_get_num_col(void* p){
176
243
177 Table* tbl =(Table*) p;
244 Table* tbl =(Table*) p;
@@ -179,7 +246,18 @@ int sqlite3_get_num_col(void* p){
179 return col_number;
246 return col_number;
180
247
181}
248}
249+
250+/*
251+ This routine returns the type of value
252+ and must be called after prepare and exec.
253+ Since exec steps through database to obtain
254+ row number, this function calls reset to
255+ set the pointer to its initial state
256+ and then calls sqlite3_column_type
257+ to get the type
258+
259+*/
182−int sqlite3_get_data_type_v2(void* p, int nRow, int nCol){
260+int sqlite3_get_data_type(void* p, int nRow, int nCol){
183
261
184 DBinfo* dbi =(DBinfo*) p;
262 DBinfo* dbi =(DBinfo*) p;
185 int rc, type, row_counter;
263 int rc, type, row_counter;
@@ -198,9 +276,12 @@ int sqlite3_get_data_type_v2(void* p, int nRow, int nCol){
198 return type;
276 return type;
199
277
200}
278}
279+/*
280+
281+ Obtains the integer value in a given column
282+*/
201
283
202−
203−int sqlite3_get_val_int_v2(void* p, int nCol){
284+int sqlite3_get_val_int(void* p, int nCol){
204
285
205
286
206 DBinfo* dbi =(DBinfo*) p;
287 DBinfo* dbi =(DBinfo*) p;
@@ -212,81 +293,14 @@ int sqlite3_get_val_int_v2(void* p, int nCol){
212
293
213}
294}
214
295
215−int sqlite3_get_data_type(void* p,const char* tbl_name, int nRow, int nCol){
296+/*
216−
297+
217− DBinfo* dbi =(DBinfo*) p;
298+ Obtains the text value
218− sqlite3_stmt* stmt;
299+ Need to allocate memory to store the string
219− const char *tail;
300+ Use GC_malloc since Boehm garbage collector
220− int rc,i, val, counter;
301+ frees the resources .
221− const char* char_int;
302+ */
222−
223− counter =0;
224− strcpy(sql_query_buffer, "select * from ");
225− strcat(sql_query_buffer, tbl_name);
226−
227− rc = sqlite3_prepare_v2(dbi->db_ptr, sql_query_buffer, -1, &stmt, &tail);
228− if(rc != SQLITE_OK){
229− fprintf(stderr, "SQL Prepare error\n");
230− return rc;
231− }
232− rc = sqlite3_step(stmt);
233−
234− while (rc == SQLITE_ROW && counter < nRow){
235−
236− rc = sqlite3_step(stmt);
237− counter++;
238−
239− }
240−
241− val =sqlite3_column_type(stmt, nCol);
242−
243− rc =sqlite3_finalize(stmt);
244− if( rc != SQLITE_OK){
245− printf("Couldnt finalize:\n");
246− }
247− return val;
248−
249−}
250−
251−
252−int sqlite3_get_val_int(void* p,const char* tbl_name, int nRow, int nCol){
253−
254−
255− DBinfo* dbi =(DBinfo*) p;
256− sqlite3_stmt* stmt;
257− const char *tail;
258− int rc,i, val, counter;
259− const char* char_int;
260−
261− counter =0;
262− strcpy(sql_query_buffer, "select * from ");
263− strcat(sql_query_buffer, tbl_name);
264−
265− rc = sqlite3_prepare_v2(dbi->db_ptr, sql_query_buffer, -1, &stmt, &tail);
266− if(rc != SQLITE_OK){
267− fprintf(stderr, "SQL Prepare error\n");
268− return rc;
269− }
270− rc = sqlite3_step(stmt);
271−
272− while (rc == SQLITE_ROW && counter < nRow){
273−
274− rc = sqlite3_step(stmt);
275− counter++;
276−
277− }
278−
279− val =sqlite3_column_int(stmt, nCol);
280− rc =sqlite3_finalize(stmt);
281− if( rc != SQLITE_OK){
282− printf("Couldnt finalize:\n");
283− }
284− return val;
285−
286−
287−}
288−
289−const unsigned char* sqlite3_get_val_text_v2(void* p,int nCol){
303+const unsigned char* sqlite3_get_val_text(void* p,int nCol){
290
304
291
305
292 DBinfo* dbi =(DBinfo*) p;
306 DBinfo* dbi =(DBinfo*) p;
@@ -302,88 +316,7 @@ const unsigned char* sqlite3_get_val_text_v2(void* p,int nCol){
302
316
303}
317}
304
318
305−
306−
307−const unsigned char* sqlite3_get_val_text(void* p,const char* tbl_name,int nRow, int nCol){
308−
309−
310− DBinfo* dbi =(DBinfo*) p;
311− sqlite3_stmt* stmt;
312− const char *tail;
313− int rc,i, val, counter;
314− const unsigned char* text_val;
315−
316− counter =0;
317− strcpy(sql_query_buffer, "select * from ");
318− strcat(sql_query_buffer, tbl_name);
319−
320− rc = sqlite3_prepare_v2(dbi->db_ptr, sql_query_buffer, -1, &stmt, &tail);
321− if(rc != SQLITE_OK){
322− fprintf(stderr, "SQL Prepare error\n");
323− return NULL;
324− }
325− rc = sqlite3_step(stmt);
326−
327− while (rc == SQLITE_ROW && counter < nRow){
328−
329− rc = sqlite3_step(stmt);
330− counter++;
331−
332− }
333−
334−
335− array =(unsigned char *) GC_malloc(1000*sizeof(char));
336−
337− text_val =sqlite3_column_text(stmt, nCol);
338− memcpy(array, text_val, sizeof(text_val));
339− rc =sqlite3_finalize(stmt);
340− if( rc != SQLITE_OK){
341− printf("Couldn't finalize.\n");
342− }
343−
344− return array;
345−
346−}
347−
348−
349−float sqlite3_get_float(void* p,const char* tbl_name, int nRow, int nCol){
319+float sqlite3_get_float(void* p, int nCol){
350−
351− DBinfo* dbi =(DBinfo*) p;
352− sqlite3_stmt* stmt;
353− const char *tail;
354− int rc,i, val, counter;
355− double double_val;
356−
357−
358− counter =0;
359− strcpy(sql_query_buffer, "select * from ");
360− strcat(sql_query_buffer, tbl_name);
361−
362− rc = sqlite3_prepare_v2(dbi->db_ptr, sql_query_buffer, -1, &stmt, &tail);
363− if(rc != SQLITE_OK){
364− fprintf(stderr, "SQL Prepare error\n");
365−
366− }
367− rc = sqlite3_step(stmt);
368−
369− while (rc == SQLITE_ROW && counter < nRow){
370−
371−
372− rc = sqlite3_step(stmt);
373− counter++;
374−
375− }
376− double_val =sqlite3_column_double(stmt, nCol);
377− float float_val =(float)double_val;
378− rc =sqlite3_finalize(stmt);
379− if( rc != SQLITE_OK){
380− printf("Couldn't finalize.\n");
381− }
382− return float_val;
383−
384−}
385−
386−float sqlite3_get_float_v2(void* p, int nCol){
387
320
388 DBinfo* dbi =(DBinfo*) p;
321 DBinfo* dbi =(DBinfo*) p;
389 double double_val;
322 double double_val;
@@ -394,6 +327,9 @@ float sqlite3_get_float_v2(void* p, int nCol){
394
327
395}
328}
396
329
330+/*
331+ frees the pointer returned by get_table.
332+ */
397
333
398void sqlite3_free_table_idr(void* db){
334void sqlite3_free_table_idr(void* db){
399 Table* tbl =(Table*) db;
335 Table* tbl =(Table*) db;
@@ -409,15 +345,19 @@ int sqlite3_step_idr(void* db){
409 return rc;
345 return rc;
410}
346}
411
347
348+
349+/*
350+ Binds integer. This returns a pointer
351+ because of the implementation of BindMulti
352+ which binds multiple values
353+ */
412void* sqlite3_bind_int_idr(void* p,int index, int val){
354void* sqlite3_bind_int_idr(void* p,int index, int val){
413
355
414 DBinfo* dbi =(DBinfo*) p;
356 DBinfo* dbi =(DBinfo*) p;
415 int rc;
357 int rc;
416
358
417− //printf("\nThe statement has %d wildcards\n", sqlite3_bind_parameter_count(dbi->ppStmt));
418 rc =sqlite3_bind_int(dbi->ppStmt,index,val);
359 rc =sqlite3_bind_int(dbi->ppStmt,index,val);
419 if(rc != SQLITE_OK){
360 if(rc != SQLITE_OK){
420− printf("Error in binding\n");
421 return NULL;
361 return NULL;
422 }
362 }
423
363
@@ -439,16 +379,16 @@ void* sqlite3_bind_float_idr(void* p,int index, float val){
439 return dbi;
379 return dbi;
440}
380}
441
381
442−int sqlite3_bind_null_idr(void* p,int index){
382+void* sqlite3_bind_null_idr(void* p,int index){
443
383
444 DBinfo* dbi =(DBinfo*) p;
384 DBinfo* dbi =(DBinfo*) p;
445 int rc;
385 int rc;
446 rc =sqlite3_bind_null(dbi->ppStmt,index);
386 rc =sqlite3_bind_null(dbi->ppStmt,index);
447 if(rc != SQLITE_OK){
387 if(rc != SQLITE_OK){
448− return 1;
388+ return NULL;
449 }
389 }
450
390
451− return rc;
391+ return dbi;
452}
392}
453
393
454void* sqlite3_bind_text_idr(void* p,const char* text, int index,int length){
394void* sqlite3_bind_text_idr(void* p,const char* text, int index,int length){
@@ -457,13 +397,22 @@ void* sqlite3_bind_text_idr(void* p,const char* text, int index,int length){
457 int rc;
397 int rc;
458 rc =sqlite3_bind_text(dbi->ppStmt,index,text,length,SQLITE_STATIC);
398 rc =sqlite3_bind_text(dbi->ppStmt,index,text,length,SQLITE_STATIC);
459 if(rc != SQLITE_OK){
399 if(rc != SQLITE_OK){
460− printf("Error in binding\n");
461 return NULL;
400 return NULL;
462 }
401 }
463
402
464 return dbi;
403 return dbi;
465
404
466}
405}
406+
407+
408+/*
409+ Used for testing column count function.
410+ This function prepares query and by passing
411+ select all, gets the count for column number
412+ Could be used for testing. Not recommended to
413+ be used with prepare and exec
414+ */
415+
467int sqlite3_column_count_idr(void* db, const char* tbl_name){
416int sqlite3_column_count_idr(void* db, const char* tbl_name){
468 DBinfo* dbi =(DBinfo*) db;
417 DBinfo* dbi =(DBinfo*) db;
469 sqlite3_stmt* stmt;
418 sqlite3_stmt* stmt;
@@ -501,6 +450,11 @@ int sqlite3_data_count_idr(void* db){
501
450
502}
451}
503
452
453+
454+/*
455+ Must be called after prepare to clean up
456+ the resources.
457+ */
504int sqlite3_finalize_idr(void* db){
458int sqlite3_finalize_idr(void* db){
505
459
506 DBinfo* dbi=(DBinfo*) db;
460 DBinfo* dbi=(DBinfo*) db;
@@ -515,6 +469,11 @@ int sqlite3_complete_idr(const char *sql){
515
469
516
470
517}
471}
472+
473+/*
474+ Resets a prepared statement pointer
475+ to its initial state
476+ */
518int sqlite3_reset_idr(void* db){
477int sqlite3_reset_idr(void* db){
519
478
520 DBinfo* dbi=(DBinfo*) db;
479 DBinfo* dbi=(DBinfo*) db;
@@ -523,6 +482,11 @@ int sqlite3_reset_idr(void* db){
523
482
524}
483}
525
484
485+/*
486+ The following routines may be used to
487+ obtain column related information.
488+ */
489+
526const char *sqlite3_column_name_idr(void* db, int N){
490const char *sqlite3_column_name_idr(void* db, int N){
527
491
528 DBinfo* dbi=(DBinfo*) db;
492 DBinfo* dbi=(DBinfo*) db;
@@ -568,7 +532,9 @@ int sqlite3_column_int_idr(void* db, int iCol){
568 return res;
532 return res;
569
533
570}
534}
571−
535+/*
536+ Some back up functions
537+ */
572
538
573void* sqlite3_backup_init_idr(void* pDest,
539void* sqlite3_backup_init_idr(void* pDest,
574 const char *zDestName,
540 const char *zDestName,
@@ -596,10 +562,6 @@ int sqlite3_backup_step_idr(void *backup, int nPage){
596
562
597 DBbackup* dbi=(DBbackup*) backup;
563 DBbackup* dbi=(DBbackup*) backup;
598 int res = sqlite3_backup_step(dbi->backup, nPage);
564 int res = sqlite3_backup_step(dbi->backup, nPage);
599−
600− if( res == SQLITE_OK){
601− printf("Backup Success\n");
602− }
603 return res;
565 return res;
604
566
605
567
@@ -629,22 +591,11 @@ int sqlite3_backup_pagecount_idr(void *backup){
629
591
630}
592}
631
593
632−int sqlite3_value_bytes_idr(void* value){
594+/*
633−
595+ Get the length of string
634− DBinfo* dbi=(DBinfo*) value;
596+ Need this in Idris since length will not
635− int res = sqlite3_value_bytes(dbi->value);
597+ work on Strings.
636− return res;
598+ */
637−
638−}
639−
640−int sqlite3_value_bytes16_idr(void* value){
641−
642− DBinfo* dbi=(DBinfo*) value;
643− int res =sqlite3_value_bytes16(dbi->value);
644− return res;
645−
646−}
647−
648int strLength(const char * str){
599int strLength(const char * str){
649
600
650 int length = strlen(str);
601 int length = strlen(str);
contribs/lib/SQLite3/sqlite3api.h+13−22
@@ -14,22 +14,25 @@
14#include <gc.h>
14#include <gc.h>
15
15
16typedef struct {
16typedef struct {
17− sqlite3 *db_ptr;
17+ sqlite3 *db_ptr; // database pointer
18− sqlite3_stmt *ppStmt;
18+ sqlite3_stmt *ppStmt; // statement pointer
19− char buffer[1000];
19+ char buffer[1000]; // bufer to store errors returned by certain functions
20 const char *Ptr_tail;
20 const char *Ptr_tail;
21− sqlite3_blob *blob_ptr;
22 sqlite3_value *value;
21 sqlite3_value *value;
23− int row_count;
22+ int row_count; // row number store by exec function
24 int col_count;
23 int col_count;
25
24
26} DBinfo;
25} DBinfo;
27
26
27+// struct used for backup functions
28typedef struct {
28typedef struct {
29 sqlite3 *source_ptr;
29 sqlite3 *source_ptr;
30 sqlite3_backup *backup;
30 sqlite3_backup *backup;
31}DBbackup ;
31}DBbackup ;
32
32
33+// Table struct used by get_table function
34+// stores row and column
35+// returned by get_table
33typedef struct {
36typedef struct {
34 int num_row;
37 int num_row;
35 int num_col;
38 int num_col;
@@ -50,9 +53,7 @@ int sqlite3_exec_idr(void*, const char *sql);
50
53
51char* sqlite3_get_error(void* db);
54char* sqlite3_get_error(void* db);
52
55
53−const unsigned char* sqlite3_get_val_text(void* p,const char* tbl_name,int nRow, int nCol);
56+const unsigned char* sqlite3_get_val_text(void* p,int nCol);
54−
55−const unsigned char* sqlite3_get_val_text_v2(void* p,int nCol);
56
57
57void* sqlite3_get_table_idr(void* db, const char *sql);
58void* sqlite3_get_table_idr(void* db, const char *sql);
58
59
@@ -66,17 +67,11 @@ int sqlite3_get_num_row_v2(void* p);
66
67
67int sqlite3_get_num_col_v2(void* p);
68int sqlite3_get_num_col_v2(void* p);
68
69
69−int sqlite3_get_data_type(void* p,const char* tbl_name,int nRow, int nCol);
70+int sqlite3_get_data_type(void* p, int nRow, int nCol);
70−
71−int sqlite3_get_data_type_v2(void* p, int nRow, int nCol);
72−
73−int sqlite3_get_val_int_v2(void* p,int nCo);
74
71
75−int sqlite3_get_val_int(void* p,const char* tbl_name, int nRow, int nCol);
72+int sqlite3_get_val_int(void* p,int nCo);
76
73
77−float sqlite3_get_float(void* p,const char* tbl_name, int nRow, int nCol);
74+float sqlite3_get_float(void* p, int nCol);
78−
79−float sqlite3_get_float_v2(void* p, int nCol);
80
75
81void* sqlite3_prepare_idr(
76void* sqlite3_prepare_idr(
82 void *db, /* Database handle */
77 void *db, /* Database handle */
@@ -89,7 +84,7 @@ void* sqlite3_bind_float_idr(void* p,int index, float val);
89
84
90void* sqlite3_bind_int_idr(void* p,int index , int val);
85void* sqlite3_bind_int_idr(void* p,int index , int val);
91
86
92−int sqlite3_bind_null_idr(void* p,int index);
87+void* sqlite3_bind_null_idr(void* p,int index);
93
88
94void* sqlite3_bind_text_idr(void* p,const char* text, int index,int length);
89void* sqlite3_bind_text_idr(void* p,const char* text, int index,int length);
95
90
@@ -132,8 +127,4 @@ int sqlite3_backup_remaining_idr(void *backup);
132
127
133int sqlite3_backup_pagecount_idr(void *backup);
128int sqlite3_backup_pagecount_idr(void *backup);
134
129
135−int sqlite3_value_bytes_idr(void* value);
136−
137−int sqlite3_value_bytes16_idr(void* value);
138−
139int strLength(const char * str);
130int strLength(const char * str);