summaryrefslogtreecommitdiff
path: root/vapi/sqlite3.vapi
blob: 50d124aec6e496be48343b2d026401aa7d57a3d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
/* sqlite3.vala
 *
 * Copyright (C) 2007 Jürg Billeter
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.

 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.

 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
 *
 * Author:
 * 	Jürg Billeter <j@bitron.ch>
 */

[CCode (lower_case_cprefix = "sqlite3_", cheader_filename = "sqlite3.h")]
namespace Sqlite {
	/* Database Connection Handle */
	[Compact]
	[CCode (free_function = "sqlite3_close", cname = "sqlite3", cprefix = "sqlite3_")]
	public class Database {
		public int busy_timeout (int ms);
		public int changes ();
		[CCode (cname = "sqlite3_exec")]
		public int _exec (string sql, Callback? callback = null, [CCode (type = "char**")] out unowned string? errmsg = null);
		[CCode (cname = "_sqlite3_exec")]
		public int exec (string sql, Callback? callback = null, out string? errmsg = null) {
			unowned string? sqlite_errmsg;
			var ec = this._exec (sql, callback, out sqlite_errmsg);
			if (&errmsg != null) {
				errmsg = sqlite_errmsg;
			} else {
				errmsg = null;
			}
			Sqlite.Memory.free ((void*) sqlite_errmsg);
			return ec;
		}
		public int extended_result_codes (int onoff);
		public int get_autocommit ();
		public void interrupt ();
		public int64 last_insert_rowid ();
		public int limit (Sqlite.Limit id, int new_val);
		public int total_changes ();
		public static int complete (string sql);
		[CCode (cname = "sqlite3_get_table")]
		public int _get_table (string sql, [CCode (array_length = false)] out unowned string[] resultp, out int nrow, out int ncolumn, [CCode (type = "char**")] out unowned string? errmsg = null);
		private static void free_table ([CCode (array_length = false)] string[] result);
		[CCode (cname = "_sqlite3_get_table")]
		public int get_table (string sql, out string[] resultp, out int nrow, out int ncolumn, out string? errmsg = null) {
			unowned string? sqlite_errmsg;
			unowned string[] sqlite_resultp;

			var ec = this._get_table (sql, out sqlite_resultp, out nrow, out ncolumn, out sqlite_errmsg);

			resultp = new string[(nrow + 1) * ncolumn];
			for (var entry = 0 ; entry < resultp.length ; entry++ ) {
				resultp[entry] = sqlite_resultp[entry];
			}
			Sqlite.Database.free_table (sqlite_resultp);

			if (&errmsg != null) {
				errmsg = sqlite_errmsg;
			} else {
				errmsg = null;
			}
			Sqlite.Memory.free ((void*) sqlite_errmsg);
			return ec;
		}
		public static int open (string filename, out Database db);
		public static int open_v2 (string filename, out Database db, int flags = OPEN_READWRITE | OPEN_CREATE, string? zVfs = null);
		public int errcode ();
		public unowned string errmsg ();
		public unowned Sqlite.Statement next_stmt (Sqlite.Statement? current);
		public int prepare (string sql, int n_bytes, out Statement stmt, out unowned string tail = null);
		public int prepare_v2 (string sql, int n_bytes, out Statement stmt, out unowned string tail = null);
		public int set_authorizer (AuthorizeCallback? auth);
		[CCode (cname = "sqlite3_db_status")]
		public int status (Sqlite.DatabaseStatus op, out int pCurrent, out int pHighwater, int resetFlag = 0);
		public int table_column_metadata (string db_name, string table_name, string column_name, out string? data_type, out string? collation_sequence, out int? not_null, out int? primary_key, out int? auto_increment);
		public void trace (TraceCallback? xtrace);
		public void profile (ProfileCallback? xprofile);
		public void progress_handler (int n_opcodes, Sqlite.ProgressCallback? progress_handler);
		public void commit_hook (CommitCallback? commit_hook);
		public void rollback_hook (RollbackCallback? rollback_hook);
		public void update_hook (UpdateCallback? update_hook);
		public int create_function (string zFunctionName, int nArg, int eTextRep, void * user_data, UserFuncCallback? xFunc, UserFuncCallback? xStep, UserFuncFinishCallback? xFinal);
		public int create_function_v2 (string zFunctionName, int nArg, int eTextRep, void * user_data, UserFuncCallback? xFunc, UserFuncCallback? xStep, UserFuncFinishCallback? xFinal, GLib.DestroyNotify? destroy = null);
		public int create_collation (string zName, int eTextRep, [CCode (delegate_target_pos = 2.9, type = "int (*)(void *, int,  const void *, int,  const void *)")] CompareCallback xCompare);

		public int wal_autocheckpoint (int N);
		public int wal_checkpoint (string zDb);
		public void* wal_hook (WALHookCallback cb);
	}

	[CCode (has_typedef = false, instance_pos = 0.9)]
	public delegate int AuthorizeCallback (Sqlite.Action action, string? p1, string? p2, string db_name, string? responsible);
	[CCode (has_typedef = false, instance_pos = 0.9)]
	public delegate void TraceCallback (string message);
	[CCode (has_typedef = false, instance_pos = 0.9)]
	public delegate void ProfileCallback (string sql, uint64 time);
	[CCode (has_typedef = false)]
	public delegate int ProgressCallback ();
	[CCode (has_typedef = false)]
	public delegate int CommitCallback ();
	[CCode (has_typedef = false)]
	public delegate void RollbackCallback ();
	[CCode (has_typedef = false, has_target = false)]
	public delegate void UserFuncCallback (Sqlite.Context context, [CCode (array_length_pos = 1.1)] Sqlite.Value[] values);
	[CCode (has_typedef = false, has_target = false)]
	public delegate void UserFuncFinishCallback (Sqlite.Context context);
	[CCode (has_typedef = false, instance_pos = 0.9)]
	public delegate void UpdateCallback (Sqlite.Action action, string dbname, string table, int64 rowid);
	[CCode (has_typedef = false, instance_pos = 0.9)]
	public delegate int CompareCallback (int alen, void* a, int blen, void* b);
	[CCode (has_typedef = false, instance_pos = 0.9)]
	public delegate int WALHookCallback (Sqlite.Database db, string dbname, int pages);

	public unowned string? compileoption_get (int n);
	public int compileoption_used (string option_name);
	public static int complete (string sql);
	[CCode (sentinel = "")]
	public static int config (Sqlite.Config op, ...);
	public unowned string libversion ();
	public int libversion_number ();
	[PrintfFormat]
	public void log (int error_code, string format, ...);
	public unowned string sourceid ();
	public static int status (Sqlite.Status op, out int pCurrent, out int pHighwater, int resetFlag = 0);
	public static int threadsafe ();

	[CCode (cname = "SQLITE_VERSION")]
	public const string VERSION;
	[CCode (cname = "SQLITE_VERSION_NUMBER")]
	public const int VERSION_NUMBER;
	[CCode (cname = "SQLITE_SOURCE_ID")]
	public const string SOURCE_ID;

	/* Dynamically Typed Value Object */
	[Compact]
	[CCode (cname = "sqlite3_value")]
	public class Value {
		[CCode (cname = "sqlite3_value_blob")]
		public void* to_blob ();
		[CCode (cname = "sqlite3_value_bytes")]
		public int to_bytes ();
		[CCode (cname = "sqlite3_value_double")]
		public double to_double ();
		[CCode (cname = "sqlite3_value_int")]
		public int to_int ();
		[CCode (cname = "sqlite3_value_int64")]
		public int64 to_int64 ();
		[CCode (cname = "sqlite3_value_text", type = "const unsigned char*")]
		public unowned string to_text ();
		[CCode (cname = "sqlite3_value_type")]
		public int to_type ();
		[CCode (cname = "sqlite3_value_numeric_type")]
		public int to_numeric_type ();
	}

	[CCode (cname = "sqlite3_callback", instance_pos = 0)]
	public delegate int Callback (int n_columns, [CCode (array_length = false)] string[] values, [CCode (array_length = false)] string[] column_names);

	[CCode (cname = "SQLITE_OK")]
	public const int OK;
	[CCode (cname = "SQLITE_ERROR")]
	public const int ERROR;
	[CCode (cname = "SQLITE_INTERNAL")]
	public const int INTERNAL;
	[CCode (cname = "SQLITE_PERM")]
	public const int PERM;
	[CCode (cname = "SQLITE_ABORT")]
	public const int ABORT;
	[CCode (cname = "SQLITE_BUSY")]
	public const int BUSY;
	[CCode (cname = "SQLITE_LOCKED")]
	public const int LOCKED;
	[CCode (cname = "SQLITE_NOMEM")]
	public const int NOMEM;
	[CCode (cname = "SQLITE_READONLY")]
	public const int READONLY;
	[CCode (cname = "SQLITE_INTERRUPT")]
	public const int INTERRUPT;
	[CCode (cname = "SQLITE_IOERR")]
	public const int IOERR;
	[CCode (cname = "SQLITE_CORRUPT")]
	public const int CORRUPT;
	[CCode (cname = "SQLITE_NOTFOUND")]
	public const int NOTFOUND;
	[CCode (cname = "SQLITE_FULL")]
	public const int FULL;
	[CCode (cname = "SQLITE_CANTOPEN")]
	public const int CANTOPEN;
	[CCode (cname = "SQLITE_PROTOCOL")]
	public const int PROTOCOL;
	[CCode (cname = "SQLITE_EMPTY")]
	public const int EMPTY;
	[CCode (cname = "SQLITE_SCHEMA")]
	public const int SCHEMA;
	[CCode (cname = "SQLITE_TOOBIG")]
	public const int TOOBIG;
	[CCode (cname = "SQLITE_CONSTRAINT")]
	public const int CONSTRAINT;
	[CCode (cname = "SQLITE_MISMATCH")]
	public const int MISMATCH;
	[CCode (cname = "SQLITE_MISUSE")]
	public const int MISUSE;
	[CCode (cname = "SQLITE_NOLFS")]
	public const int NOLFS;
	[CCode (cname = "SQLITE_AUTH")]
	public const int AUTH;
	[CCode (cname = "SQLITE_FORMAT")]
	public const int FORMAT;
	[CCode (cname = "SQLITE_RANGE")]
	public const int RANGE;
	[CCode (cname = "SQLITE_NOTADB")]
	public const int NOTADB;
	[CCode (cname = "SQLITE_ROW")]
	public const int ROW;
	[CCode (cname = "SQLITE_DONE")]
	public const int DONE;
	[CCode (cname = "SQLITE_OPEN_READONLY")]
	public const int OPEN_READONLY;
	[CCode (cname = "SQLITE_OPEN_READWRITE")]
	public const int OPEN_READWRITE;
	[CCode (cname = "SQLITE_OPEN_CREATE")]
	public const int OPEN_CREATE;
	[CCode (cname = "SQLITE_OPEN_URI")]
	public const int OPEN_URI;
	[CCode (cname = "SQLITE_OPEN_MEMORY")]
	public const int OPEN_MEMORY;
	[CCode (cname = "SQLITE_OPEN_NOMUTEX")]
	public const int OPEN_NOMUTEX;
	[CCode (cname = "SQLITE_OPEN_FULLMUTEX")]
	public const int OPEN_FULLMUTEX;
	[CCode (cname = "SQLITE_OPEN_SHAREDCACHE")]
	public const int OPEN_SHAREDCACHE;
	[CCode (cname = "SQLITE_OPEN_PRIVATECACHE")]
	public const int OPEN_PRIVATECACHE;
	[CCode (cname = "SQLITE_INTEGER")]
	public const int INTEGER;
	[CCode (cname = "SQLITE_FLOAT")]
	public const int FLOAT;
	[CCode (cname = "SQLITE_BLOB")]
	public const int BLOB;
	[CCode (cname = "SQLITE_NULL")]
	public const int NULL;
	[CCode (cname = "SQLITE3_TEXT")]
	public const int TEXT;
	[CCode (cname = "SQLITE_MUTEX_FAST")]
	public const int MUTEX_FAST;
	[CCode (cname = "SQLITE_MUTEX_RECURSIVE")]
	public const int MUTEX_RECURSIVE;
	[CCode (cname = "SQLITE_UTF8")]
	public const int UTF8;
	[CCode (cname = "SQLITE_UTF16LE")]
	public const int UTF16LE;
	[CCode (cname = "SQLITE_UTF16BE")]
	public const int UTF16BE;
	[CCode (cname = "SQLITE_UTF16")]
	public const int UTF16;
	[CCode (cname = "SQLITE_ANY")]
	public const int ANY;
	[CCode (cname = "SQLITE_UTF16_ALIGNED")]
	public const int UTF16_ALIGNED;

	[CCode (cname = "int", cprefix = "SQLITE_", has_type_id = false)]
	public enum Action {
		CREATE_INDEX,
		CREATE_TABLE,
		CREATE_TEMP_INDEX,
		CREATE_TEMP_TABLE,
		CREATE_TEMP_TRIGGER,
		CREATE_TEMP_VIEW,
		CREATE_TRIGGER,
		CREATE_VIEW,
		DELETE,
		DROP_INDEX,
		DROP_TABLE,
		DROP_TEMP_INDEX,
		DROP_TEMP_TABLE,
		DROP_TEMP_TRIGGER,
		DROP_TEMP_VIEW,
		DROP_TRIGGER,
		DROP_VIEW,
		INSERT,
		PRAGMA,
		READ,
		SELECT,
		TRANSACTION,
		UPDATE,
		ATTACH,
		DETACH,
		ALTER_TABLE,
		REINDEX,
		ANALYZE,
		CREATE_VTABLE,
		DROP_VTABLE,
		FUNCTION,
		SAVEPOINT,
		COPY
	}

	[CCode (cname = "int", cprefix = "SQLITE_CONFIG_", has_type_id = false)]
	public enum Config {
		SINGLETHREAD,
		MULTITHREAD,
		SERIALIZED,
		MALLOC,
		GETMALLOC,
		SCRATCH,
		PAGECACHE,
		HEAP,
		MEMSTATUS,
		MUTEX,
		GETMUTEX,
		LOOKASIDE,
		PCACHE,
		GETPCACHE,
		LOG,
	}

	[CCode (cname = "int", cprefix = "SQLITE_DBSTATUS_", has_type_id = false)]
	public enum DatabaseStatus {
		LOOKASIDE_USED
	}

	[CCode (cname = "int", cprefix = "SQLITE_LIMIT_", has_type_id = false)]
	public enum Limit {
		LENGTH,
		SQL_LENGTH,
		COLUMN,
		EXPR_DEPTH,
		COMPOUND_SELECT,
		VDBE_OP,
		FUNCTION_ARG,
		ATTACHED,
		LIKE_PATTERN_LENGTH,
		VARIABLE_NUMBER,
		TRIGGER_DEPTH
	}

	[CCode (cname = "int", cprefix = "SQLITE_STMTSTATUS_", has_type_id = false)]
	public enum StatementStatus {
		FULLSCAN_STEP,
		SORT
	}

	[CCode (cname = "int", cprefix = "SQLITE_STATUS_", has_type_id = false)]
	public enum Status {
		MEMORY_USED,
		PAGECACHE_USED,
		PAGECACHE_OVERFLOW,
		SCRATCH_USED,
		SCRATCH_OVERFLOW,
		MALLOC_SIZE,
		PARSER_STACK,
		PAGECACHE_SIZE,
		SCRATCH_SIZE
	}

	/* SQL Statement Object */
	[Compact]
	[CCode (free_function = "sqlite3_finalize", cname = "sqlite3_stmt", cprefix = "sqlite3_")]
	public class Statement {
		public int bind_parameter_count ();
		public int bind_parameter_index (string name);
		public unowned string bind_parameter_name (int index);
		public int clear_bindings ();
		public int column_count ();
		public int data_count ();
		public unowned Database db_handle ();
		public int reset ();
		[CCode (cname = "sqlite3_stmt_status")]
		public int status (Sqlite.StatementStatus op, int resetFlg = 0);
		public int step ();
		public int bind_blob (int index, void* value, int n, GLib.DestroyNotify? destroy_notify = null);
		public int bind_double (int index, double value);
		public int bind_int (int index, int value);
		public int bind_int64 (int index, int64 value);
		public int bind_null (int index);
		[CCode (cname = "sqlite3_bind_text")]
		public int _bind_text (int index, string value, int n = -1, GLib.DestroyNotify? destroy_notify = null);
		public int bind_text (int index, owned string value, int n = -1, GLib.DestroyNotify destroy_notify = GLib.g_free);
		public int bind_value (int index, Value value);
		public int bind_zeroblob (int index, int n);
		public void* column_blob (int col);
		public int column_bytes (int col);
		public double column_double (int col);
		public int column_int (int col);
		public int64 column_int64 (int col);
		[CCode (type = "const unsigned char*")]
		public unowned string? column_text (int col);
		public int column_type (int col);
		public unowned Value column_value (int col);
		public unowned string column_name (int index);
		public unowned string column_database_name (int col);
		public unowned string column_table_name (int col);
		public unowned string column_origin_name (int col);
		public unowned string sql ();
		[CCode (cname = "vala_sqlite3_expanded_sql")]
		public string? expanded_sql () {
			string* sqlite = this._expanded_sql ();
			string? sql = sqlite;
			Sqlite.Memory.free ((void*) sqlite);
			return sql;
		}
		[CCode (cname = "sqlite3_expanded_sql")]
		private string? _expanded_sql ();
		public unowned string normalized_sql ();
	}

	namespace Memory {
		[CCode (cname = "sqlite3_malloc")]
		public static void* malloc (int n_bytes);
		[CCode (cname = "sqlite3_realloc")]
		public static void* realloc (void* mem, int n_bytes);
		[CCode (cname = "sqlite3_free")]
		public static void free (void* mem);
		[CCode (cname = "sqlite3_release_memory")]
		public static int release (int bytes);
		[CCode (cname = "sqlite3_memory_used")]
		public static int64 used ();
		[CCode (cname = "sqlite3_memory_highwater")]
		public static int64 highwater (int reset = 0);
		[Version (deprecated_since = "3.7.2", replacement = "Sqlite.Memory.soft_heap_limit64")]
		[CCode (cname = "sqlite3_soft_heap_limit")]
		public static void soft_heap_limit (int limit);
		[CCode (cname = "sqlite3_soft_heap_limit64")]
		public static int64 soft_heap_limit64 (int64 limit = -1);
	}

	[Compact]
	[CCode (cname = "sqlite3_mutex", free_function = "sqlite3_mutex_free")]
	public class Mutex {
		[CCode (cname = "sqlite3_mutex_alloc")]
		public Mutex (int mutex_type = MUTEX_RECURSIVE);
		public void enter ();
		public int held ();
		public int notheld ();
		public int @try ();
		public void leave ();
	}

	[Compact, CCode (cname = "sqlite3_context", cprefix = "sqlite3_")]
	public class Context {
		public void result_blob (owned uint8[] data, GLib.DestroyNotify? destroy_notify = GLib.g_free);
		public void result_double (double value);
		public void result_error (string value, int error_code);
		public void result_error_toobig ();
		public void result_error_nomem ();
		public void result_error_code (int error_code);
		public void result_int (int value);
		public void result_int64 (int64 value);
		public void result_null ();
		public void result_text (owned string value, int length = -1, GLib.DestroyNotify? destroy_notify = GLib.g_free);
		public void result_value (Sqlite.Value value);
		public void result_zeroblob (int n);

		[CCode (simple_generics = true)]
		public unowned T user_data<T> ();
		[CCode (simple_generics = true)]
		public void set_auxdata<T> (int N, owned T data);
		[CCode (simple_generics = true)]
		public unowned T get_auxdata<T> (int N);
		[CCode (cname = "sqlite3_context_db_handle")]
		public unowned Database db_handle ();
		[CCode (cname = "sqlite3_aggregate_context")]
		public void * aggregate (int n_bytes);
	}

	[Compact, CCode (cname = "sqlite3_backup", free_function = "sqlite3_backup_finish", cprefix = "sqlite3_backup_")]
	public class Backup {
		[CCode (cname = "sqlite3_backup_init")]
		public Backup (Database dest, string dest_name, Database source, string source_name);
		public int step (int nPage);
		public int remaining ();
		public int pagecount ();
	}
}