source: oup/releases/0.18a2/SQLite3.pas@ 595

Last change on this file since 595 was 21, checked in by alloc, 18 years ago
File size: 7.6 KB
RevLine 
[21]1unit SQLite3;
2
3{
4 Simplified interface for SQLite.
5 Updated for Sqlite 3 by Tim Anderson (tim@itwriting.com)
6 Note: NOT COMPLETE for version 3, just minimal functionality
7 Adapted from file created by Pablo Pissanetzky (pablo@myhtpc.net)
8 which was based on SQLite.pas by Ben Hochstrasser (bhoc@surfeu.ch)
9}
10
11interface
12
13const
14// Return values for sqlite3_exec() and sqlite3_step()
15
16SQLITE_OK = 0; // Successful result
17SQLITE_ERROR = 1; // SQL error or missing database
18SQLITE_INTERNAL = 2; // An internal logic error in SQLite
19SQLITE_PERM = 3 ; // Access permission denied
20SQLITE_ABORT = 4; // Callback routine requested an abort
21SQLITE_BUSY = 5; // The database file is locked
22SQLITE_LOCKED = 6; // A table in the database is locked
23SQLITE_NOMEM = 7; // A malloc() failed
24SQLITE_READONLY = 8; // Attempt to write a readonly database
25SQLITE_INTERRUPT = 9; // Operation terminated by sqlite3_interrupt()
26SQLITE_IOERR = 10; // Some kind of disk I/O error occurred
27SQLITE_CORRUPT = 11; // The database disk image is malformed
28SQLITE_NOTFOUND = 12; // (Internal Only) Table or record not found
29SQLITE_FULL = 13; // Insertion failed because database is full
30SQLITE_CANTOPEN = 14; // Unable to open the database file
31SQLITE_PROTOCOL = 15; // Database lock protocol error
32SQLITE_EMPTY = 16; // Database is empty
33SQLITE_SCHEMA = 17; // The database schema changed
34SQLITE_TOOBIG = 18; // Too much data for one row of a table
35SQLITE_CONSTRAINT = 19; // Abort due to contraint violation
36SQLITE_MISMATCH = 20; // Data type mismatch
37SQLITE_MISUSE = 21; // Library used incorrectly
38SQLITE_NOLFS = 22; // Uses OS features not supported on host
39SQLITE_AUTH = 23; // Authorization denied
40SQLITE_FORMAT = 24; // Auxiliary database format error
41SQLITE_RANGE = 25; // 2nd parameter to sqlite3_bind out of range
42SQLITE_NOTADB = 26; // File opened that is not a database file
43SQLITE_ROW = 100; // sqlite3_step() has another row ready
44SQLITE_DONE = 101; // sqlite3_step() has finished executing
45
46SQLITE_INTEGER = 1;
47SQLITE_FLOAT = 2;
48SQLITE_TEXT = 3;
49SQLITE_BLOB = 4;
50SQLITE_NULL = 5;
51
52type
53TSQLiteDB = Pointer;
54TSQLiteResult = ^PChar;
55TSQLiteStmt = Pointer;
56
57function SQLite3_Open (dbname: PChar; var db: TSqliteDB): integer; cdecl; external 'sqlite3.dll' name 'sqlite3_open';
58function SQLite3_Close (db: TSQLiteDB): integer; cdecl; external 'sqlite3.dll' name 'sqlite3_close';
59function SQLite3_Exec (db: TSQLiteDB; SQLStatement: PChar; CallbackPtr: Pointer; Sender: TObject; var ErrMsg: PChar): integer; cdecl; external 'sqlite3.dll' name 'sqlite3_exec';
60function SQLite3_Version (): PChar; cdecl; external 'sqlite3.dll' name 'sqlite3_libversion';
61function SQLite3_ErrMsg (db: TSQLiteDB): PChar; cdecl; external 'sqlite3.dll' name 'sqlite3_errmsg';
62function SQLite3_ErrCode (db: TSQLiteDB): integer; cdecl; external 'sqlite3.dll' name 'sqlite3_errcode';
63procedure SQlite3_Free (P: PChar); cdecl; external 'sqlite3.dll' name 'sqlite3_free';
64function SQLite3_GetTable (db: TSQLiteDB; SQLStatement: PChar; var ResultPtr: TSQLiteResult; var RowCount: Cardinal; var ColCount: Cardinal; var ErrMsg: PChar): integer; cdecl; external 'sqlite3.dll' name 'sqlite3_get_table';
65procedure SQLite3_FreeTable (Table:TSQLiteResult ); cdecl; external 'sqlite3.dll' name 'sqlite3_free_table';
66function SQLite3_Complete (P: PChar): boolean; cdecl; external 'sqlite3.dll' name 'sqlite3_complete';
67function SQLite3_LastInsertRowID(db: TSQLiteDB): int64; cdecl; external 'sqlite3.dll' name 'sqlite3_last_insert_rowid';
68procedure SQLite3_Interrupt (db: TSQLiteDB); cdecl; external 'sqlite3.dll' name 'sqlite3_interrupt';
69procedure SQLite3_BusyHandler (db: TSQLiteDB; CallbackPtr: Pointer; Sender: TObject); cdecl; external 'sqlite3.dll' name'sqlite3_busy_handler' ;
70procedure SQLite3_BusyTimeout (db: TSQLiteDB; TimeOut: integer); cdecl; external 'sqlite3.dll' name 'sqlite3_busy_timeout';
71function SQLite3_Changes (db: TSQLiteDB): integer; cdecl; external 'sqlite3.dll' name 'sqlite3_changes';
72function SQLite3_TotalChanges (db: TSQLiteDB): integer; cdecl; external 'sqlite3.dll' name 'sqlite3_total_changes';
73function SQLite3_Prepare (db: TSQLiteDB; SQLStatement: PChar; nBytes: integer; var hStmt: TSqliteStmt; var pzTail: PChar): integer; cdecl; external 'sqlite3.dll' name 'sqlite3_prepare';
74function SQLite3_ColumnCount (hStmt: TSqliteStmt): integer; cdecl; external 'sqlite3.dll' name 'sqlite3_column_count';
75function Sqlite3_ColumnName (hStmt: TSqliteStmt; ColNum: integer): pchar; cdecl; external 'sqlite3.dll' name 'sqlite3_column_name';
76function Sqlite3_ColumnDeclType (hStmt: TSqliteStmt; ColNum: integer): pchar; cdecl; external 'sqlite3.dll' name 'sqlite3_column_decltype';
77function Sqlite3_Step (hStmt: TSqliteStmt): integer; cdecl; external 'sqlite3.dll' name 'sqlite3_step';
78function SQLite3_DataCount (hStmt: TSqliteStmt): integer; cdecl; external 'sqlite3.dll' name 'sqlite3_data_count';
79
80function Sqlite3_ColumnBlob (hStmt: TSqliteStmt; ColNum: integer):pointer; cdecl; external 'sqlite3.dll' name 'sqlite3_column_blob';
81function Sqlite3_ColumnBytes (hStmt: TSqliteStmt; ColNum: integer): integer; cdecl; external 'sqlite3.dll' name 'sqlite3_column_bytes';
82function Sqlite3_ColumnDouble (hStmt: TSqliteStmt; ColNum: integer): double; cdecl; external 'sqlite3.dll' name 'sqlite3_column_double';
83function Sqlite3_ColumnInt (hStmt: TSqliteStmt; ColNum: integer): integer; cdecl; external 'sqlite3.dll' name 'sqlite3_column_int';
84function Sqlite3_ColumnText (hStmt: TSqliteStmt; ColNum: integer): pchar; cdecl; external 'sqlite3.dll' name 'sqlite3_column_text';
85function Sqlite3_ColumnType (hStmt: TSqliteStmt; ColNum: integer): integer; cdecl; external 'sqlite3.dll' name 'sqlite3_column_type';
86 // function Sqlite3_ColumnInt64 (hStmt: TSqliteStmt; ColNum: integer): SqliteInt64; cdecl; external 'sqlite3.dll' name 'sqlite3_column_int64';
87function SQLite3_Finalize (hStmt: TSqliteStmt): integer; cdecl; external 'sqlite3.dll' name 'sqlite3_finalize';
88function SQLite3_Reset (hStmt: TSqliteStmt): integer; cdecl; external 'sqlite3.dll' name 'sqlite3_reset';
89
90//
91// In the SQL strings input to sqlite3_prepare() and sqlite3_prepare16(),
92// one or more literals can be replace by a wildcard "?" or ":N:" where
93// N is an integer. These value of these wildcard literals can be set
94// using the routines listed below.
95//
96// In every case, the first parameter is a pointer to the sqlite3_stmt
97// structure returned from sqlite3_prepare(). The second parameter is the
98// index of the wildcard. The first "?" has an index of 1. ":N:" wildcards
99// use the index N.
100//
101 // The fifth parameter to sqlite3_bind_blob(), sqlite3_bind_text(), and
102 //sqlite3_bind_text16() is a destructor used to dispose of the BLOB or
103//text after SQLite has finished with it. If the fifth argument is the
104// special value SQLITE_STATIC, then the library assumes that the information
105// is in static, unmanaged space and does not need to be freed. If the
106// fifth argument has the value SQLITE_TRANSIENT, then SQLite makes its
107// own private copy of the data.
108//
109// The sqlite3_bind_* routine must be called before sqlite3_step() after
110// an sqlite3_prepare() or sqlite3_reset(). Unbound wildcards are interpreted
111// as NULL.
112//
113
114function SQLite3_BindBlob(hStmt: TSqliteStmt; ParamNum: integer;
115ptrData: pointer; numBytes: integer; ptrDestructor: pointer): integer;
116cdecl; external 'sqlite3.dll' name 'sqlite3_bind_blob';
117
118implementation
119
120end.
Note: See TracBrowser for help on using the repository browser.