'SQLite3 Demo
'needs SQLite3.dll
'
'SQLITE_API int sqlite3_open(
' const char *filename, /* Database filename (UTF-8) */
' sqlite3 **ppDb /* OUT: SQLite db handle */
');
'
'
'SQLITE_API int sqlite3_exec(
'sqlite3*, /* An open database */
'const char *sql, /* SQL to be evaluated */
'int (*callback)(void*,int,char**,char**), /* Callback function */
'void *, /* 1st argument to callback */
'char **errmsg /* Error msg written here */
');
'
'
'SQLITE_API int sqlite3_prepare_v2(
' sqlite3 *db, /* Database handle */
' const char *zSql, /* SQL statement, UTF-8 encoded */
' int nByte, /* Maximum length of zSql in bytes. */
' sqlite3_stmt **ppStmt, /* OUT: Statement handle */
' const char **pzTail /* OUT: Pointer to unused portion of zSql */
');
'
'
'SQLITE_API int sqlite3_step(sqlite3_stmt*);
'
'
'SQLITE_API const unsigned char *sqlite3_column_text(sqlite3_stmt*, int iCol);
'
'
'SQLITE_API int sqlite3_close(sqlite3 *);
'
'
extern lib "sqlite3.dll"
sys sqlite3_open (zstring*name,sys*db)
sys sqlite3_exec (sys db,zstring* s, sys p1, sys p2, sys*dberr)
sys sqlite3_prepare_v2 (sys db, zstring*s, sys p1, sys*stmt, sys p2)
sys sqlite3_step (sys n)
zstring* sqlite3_column_text (sys row, sys col)
sys sqlite3_close (sys db)
'
end extern
'
sys SQLITE_ROW = 100
sys hdb
sys dberr
sys stmt
'
zstring *errmsg
string cr=chr(13)+chr(10)
string pr="DataBase Listing:" cr
'
sqlite3_open "testsql",hdb
'
sqlite3_exec hdb, "CREATE TABLE demo(someval INTEGER, sometxt TEXT);", 0, 0, dberr
sqlite3_exec hdb, "INSERT INTO demo VALUES (123, 'Hello');", 0, 0, dberr
sqlite3_exec hdb, "INSERT INTO demo VALUES (234, 'cruel');", 0, 0, dberr
sqlite3_exec hdb, "INSERT INTO demo VALUES (345, 'world');", 0, 0, dberr
'
result = sqlite3_prepare_v2 hdb, "SELECT * FROM demo;" cr, -1, stmt, 0
'
if dberr then @errmsg=dberr : print errmsg
'
while sqlite3_step(stmt) = SQLITE_ROW
pr+=sqlite3_column_text(stmt, 0) " - " sqlite3_column_text(stmt, 1) cr
wend
'
sqlite3_close hdb
print pr