**** Merged from MCS ****
[mono-project.git] / mcs / class / Mono.Data.SqliteClient / Mono.Data.SqliteClient / Sqlite.cs
blobe82ca0f56c7fc92ca50f3f9e30604460a8c7cc6a
1 //
2 // Mono.Data.SqliteClient.Sqlite.cs
3 //
4 // Provides C# bindings to the library sqlite.dll
5 //
6 // Author(s): Everaldo Canuto <everaldo_canuto@yahoo.com.br>
7 //
8 // Copyright (C) 2004 Everaldo Canuto
9 //
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:
17 //
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
20 //
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.
30 using System;
31 using System.Security;
32 using System.Runtime.InteropServices;
34 namespace Mono.Data.SqliteClient
36 /// <summary>
37 /// Represents the return values for sqlite_exec() and sqlite_step()
38 /// </summary>
39 internal enum SqliteError : int {
40 /// <value>Successful result</value>
41 OK = 0,
42 /// <value>SQL error or missing database</value>
43 ERROR = 1,
44 /// <value>An internal logic error in SQLite</value>
45 INTERNAL = 2,
46 /// <value>Access permission denied</value>
47 PERM = 3,
48 /// <value>Callback routine requested an abort</value>
49 ABORT = 4,
50 /// <value>The database file is locked</value>
51 BUSY = 5,
52 /// <value>A table in the database is locked</value>
53 LOCKED = 6,
54 /// <value>A malloc() failed</value>
55 NOMEM = 7,
56 /// <value>Attempt to write a readonly database</value>
57 READONLY = 8,
58 /// <value>Operation terminated by public const int interrupt()</value>
59 INTERRUPT = 9,
60 /// <value>Some kind of disk I/O error occurred</value>
61 IOERR = 10,
62 /// <value>The database disk image is malformed</value>
63 CORRUPT = 11,
64 /// <value>(Internal Only) Table or record not found</value>
65 NOTFOUND = 12,
66 /// <value>Insertion failed because database is full</value>
67 FULL = 13,
68 /// <value>Unable to open the database file</value>
69 CANTOPEN = 14,
70 /// <value>Database lock protocol error</value>
71 PROTOCOL = 15,
72 /// <value>(Internal Only) Database table is empty</value>
73 EMPTY = 16,
74 /// <value>The database schema changed</value>
75 SCHEMA = 17,
76 /// <value>Too much data for one row of a table</value>
77 TOOBIG = 18,
78 /// <value>Abort due to contraint violation</value>
79 CONSTRAINT= 19,
80 /// <value>Data type mismatch</value>
81 MISMATCH = 20,
82 /// <value>Library used incorrectly</value>
83 MISUSE = 21,
84 /// <value>Uses OS features not supported on host</value>
85 NOLFS = 22,
86 /// <value>Authorization denied</value>
87 AUTH = 23,
88 /// <value>Auxiliary database format error</value>
89 FORMAT = 24,
90 /// <value>2nd parameter to sqlite_bind out of range</value>
91 RANGE = 25,
92 /// <value>File opened that is not a database file</value>
93 NOTADB = 26,
94 /// <value>sqlite_step() has another row ready</value>
95 ROW = 100,
96 /// <value>sqlite_step() has finished executing</value>
97 DONE = 101
100 /// <summary>
101 /// Provides the core of C# bindings to the library sqlite.dll
102 /// </summary>
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 string errstr);
110 [DllImport("sqlite")]
111 internal static extern void sqlite_close (IntPtr sqlite_handle);
113 [DllImport("sqlite")]
114 internal unsafe static extern SqliteError sqlite_exec (IntPtr handle, string sql, SqliteCallbackFunction callback, IntPtr user_data, byte **errstr_ptr);
116 [DllImport("sqlite")]
117 internal static extern int sqlite_changes (IntPtr handle);
119 [DllImport("sqlite")]
120 internal static extern int sqlite_last_insert_rowid (IntPtr sqlite_handle);
122 [DllImport ("sqlite")]
123 internal unsafe static extern void sqliteFree (void *ptr);
125 #endregion
127 #region Delegates
129 internal unsafe delegate int SqliteCallbackFunction (ref object o, int argc, sbyte **argv, sbyte **colnames);
131 #endregion