2 // Mono.Data.SqliteClient.Sqlite.cs
4 // Provides C# bindings to the library sqlite.dll
6 // Author(s): Everaldo Canuto <everaldo_canuto@yahoo.com.br>
8 // Copyright (C) 2004 Everaldo Canuto
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using System
.Security
;
32 using System
.Runtime
.InteropServices
;
34 namespace Mono
.Data
.SqliteClient
37 /// Represents the return values for sqlite_exec() and sqlite_step()
39 public enum SqliteError
: int {
40 /// <value>Successful result</value>
42 /// <value>SQL error or missing database</value>
44 /// <value>An internal logic error in SQLite</value>
46 /// <value>Access permission denied</value>
48 /// <value>Callback routine requested an abort</value>
50 /// <value>The database file is locked</value>
52 /// <value>A table in the database is locked</value>
54 /// <value>A malloc() failed</value>
56 /// <value>Attempt to write a readonly database</value>
58 /// <value>Operation terminated by public const int interrupt()</value>
60 /// <value>Some kind of disk I/O error occurred</value>
62 /// <value>The database disk image is malformed</value>
64 /// <value>(Internal Only) Table or record not found</value>
66 /// <value>Insertion failed because database is full</value>
68 /// <value>Unable to open the database file</value>
70 /// <value>Database lock protocol error</value>
72 /// <value>(Internal Only) Database table is empty</value>
74 /// <value>The database schema changed</value>
76 /// <value>Too much data for one row of a table</value>
78 /// <value>Abort due to contraint violation</value>
80 /// <value>Data type mismatch</value>
82 /// <value>Library used incorrectly</value>
84 /// <value>Uses OS features not supported on host</value>
86 /// <value>Authorization denied</value>
88 /// <value>Auxiliary database format error</value>
90 /// <value>2nd parameter to sqlite_bind out of range</value>
92 /// <value>File opened that is not a database file</value>
94 /// <value>sqlite_step() has another row ready</value>
96 /// <value>sqlite_step() has finished executing</value>
101 /// Provides the core of C# bindings to the library sqlite.dll
103 internal sealed class Sqlite
{
105 #region PInvoke Functions
107 [DllImport("sqlite")]
108 internal static extern IntPtr
sqlite_open (string dbname
, int db_mode
, out IntPtr errstr
);
110 [DllImport("sqlite")]
111 internal static extern void sqlite_close (IntPtr sqlite_handle
);
113 [DllImport("sqlite")]
114 internal static extern int sqlite_changes (IntPtr handle
);
116 [DllImport("sqlite")]
117 internal static extern int sqlite_last_insert_rowid (IntPtr sqlite_handle
);
119 [DllImport ("sqlite")]
120 internal static extern void sqliteFree (IntPtr ptr
);
122 [DllImport ("sqlite")]
123 internal static extern SqliteError
sqlite_compile (IntPtr sqlite_handle
, string zSql
, out IntPtr pzTail
, out IntPtr pVm
, out IntPtr errstr
);
125 [DllImport ("sqlite")]
126 internal static extern SqliteError
sqlite_step (IntPtr pVm
, out int pN
, out IntPtr pazValue
, out IntPtr pazColName
);
128 [DllImport ("sqlite")]
129 internal static extern SqliteError
sqlite_finalize (IntPtr pVm
, out IntPtr pzErrMsg
);
131 [DllImport ("sqlite")]
132 internal static extern SqliteError
sqlite_exec (IntPtr handle
, string sql
, IntPtr callback
, IntPtr user_data
, out IntPtr errstr_ptr
);
134 [DllImport("sqlite3")]
135 internal static extern int sqlite3_open (string dbname
, out IntPtr handle
);
137 [DllImport("sqlite3")]
138 internal static extern void sqlite3_close (IntPtr sqlite_handle
);
140 [DllImport("sqlite3")]
141 internal static extern string sqlite3_errmsg (IntPtr sqlite_handle
);
143 [DllImport("sqlite3")]
144 internal static extern int sqlite3_changes (IntPtr handle
);
146 [DllImport("sqlite3")]
147 internal static extern int sqlite3_last_insert_rowid (IntPtr sqlite_handle
);
149 [DllImport ("sqlite3")]
150 internal static extern SqliteError
sqlite3_prepare (IntPtr sqlite_handle
, string zSql
, int zSqllen
, out IntPtr pVm
, out IntPtr pzTail
);
152 [DllImport ("sqlite3")]
153 internal static extern SqliteError
sqlite3_step (IntPtr pVm
);
155 [DllImport ("sqlite3")]
156 internal static extern SqliteError
sqlite3_finalize (IntPtr pVm
, out IntPtr pzErrMsg
);
158 [DllImport ("sqlite3")]
159 internal static extern SqliteError
sqlite3_exec (IntPtr handle
, string sql
, IntPtr callback
, IntPtr user_data
, out IntPtr errstr_ptr
);
161 [DllImport ("sqlite3")]
162 internal static extern IntPtr
sqlite3_column_name (IntPtr pVm
, int col
);
163 [DllImport ("sqlite3")]
164 internal static extern IntPtr
sqlite3_column_text (IntPtr pVm
, int col
);
165 [DllImport ("sqlite3")]
166 internal static extern IntPtr
sqlite3_column_blob (IntPtr pVm
, int col
);
167 [DllImport ("sqlite3")]
168 internal static extern int sqlite3_column_bytes (IntPtr pVm
, int col
);
169 [DllImport ("sqlite3")]
170 internal static extern int sqlite3_column_count (IntPtr pVm
);
171 [DllImport ("sqlite3")]
172 internal static extern int sqlite3_column_type (IntPtr pVm
, int col
);
173 [DllImport ("sqlite3")]
174 internal static extern Int64
sqlite3_column_int64 (IntPtr pVm
, int col
);
175 [DllImport ("sqlite3")]
176 internal static extern double sqlite3_column_double (IntPtr pVm
, int col
);