]> gitweb.factorcode.org Git - factor.git/blob - basis/db/sqlite/ffi/ffi.factor
use radix literals
[factor.git] / basis / db / sqlite / ffi / ffi.factor
1 ! Copyright (C) 2005 Chris Double, Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 ! An interface to the sqlite database. Tested against sqlite v3.1.3.
4 ! Not all functions have been wrapped.
5 USING: alien compiler kernel math namespaces sequences strings alien.syntax
6 system combinators alien.c-types alien.libraries ;
7 IN: db.sqlite.ffi
8
9 << "sqlite" {
10         { [ os windows? ]  [ "sqlite3.dll" ] }
11         { [ os macosx? ] [ "/usr/lib/libsqlite3.dylib" ] }
12         { [ os unix? ]  [ "libsqlite3.so" ] }
13     } cond cdecl add-library >>
14
15 ! Return values from sqlite functions
16 CONSTANT: SQLITE_OK           0 ! Successful result
17 CONSTANT: SQLITE_ERROR        1 ! SQL error or missing database
18 CONSTANT: SQLITE_INTERNAL     2 ! An internal logic error in SQLite 
19 CONSTANT: SQLITE_PERM         3 ! Access permission denied 
20 CONSTANT: SQLITE_ABORT        4 ! Callback routine requested an abort 
21 CONSTANT: SQLITE_BUSY         5 ! The database file is locked 
22 CONSTANT: SQLITE_LOCKED       6 ! A table in the database is locked 
23 CONSTANT: SQLITE_NOMEM        7 ! A malloc() failed 
24 CONSTANT: SQLITE_READONLY     8 ! Attempt to write a readonly database 
25 CONSTANT: SQLITE_INTERRUPT    9 ! Operation terminated by sqlite_interrupt() 
26 CONSTANT: SQLITE_IOERR       10 ! Some kind of disk I/O error occurred 
27 CONSTANT: SQLITE_CORRUPT     11 ! The database disk image is malformed 
28 CONSTANT: SQLITE_NOTFOUND    12 ! (Internal Only) Table or record not found 
29 CONSTANT: SQLITE_FULL        13 ! Insertion failed because database is full 
30 CONSTANT: SQLITE_CANTOPEN    14 ! Unable to open the database file 
31 CONSTANT: SQLITE_PROTOCOL    15 ! Database lock protocol error 
32 CONSTANT: SQLITE_EMPTY       16 ! (Internal Only) Database table is empty 
33 CONSTANT: SQLITE_SCHEMA      17 ! The database schema changed 
34 CONSTANT: SQLITE_TOOBIG      18 ! Too much data for one row of a table 
35 CONSTANT: SQLITE_CONSTRAINT  19 ! Abort due to contraint violation 
36 CONSTANT: SQLITE_MISMATCH    20 ! Data type mismatch 
37 CONSTANT: SQLITE_MISUSE      21 ! Library used incorrectly 
38 CONSTANT: SQLITE_NOLFS       22 ! Uses OS features not supported on host 
39 CONSTANT: SQLITE_AUTH        23 ! Authorization denied 
40 CONSTANT: SQLITE_FORMAT      24 ! Auxiliary database format error
41 CONSTANT: SQLITE_RANGE       25 ! 2nd parameter to sqlite3_bind out of range
42 CONSTANT: SQLITE_NOTADB      26 ! File opened that is not a database file
43
44 : sqlite-error-messages ( -- seq ) {
45     "Successful result"
46     "SQL error or missing database"
47     "An internal logic error in SQLite"
48     "Access permission denied"
49     "Callback routine requested an abort"
50     "The database file is locked"
51     "A table in the database is locked"
52     "A malloc() failed"
53     "Attempt to write a readonly database"
54     "Operation terminated by sqlite_interrupt()"
55     "Some kind of disk I/O error occurred"
56     "The database disk image is malformed"
57     "(Internal Only) Table or record not found"
58     "Insertion failed because database is full"
59     "Unable to open the database file"
60     "Database lock protocol error"
61     "(Internal Only) Database table is empty"
62     "The database schema changed"
63     "Too much data for one row of a table"
64     "Abort due to contraint violation"
65     "Data type mismatch"
66     "Library used incorrectly"
67     "Uses OS features not supported on host"
68     "Authorization denied"
69     "Auxiliary database format error"
70     "2nd parameter to sqlite3_bind out of range"
71     "File opened that is not a database file"
72 } ;
73
74 ! Return values from sqlite3_step
75 CONSTANT: SQLITE_ROW         100
76 CONSTANT: SQLITE_DONE        101
77
78 ! Return values from the sqlite3_column_type function
79 CONSTANT: SQLITE_INTEGER     1
80 CONSTANT: SQLITE_FLOAT       2
81 CONSTANT: SQLITE_TEXT        3
82 CONSTANT: SQLITE_BLOB        4
83 CONSTANT: SQLITE_NULL        5
84
85 ! Values for the 'destructor' parameter of the 'bind' routines. 
86 CONSTANT: SQLITE_STATIC      0
87 CONSTANT: SQLITE_TRANSIENT   -1
88
89 CONSTANT: SQLITE_OPEN_READONLY         0x00000001
90 CONSTANT: SQLITE_OPEN_READWRITE        0x00000002
91 CONSTANT: SQLITE_OPEN_CREATE           0x00000004
92 CONSTANT: SQLITE_OPEN_DELETEONCLOSE    0x00000008
93 CONSTANT: SQLITE_OPEN_EXCLUSIVE        0x00000010
94 CONSTANT: SQLITE_OPEN_MAIN_DB          0x00000100
95 CONSTANT: SQLITE_OPEN_TEMP_DB          0x00000200
96 CONSTANT: SQLITE_OPEN_TRANSIENT_DB     0x00000400
97 CONSTANT: SQLITE_OPEN_MAIN_JOURNAL     0x00000800
98 CONSTANT: SQLITE_OPEN_TEMP_JOURNAL     0x00001000
99 CONSTANT: SQLITE_OPEN_SUBJOURNAL       0x00002000
100 CONSTANT: SQLITE_OPEN_MASTER_JOURNAL   0x00004000
101
102 C-TYPE: sqlite3
103 C-TYPE: sqlite3_stmt
104 TYPEDEF: longlong sqlite3_int64
105 TYPEDEF: ulonglong sqlite3_uint64
106
107 LIBRARY: sqlite
108 FUNCTION: int sqlite3_open ( c-string filename, void* ppDb ) ;
109 FUNCTION: int sqlite3_close ( sqlite3* pDb ) ;
110 FUNCTION: c-string sqlite3_errmsg ( sqlite3* pDb ) ;
111 FUNCTION: int sqlite3_prepare ( sqlite3* pDb, c-string zSql, int nBytes, void* ppStmt, void* pzTail ) ;
112 FUNCTION: int sqlite3_prepare_v2 ( sqlite3* pDb, c-string zSql, int nBytes, void* ppStmt, void* pzTail ) ;
113 FUNCTION: int sqlite3_finalize ( sqlite3_stmt* pStmt ) ;
114 FUNCTION: int sqlite3_reset ( sqlite3_stmt* pStmt ) ;
115 FUNCTION: int sqlite3_step ( sqlite3_stmt* pStmt ) ;
116 FUNCTION: sqlite3_uint64 sqlite3_last_insert_rowid ( sqlite3* pStmt ) ;
117 FUNCTION: int sqlite3_bind_blob ( sqlite3_stmt* pStmt, int index, void* ptr, int len, int destructor ) ;
118 FUNCTION: int sqlite3_bind_double ( sqlite3_stmt* pStmt, int index, double x ) ;
119 FUNCTION: int sqlite3_bind_int ( sqlite3_stmt* pStmt, int index, int n ) ;
120 FUNCTION: int sqlite3_bind_int64 ( sqlite3_stmt* pStmt, int index, sqlite3_int64 n ) ;
121 ! Bind the same function as above, but for unsigned 64bit integers
122 FUNCTION-ALIAS: sqlite3-bind-uint64
123     int sqlite3_bind_int64 ( sqlite3_stmt* pStmt, int index, sqlite3_uint64 in64 ) ;
124 FUNCTION: int sqlite3_bind_null ( sqlite3_stmt* pStmt, int n ) ;
125 FUNCTION: int sqlite3_bind_text ( sqlite3_stmt* pStmt, int index, c-string text, int len, int destructor ) ;
126 FUNCTION: int sqlite3_bind_parameter_index ( sqlite3_stmt* pStmt, c-string name ) ;
127 FUNCTION: int sqlite3_clear_bindings ( sqlite3_stmt* pStmt ) ;
128 FUNCTION: int sqlite3_column_count ( sqlite3_stmt* pStmt ) ;
129 FUNCTION: void* sqlite3_column_blob ( sqlite3_stmt* pStmt, int col ) ;
130 FUNCTION: int sqlite3_column_bytes ( sqlite3_stmt* pStmt, int col ) ;
131 FUNCTION: c-string sqlite3_column_decltype ( sqlite3_stmt* pStmt, int col ) ;
132 FUNCTION: int sqlite3_column_int ( sqlite3_stmt* pStmt, int col ) ;
133 FUNCTION: sqlite3_int64 sqlite3_column_int64 ( sqlite3_stmt* pStmt, int col ) ;
134 ! Bind the same function as above, but for unsigned 64bit integers
135 FUNCTION-ALIAS: sqlite3-column-uint64
136     sqlite3_uint64 sqlite3_column_int64 ( sqlite3_stmt* pStmt, int col ) ;
137 FUNCTION: double sqlite3_column_double ( sqlite3_stmt* pStmt, int col ) ;
138 FUNCTION: c-string sqlite3_column_name ( sqlite3_stmt* pStmt, int col ) ;
139 FUNCTION: c-string sqlite3_column_text ( sqlite3_stmt* pStmt, int col ) ;
140 FUNCTION: int sqlite3_column_type ( sqlite3_stmt* pStmt, int col ) ;