This class provides an interface to SQLite databases.
:class SQLiteDB <SUPER Object
SQLiteDB is an interface to SQLite.
:M ERR: ( -- ) \ thows an error on any problem
Displays any error that might have occured.
:M Open: ( str len -- )
Opens a database file so we can execute operations on it.
If the string is ":memory:" the database is actually created
in memory instead of on disk, and should be faster.
:M Close: ( -- flag )
Closes the database. You can still open another database with the same object after closing, if desired.
:M Version: ( -- str len )
Returns the version of SQLite being used
:M Execute: ( str len -- )
Execute a SQL query on the cursor. Any returned data will be in the cursor.
:M Requery: ( -- )
Rerun the last query.
:M FieldCnt: ( -- n )
Returns the number of columns in the current record.
:M FieldType: ( field -- DataTypeEnum )
Returns the data type constant of the given column. Possible data types are:
SQLITE_INTEGER |
SQLITE_FLOAT |
SQLITE_TEXT |
SQLITE_BLOB |
SQLITE_NULL |
:M FieldName: ( field -- str len )
Returns the column name of the given column number.
:M GetInt: ( field -- int )
Returns an integer value of the given column on the current row.
:M GetDouble: ( field -- d )
Returns the double of the given column on the current row.
:M GetFloat: ( field -- float )
Returns the floating point value of the given column on the current row.
:M GetStr: ( field -- str len )
Returns the string of the given column on the current row. May be much longer than 255
:M GetBLOB: ( field -- addr len )
Returns the Binary Buffer of the given column on the current row. This binary data may be anything.
:M isNull?: ( field -- flag )
Returns true if the given field for the given flag is null
:M NextRow: ( -- flag )
Goes to the next row of the query result. If there are no more rows, it will return true
:M BindInt: ( n i -- )
Binds a '?' in the query string to a integer. If there are no more question marks in the query string, the query will execute.
:M BindDouble: ( d i -- )
Binds a '?' in the query string to a double int. If there are no more question marks in the query string, the query will execute.
:M BindFloat: ( f i -- )
Binds a '?' in the query string to a floating point number. If there are no more question marks in the query string, the query will execute.
:M BindStr: ( str len i -- )
Binds a '?' in the query string to a string. If there are no more question marks in the query string, the query will execute.
:M BindBlob: ( str len i -- )
Binds a '?' in the query string to a blob (binary buffer object, or in simpler terms, a bunch of bytes). If there are no more question marks in the query string, the query will execute.
SQLiteDB sqlite s" c:\test.db" open: sqlite
SQLiteDB sqlite s" :memory:" open: sqlite
close: sqlite
s" CREATE TABLE idtoname (id int, name varchar)" execute: sqlite
s" INSERT INTO idtoname(id, name) VALUES(?,?)" execute: sqlite 1 0 bindint: sqlite s" Jim Hawkins" 1 bindstr: sqlite s" INSERT INTO idtoname(id, name) VALUES(?,?)" execute: sqlite 2 0 bindint: sqlite s" Billy Bones" 1 bindstr: sqlite s" INSERT INTO idtoname(id, name) VALUES(?,?)" execute: sqlite 3 0 bindint: sqlite s" Long John Silver" 1 bindstr: sqlite
: qdump ( -- ) fieldcnt: sqlite 0 ?do i fieldname: sqlite type tab loop cr cr begin fieldcnt: sqlite 0 ?do i getstr: sqlite type tab loop cr nextrow: sqlite until ; s" SELECT * FROM idtoname WHERE id < 1000 ORDER BY name DESC" execute: sqlite cr qdump
s" DROP TABLE idtoname" execute: sqlite