// // Mono.Data.SqliteClient.Sqlite.cs // // Provides C# bindings to the library sqlite.dll // // Author(s): Everaldo Canuto // // Copyright (C) 2004 Everaldo Canuto // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the // "Software"), to deal in the Software without restriction, including // without limitation the rights to use, copy, modify, merge, publish, // distribute, sublicense, and/or sell copies of the Software, and to // permit persons to whom the Software is furnished to do so, subject to // the following conditions: // // The above copyright notice and this permission notice shall be // included in all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // using System; using System.Security; using System.Runtime.InteropServices; namespace Mono.Data.SqliteClient { /// /// Represents the return values for sqlite_exec() and sqlite_step() /// internal enum SqliteError : int { /// Successful result OK = 0, /// SQL error or missing database ERROR = 1, /// An internal logic error in SQLite INTERNAL = 2, /// Access permission denied PERM = 3, /// Callback routine requested an abort ABORT = 4, /// The database file is locked BUSY = 5, /// A table in the database is locked LOCKED = 6, /// A malloc() failed NOMEM = 7, /// Attempt to write a readonly database READONLY = 8, /// Operation terminated by public const int interrupt() INTERRUPT = 9, /// Some kind of disk I/O error occurred IOERR = 10, /// The database disk image is malformed CORRUPT = 11, /// (Internal Only) Table or record not found NOTFOUND = 12, /// Insertion failed because database is full FULL = 13, /// Unable to open the database file CANTOPEN = 14, /// Database lock protocol error PROTOCOL = 15, /// (Internal Only) Database table is empty EMPTY = 16, /// The database schema changed SCHEMA = 17, /// Too much data for one row of a table TOOBIG = 18, /// Abort due to contraint violation CONSTRAINT= 19, /// Data type mismatch MISMATCH = 20, /// Library used incorrectly MISUSE = 21, /// Uses OS features not supported on host NOLFS = 22, /// Authorization denied AUTH = 23, /// Auxiliary database format error FORMAT = 24, /// 2nd parameter to sqlite_bind out of range RANGE = 25, /// File opened that is not a database file NOTADB = 26, /// sqlite_step() has another row ready ROW = 100, /// sqlite_step() has finished executing DONE = 101 } /// /// Provides the core of C# bindings to the library sqlite.dll /// internal sealed class Sqlite { #region PInvoke Functions [DllImport("sqlite")] internal static extern IntPtr sqlite_open (string dbname, int db_mode, out IntPtr errstr); [DllImport("sqlite")] internal static extern void sqlite_close (IntPtr sqlite_handle); [DllImport("sqlite")] internal static extern int sqlite_changes (IntPtr handle); [DllImport("sqlite")] internal static extern int sqlite_last_insert_rowid (IntPtr sqlite_handle); [DllImport ("sqlite")] internal static extern void sqliteFree (IntPtr ptr); [DllImport ("sqlite")] internal static extern SqliteError sqlite_compile (IntPtr sqlite_handle, string zSql, out IntPtr pzTail, out IntPtr pVm, out IntPtr errstr); [DllImport ("sqlite")] internal static extern SqliteError sqlite_step (IntPtr pVm, out int pN, out IntPtr pazValue, out IntPtr pazColName); [DllImport ("sqlite")] internal static extern SqliteError sqlite_finalize (IntPtr pVm, out IntPtr pzErrMsg); [DllImport ("sqlite")] internal static extern SqliteError sqlite_exec (IntPtr handle, string sql, IntPtr callback, IntPtr user_data, out IntPtr errstr_ptr); [DllImport("sqlite3")] internal static extern int sqlite3_open (string dbname, out IntPtr handle); [DllImport("sqlite3")] internal static extern void sqlite3_close (IntPtr sqlite_handle); [DllImport("sqlite3")] internal static extern string sqlite3_errmsg (IntPtr sqlite_handle); [DllImport("sqlite3")] internal static extern int sqlite3_changes (IntPtr handle); [DllImport("sqlite3")] internal static extern int sqlite3_last_insert_rowid (IntPtr sqlite_handle); [DllImport ("sqlite3")] internal static extern SqliteError sqlite3_prepare (IntPtr sqlite_handle, string zSql, int zSqllen, out IntPtr pVm, out IntPtr pzTail); [DllImport ("sqlite3")] internal static extern SqliteError sqlite3_step (IntPtr pVm); [DllImport ("sqlite3")] internal static extern SqliteError sqlite3_finalize (IntPtr pVm, out IntPtr pzErrMsg); [DllImport ("sqlite3")] internal static extern SqliteError sqlite3_exec (IntPtr handle, string sql, IntPtr callback, IntPtr user_data, out IntPtr errstr_ptr); [DllImport ("sqlite3")] internal static extern IntPtr sqlite3_column_name (IntPtr pVm, int col); [DllImport ("sqlite3")] internal static extern IntPtr sqlite3_column_text (IntPtr pVm, int col); [DllImport ("sqlite3")] internal static extern IntPtr sqlite3_column_blob (IntPtr pVm, int col); [DllImport ("sqlite3")] internal static extern int sqlite3_column_bytes (IntPtr pVm, int col); [DllImport ("sqlite3")] internal static extern int sqlite3_column_count (IntPtr pVm); [DllImport ("sqlite3")] internal static extern int sqlite3_column_type (IntPtr pVm, int col); [DllImport ("sqlite3")] internal static extern Int64 sqlite3_column_int64 (IntPtr pVm, int col); [DllImport ("sqlite3")] internal static extern double sqlite3_column_double (IntPtr pVm, int col); #endregion } }