'
' Demonstration program for SQlite3
'
' PvE - May 2010, GPL.
' ------------------------------------------------------------------------
' Include the binding
INCLUDE "sqlite3.bac"
' Name of the data file
CONST datafile$ = "data.sdb"
' Print version
PRINT NL$, "Using SQLite version: ", DB_VERSION$()
' Create a database
mydb = DB_OPEN(datafile$)
' Create table and add data
DB_SQL(mydb, "CREATE TABLE demo(someval INTEGER, sometxt TEXT);")
DB_SQL(mydb, "INSERT INTO demo VALUES (123, 'Hello');")
DB_SQL(mydb, "INSERT INTO demo VALUES (234, 'cruel');")
DB_SQL(mydb, "INSERT INTO demo VALUES (345, 'world');")
DB_SQL(mydb, "COMMIT;")
' Fetch some data
res = DB_SQL(mydb, "SELECT * FROM demo;")
IF res IS 0 THEN PRINT NL$, DB_RESULT$
ELSE PRINT NL$, DB_ERROR$
' Count the records
DB_SQL(mydb, "SELECT COUNT(*) FROM demo;")
PRINT "Amount of records: ", MID$(DB_RESULT$, INSTR(DB_RESULT$, NL$) + 1)
' Close database
res = DB_CLOSE(mydb)
' Print some info
PRINT "Size of data file is: ", FILELEN(datafile$), " bytes.", NL$
' Delete data file again
DELETE FILE datafile$