3 * Copyright (C) 2007 Jürg Billeter
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 * Jürg Billeter <j@bitron.ch>
23 [CCode (lower_case_cprefix = "sqlite3_", cheader_filename = "sqlite3.h")]
25 /* Database Connection Handle */
27 [CCode (free_function = "sqlite3_close", cname = "sqlite3", cprefix = "sqlite3_")]
28 public class Database {
29 public int busy_timeout (int ms);
30 public int changes ();
31 public int exec (string sql, Callback? sqlite3_callback = null, out string errmsg = null);
32 public int extended_result_codes (int onoff);
33 public int get_autocommit ();
34 public void interrupt ();
35 public int64 last_insert_rowid ();
36 public int total_changes ();
38 public int complete (string sql);
39 public int get_table (string sql, [CCode (array_length = false)] out weak string[] resultp, out int nrow, out int ncolumn, out string errmsg);
40 public static void free_table ([CCode (array_length = false)] string[] result);
41 public static int open (string filename, out Database db);
42 public static int open_v2 (string filename, out Database db, int flags = OPEN_READWRITE | OPEN_CREATE, string? zVfs = null);
43 public int errcode ();
44 public weak string errmsg ();
45 public int prepare (string sql, int n_bytes, out Statement stmt, out string tail = null);
46 public int prepare_v2 (string sql, int n_bytes, out Statement stmt, out string tail = null);
47 public void trace (TraceCallback? xtrace);
48 public void profile (ProfileCallback? xprofile);
49 public void commit_hook (CommitCallback? commit_hook);
50 public void rollback_hook (RollbackCallback? rollback_hook);
53 [CCode (instance_pos = 0)]
54 public delegate void TraceCallback (string message);
55 [CCode (instance_pos = 0)]
56 public delegate void ProfileCallback (string sql, uint64 time);
57 public delegate int CommitCallback ();
58 public delegate void RollbackCallback ();
60 /* Dynamically Typed Value Object */
62 [CCode (cname = "sqlite3_value")]
64 [CCode (cname = "sqlite3_value_blob")]
65 public void* to_blob ();
66 [CCode (cname = "sqlite3_value_bytes")]
67 public int to_bytes ();
68 [CCode (cname = "sqlite3_value_double")]
69 public double to_double ();
70 [CCode (cname = "sqlite3_value_int")]
72 [CCode (cname = "sqlite3_value_int64")]
73 public int64 to_int64 ();
74 [CCode (cname = "sqlite3_value_text")]
75 public weak string to_text ();
76 [CCode (cname = "sqlite3_value_type")]
77 public int to_type ();
78 [CCode (cname = "sqlite3_value_numeric_type")]
79 public int to_numeric_type ();
82 [CCode (cname = "sqlite3_callback", instance_pos = 0)]
83 public delegate int Callback (int n_columns, [CCode (array_length = false)] string[] values, [CCode (array_length = false)] string[] column_names);
85 [CCode (cname = "SQLITE_OK")]
87 [CCode (cname = "SQLITE_ERROR")]
88 public const int ERROR;
89 [CCode (cname = "SQLITE_INTERNAL")]
90 public const int INTERNAL;
91 [CCode (cname = "SQLITE_PERM")]
92 public const int PERM;
93 [CCode (cname = "SQLITE_ABORT")]
94 public const int ABORT;
95 [CCode (cname = "SQLITE_BUSY")]
96 public const int BUSY;
97 [CCode (cname = "SQLITE_LOCKED")]
98 public const int LOCKED;
99 [CCode (cname = "SQLITE_NOMEM")]
100 public const int NOMEM;
101 [CCode (cname = "SQLITE_READONLY")]
102 public const int READONLY;
103 [CCode (cname = "SQLITE_INTERRUPT")]
104 public const int INTERRUPT;
105 [CCode (cname = "SQLITE_IOERR")]
106 public const int IOERR;
107 [CCode (cname = "SQLITE_CORRUPT")]
108 public const int CORRUPT;
109 [CCode (cname = "SQLITE_NOTFOUND")]
110 public const int NOTFOUND;
111 [CCode (cname = "SQLITE_FULL")]
112 public const int FULL;
113 [CCode (cname = "SQLITE_CANTOPEN")]
114 public const int CANTOPEN;
115 [CCode (cname = "SQLITE_PROTOCOL")]
116 public const int PROTOCOL;
117 [CCode (cname = "SQLITE_EMPTY")]
118 public const int EMPTY;
119 [CCode (cname = "SQLITE_SCHEMA")]
120 public const int SCHEMA;
121 [CCode (cname = "SQLITE_TOOBIG")]
122 public const int TOOBIG;
123 [CCode (cname = "SQLITE_CONSTRAINT")]
124 public const int CONSTRAINT;
125 [CCode (cname = "SQLITE_MISMATCH")]
126 public const int MISMATCH;
127 [CCode (cname = "SQLITE_MISUSE")]
128 public const int MISUSE;
129 [CCode (cname = "SQLITE_NOLFS")]
130 public const int NOLFS;
131 [CCode (cname = "SQLITE_AUTH")]
132 public const int AUTH;
133 [CCode (cname = "SQLITE_FORMAT")]
134 public const int FORMAT;
135 [CCode (cname = "SQLITE_RANGE")]
136 public const int RANGE;
137 [CCode (cname = "SQLITE_NOTADB")]
138 public const int NOTADB;
139 [CCode (cname = "SQLITE_ROW")]
140 public const int ROW;
141 [CCode (cname = "SQLITE_DONE")]
142 public const int DONE;
143 [CCode (cname = "SQLITE_OPEN_READONLY")]
144 public const int OPEN_READONLY;
145 [CCode (cname = "SQLITE_OPEN_READWRITE")]
146 public const int OPEN_READWRITE;
147 [CCode (cname = "SQLITE_OPEN_CREATE")]
148 public const int OPEN_CREATE;
149 [CCode (cname = "SQLITE_INTEGER")]
150 public const int INTEGER;
151 [CCode (cname = "SQLITE_FLOAT")]
152 public const int FLOAT;
153 [CCode (cname = "SQLITE_BLOB")]
154 public const int BLOB;
155 [CCode (cname = "SQLITE_NULL")]
156 public const int NULL;
157 [CCode (cname = "SQLITE3_TEXT")]
158 public const int TEXT;
159 [CCode (cname = "SQLITE_MUTEX_FAST")]
160 public const int MUTEX_FAST;
161 [CCode (cname = "SQLITE_MUTEX_RECURSIVE")]
162 public const int MUTEX_RECURSIVE;
164 /* SQL Statement Object */
166 [CCode (free_function = "sqlite3_finalize", cname = "sqlite3_stmt", cprefix = "sqlite3_")]
167 public class Statement {
168 public int bind_parameter_count ();
169 public int bind_parameter_index (string name);
170 public weak string bind_parameter_name (int index);
171 public int clear_bindings ();
172 public int column_count ();
173 public int data_count ();
174 public weak Database db_handle ();
177 public int bind_blob (int index, void* value, int n, GLib.DestroyNotify destroy_notify);
178 public int bind_double (int index, double value);
179 public int bind_int (int index, int value);
180 public int bind_int64 (int index, int64 value);
181 public int bind_null (int index);
182 public int bind_text (int index, string# value, int n = -1, GLib.DestroyNotify destroy_notify = GLib.g_free);
183 public int bind_value (int index, Value value);
184 public int bind_zeroblob (int index, int n);
185 public void* column_blob (int col);
186 public int column_bytes (int col);
187 public double column_double (int col);
188 public int column_int (int col);
189 public int64 column_int64 (int col);
190 public weak string column_text (int col);
191 public int column_type (int col);
192 public weak Value column_value (int col);
193 public weak string column_name (int index);
194 public weak string sql ();
198 [CCode (cname = "sqlite3_mutex")]
200 [CCode (cname = "sqlite3_mutex_alloc")]
201 public Mutex (int mutex_type = MUTEX_RECURSIVE);
202 public void enter ();
204 public void leave ();