The Birdfont Source Code


All Repositories / birdfont.git / blob – RSS feed

sqlite3.vapi

This file is a part of the Birdfont project.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git
Circle boundaries heads/master
1 /* sqlite3.vala 2 * 3 * Copyright (C) 2007 Jürg Billeter 4 * 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. 9 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. 14 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 18 * 19 * Author: 20 * Jürg Billeter <j@bitron.ch> 21 */ 22 23 [CCode (lower_case_cprefix = "sqlite3_", cheader_filename = "sqlite3.h")] 24 namespace Sqlite { 25 /* Database Connection Handle */ 26 [Compact] 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 [CCode (cname = "sqlite3_exec")] 32 public int _exec (string sql, Callback? callback = null, [CCode (type = "char**")] out unowned string errmsg = null); 33 [CCode (cname = "_sqlite3_exec")] 34 public int exec (string sql, Callback? callback = null, out string errmsg = null) { 35 unowned string sqlite_errmsg; 36 var ec = this._exec (sql, callback, out sqlite_errmsg); 37 if (&errmsg != null) { 38 errmsg = sqlite_errmsg; 39 } 40 Sqlite.Memory.free ((void*) sqlite_errmsg); 41 return ec; 42 } 43 public int extended_result_codes (int onoff); 44 public int get_autocommit (); 45 public void interrupt (); 46 public int64 last_insert_rowid (); 47 public int limit (Sqlite.Limit id, int new_val); 48 public int total_changes (); 49 public int complete (string sql); 50 [CCode (cname = "sqlite3_get_table")] 51 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); 52 private static void free_table ([CCode (array_length = false)] string[] result); 53 [CCode (cname = "_sqlite3_get_table")] 54 public int get_table (string sql, out string[] resultp, out int nrow, out int ncolumn, out string? errmsg = null) { 55 unowned string? sqlite_errmsg; 56 unowned string[] sqlite_resultp; 57 58 var ec = this._get_table (sql, out sqlite_resultp, out nrow, out ncolumn, out sqlite_errmsg); 59 60 resultp = new string[(nrow + 1) * ncolumn]; 61 for (var entry = 0 ; entry < resultp.length ; entry++ ) { 62 resultp[entry] = sqlite_resultp[entry]; 63 } 64 Sqlite.Database.free_table (sqlite_resultp); 65 66 if (&errmsg != null) { 67 errmsg = sqlite_errmsg; 68 } 69 Sqlite.Memory.free ((void*) sqlite_errmsg); 70 return ec; 71 } 72 public static int open (string filename, out Database db); 73 public static int open_v2 (string filename, out Database db, int flags = OPEN_READWRITE | OPEN_CREATE, string? zVfs = null); 74 public int errcode (); 75 public unowned string errmsg (); 76 public unowned Sqlite.Statement next_stmt (Sqlite.Statement? current); 77 public int prepare (string sql, int n_bytes, out Statement stmt, out unowned string tail = null); 78 public int prepare_v2 (string sql, int n_bytes, out Statement stmt, out unowned string tail = null); 79 public int set_authorizer (AuthorizeCallback? auth); 80 [CCode (cname = "sqlite3_db_status")] 81 public int status (Sqlite.DatabaseStatus op, out int pCurrent, out int pHighwater, int resetFlag = 0); 82 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); 83 public void trace (TraceCallback? xtrace); 84 public void profile (ProfileCallback? xprofile); 85 public void progress_handler (int n_opcodes, Sqlite.ProgressCallback? progress_handler); 86 public void commit_hook (CommitCallback? commit_hook); 87 public void rollback_hook (RollbackCallback? rollback_hook); 88 public void update_hook (UpdateCallback? update_hook); 89 public int create_function (string zFunctionName, int nArg, int eTextRep, void * user_data, UserFuncCallback? xFunc, UserFuncCallback? xStep, UserFuncFinishCallback? xFinal); 90 public int create_function_v2 (string zFunctionName, int nArg, int eTextRep, void * user_data, UserFuncCallback? xFunc, UserFuncCallback? xStep, UserFuncFinishCallback? xFinal, GLib.DestroyNotify? destroy = null); 91 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); 92 93 public int wal_autocheckpoint (int N); 94 public int wal_checkpoint (string zDb); 95 public void* wal_hook (WALHookCallback cb, string db_name, int page_count); 96 } 97 98 [CCode (instance_pos = 0)] 99 public delegate int AuthorizeCallback (Sqlite.Action action, string? p1, string? p2, string db_name, string? responsible); 100 [CCode (instance_pos = 0)] 101 public delegate void TraceCallback (string message); 102 [CCode (instance_pos = 0)] 103 public delegate void ProfileCallback (string sql, uint64 time); 104 public delegate int ProgressCallback (); 105 public delegate int CommitCallback (); 106 public delegate void RollbackCallback (); 107 [CCode (has_target = false)] 108 public delegate void UserFuncCallback (Sqlite.Context context, [CCode (array_length_pos = 1.1)] Sqlite.Value[] values); 109 [CCode (has_target = false)] 110 public delegate void UserFuncFinishCallback (Sqlite.Context context); 111 [CCode (instance_pos = 0)] 112 public delegate void UpdateCallback (Sqlite.Action action, string dbname, string table, int64 rowid); 113 [CCode (instance_pos = 0)] 114 public delegate int CompareCallback (int alen, void* a, int blen, void* b); 115 [CCode (instance_pos = 0)] 116 public delegate int WALHookCallback (Sqlite.Database db, string dbname, int pages); 117 118 public unowned string? compileoption_get (int n); 119 public int compileoption_used (string option_name); 120 public static int complete (string sql); 121 [CCode (sentinel = "")] 122 public static int config (Sqlite.Config op, ...); 123 public unowned string libversion (); 124 public int libversion_number (); 125 [PrintfFormat] 126 public void log (int error_code, string format, ...); 127 public unowned string sourceid (); 128 public static int status (Sqlite.Status op, out int pCurrent, out int pHighwater, int resetFlag = 0); 129 public static int threadsafe (); 130 131 [CCode (cname = "SQLITE_VERSION")] 132 public const string VERSION; 133 [CCode (cname = "SQLITE_VERSION_NUMBER")] 134 public const int VERSION_NUMBER; 135 [CCode (cname = "SQLITE_SOURCE_ID")] 136 public const string SOURCE_ID; 137 138 /* Dynamically Typed Value Object */ 139 [Compact] 140 [CCode (cname = "sqlite3_value")] 141 public class Value { 142 [CCode (cname = "sqlite3_value_blob")] 143 public void* to_blob (); 144 [CCode (cname = "sqlite3_value_bytes")] 145 public int to_bytes (); 146 [CCode (cname = "sqlite3_value_double")] 147 public double to_double (); 148 [CCode (cname = "sqlite3_value_int")] 149 public int to_int (); 150 [CCode (cname = "sqlite3_value_int64")] 151 public int64 to_int64 (); 152 [CCode (cname = "sqlite3_value_text")] 153 public unowned string to_text (); 154 [CCode (cname = "sqlite3_value_type")] 155 public int to_type (); 156 [CCode (cname = "sqlite3_value_numeric_type")] 157 public int to_numeric_type (); 158 } 159 160 [CCode (cname = "sqlite3_callback", instance_pos = 0)] 161 public delegate int Callback (int n_columns, [CCode (array_length = false)] string[] values, [CCode (array_length = false)] string[] column_names); 162 163 [CCode (cname = "SQLITE_OK")] 164 public const int OK; 165 [CCode (cname = "SQLITE_ERROR")] 166 public const int ERROR; 167 [CCode (cname = "SQLITE_INTERNAL")] 168 public const int INTERNAL; 169 [CCode (cname = "SQLITE_PERM")] 170 public const int PERM; 171 [CCode (cname = "SQLITE_ABORT")] 172 public const int ABORT; 173 [CCode (cname = "SQLITE_BUSY")] 174 public const int BUSY; 175 [CCode (cname = "SQLITE_LOCKED")] 176 public const int LOCKED; 177 [CCode (cname = "SQLITE_NOMEM")] 178 public const int NOMEM; 179 [CCode (cname = "SQLITE_READONLY")] 180 public const int READONLY; 181 [CCode (cname = "SQLITE_INTERRUPT")] 182 public const int INTERRUPT; 183 [CCode (cname = "SQLITE_IOERR")] 184 public const int IOERR; 185 [CCode (cname = "SQLITE_CORRUPT")] 186 public const int CORRUPT; 187 [CCode (cname = "SQLITE_NOTFOUND")] 188 public const int NOTFOUND; 189 [CCode (cname = "SQLITE_FULL")] 190 public const int FULL; 191 [CCode (cname = "SQLITE_CANTOPEN")] 192 public const int CANTOPEN; 193 [CCode (cname = "SQLITE_PROTOCOL")] 194 public const int PROTOCOL; 195 [CCode (cname = "SQLITE_EMPTY")] 196 public const int EMPTY; 197 [CCode (cname = "SQLITE_SCHEMA")] 198 public const int SCHEMA; 199 [CCode (cname = "SQLITE_TOOBIG")] 200 public const int TOOBIG; 201 [CCode (cname = "SQLITE_CONSTRAINT")] 202 public const int CONSTRAINT; 203 [CCode (cname = "SQLITE_MISMATCH")] 204 public const int MISMATCH; 205 [CCode (cname = "SQLITE_MISUSE")] 206 public const int MISUSE; 207 [CCode (cname = "SQLITE_NOLFS")] 208 public const int NOLFS; 209 [CCode (cname = "SQLITE_AUTH")] 210 public const int AUTH; 211 [CCode (cname = "SQLITE_FORMAT")] 212 public const int FORMAT; 213 [CCode (cname = "SQLITE_RANGE")] 214 public const int RANGE; 215 [CCode (cname = "SQLITE_NOTADB")] 216 public const int NOTADB; 217 [CCode (cname = "SQLITE_ROW")] 218 public const int ROW; 219 [CCode (cname = "SQLITE_DONE")] 220 public const int DONE; 221 [CCode (cname = "SQLITE_OPEN_READONLY")] 222 public const int OPEN_READONLY; 223 [CCode (cname = "SQLITE_OPEN_READWRITE")] 224 public const int OPEN_READWRITE; 225 [CCode (cname = "SQLITE_OPEN_CREATE")] 226 public const int OPEN_CREATE; 227 [CCode (cname = "SQLITE_INTEGER")] 228 public const int INTEGER; 229 [CCode (cname = "SQLITE_FLOAT")] 230 public const int FLOAT; 231 [CCode (cname = "SQLITE_BLOB")] 232 public const int BLOB; 233 [CCode (cname = "SQLITE_NULL")] 234 public const int NULL; 235 [CCode (cname = "SQLITE3_TEXT")] 236 public const int TEXT; 237 [CCode (cname = "SQLITE_MUTEX_FAST")] 238 public const int MUTEX_FAST; 239 [CCode (cname = "SQLITE_MUTEX_RECURSIVE")] 240 public const int MUTEX_RECURSIVE; 241 [CCode (cname = "SQLITE_UTF8")] 242 public const int UTF8; 243 [CCode (cname = "SQLITE_UTF16LE")] 244 public const int UTF16LE; 245 [CCode (cname = "SQLITE_UTF16BE")] 246 public const int UTF16BE; 247 [CCode (cname = "SQLITE_UTF16")] 248 public const int UTF16; 249 [CCode (cname = "SQLITE_ANY")] 250 public const int ANY; 251 [CCode (cname = "SQLITE_UTF16_ALIGNED")] 252 public const int UTF16_ALIGNED; 253 254 [CCode (cname = "int", cprefix = "SQLITE_", has_type_id = false)] 255 public enum Action { 256 CREATE_INDEX, 257 CREATE_TABLE, 258 CREATE_TEMP_INDEX, 259 CREATE_TEMP_TABLE, 260 CREATE_TEMP_TRIGGER, 261 CREATE_TEMP_VIEW, 262 CREATE_TRIGGER, 263 CREATE_VIEW, 264 DELETE, 265 DROP_INDEX, 266 DROP_TABLE, 267 DROP_TEMP_INDEX, 268 DROP_TEMP_TABLE, 269 DROP_TEMP_TRIGGER, 270 DROP_TEMP_VIEW, 271 DROP_TRIGGER, 272 DROP_VIEW, 273 INSERT, 274 PRAGMA, 275 READ, 276 SELECT, 277 TRANSACTION, 278 UPDATE, 279 ATTACH, 280 DETACH, 281 ALTER_TABLE, 282 REINDEX, 283 ANALYZE, 284 CREATE_VTABLE, 285 DROP_VTABLE, 286 FUNCTION, 287 SAVEPOINT, 288 COPY 289 } 290 291 [CCode (cname = "int", cprefix = "SQLITE_CONFIG_", has_type_id = false)] 292 public enum Config { 293 SINGLETHREAD, 294 MULTITHREAD, 295 SERIALIZED, 296 MALLOC, 297 GETMALLOC, 298 SCRATCH, 299 PAGECACHE, 300 HEAP, 301 MEMSTATUS, 302 MUTEX, 303 GETMUTEX, 304 LOOKASIDE, 305 PCACHE, 306 GETPCACHE, 307 LOG, 308 } 309 310 [CCode (cname = "int", cprefix = "SQLITE_DBSTATUS_", has_type_id = false)] 311 public enum DatabaseStatus { 312 LOOKASIDE_USED 313 } 314 315 [CCode (cname = "int", cprefix = "SQLITE_LIMIT_", has_type_id = false)] 316 public enum Limit { 317 LENGTH, 318 SQL_LENGTH, 319 COLUMN, 320 EXPR_DEPTH, 321 COMPOUND_SELECT, 322 VDBE_OP, 323 FUNCTION_ARG, 324 ATTACHED, 325 LIKE_PATTERN_LENGTH, 326 VARIABLE_NUMBER, 327 TRIGGER_DEPTH 328 } 329 330 [CCode (cname = "int", cprefix = "SQLITE_STMTSTATUS_", has_type_id = false)] 331 public enum StatementStatus { 332 FULLSCAN_STEP, 333 SORT 334 } 335 336 [CCode (cname = "int", cprefix = "SQLITE_STATUS_", has_type_id = false)] 337 public enum Status { 338 MEMORY_USED, 339 PAGECACHE_USED, 340 PAGECACHE_OVERFLOW, 341 SCRATCH_USED, 342 SCRATCH_OVERFLOW, 343 MALLOC_SIZE, 344 PARSER_STACK, 345 PAGECACHE_SIZE, 346 SCRATCH_SIZE 347 } 348 349 /* SQL Statement Object */ 350 [Compact] 351 [CCode (free_function = "sqlite3_finalize", cname = "sqlite3_stmt", cprefix = "sqlite3_")] 352 public class Statement { 353 public int bind_parameter_count (); 354 public int bind_parameter_index (string name); 355 public unowned string bind_parameter_name (int index); 356 public int clear_bindings (); 357 public int column_count (); 358 public int data_count (); 359 public unowned Database db_handle (); 360 public int reset (); 361 [CCode (cname = "sqlite3_stmt_status")] 362 public int status (Sqlite.StatementStatus op, int resetFlg = 0); 363 public int step (); 364 public int bind_blob (int index, void* value, int n, GLib.DestroyNotify? destroy_notify = null); 365 public int bind_double (int index, double value); 366 public int bind_int (int index, int value); 367 public int bind_int64 (int index, int64 value); 368 public int bind_null (int index); 369 [CCode (cname = "sqlite3_bind_text")] 370 public int _bind_text (int index, string value, int n = -1, GLib.DestroyNotify? destroy_notify = null); 371 public int bind_text (int index, owned string value, int n = -1, GLib.DestroyNotify destroy_notify = GLib.g_free); 372 public int bind_value (int index, Value value); 373 public int bind_zeroblob (int index, int n); 374 public void* column_blob (int col); 375 public int column_bytes (int col); 376 public double column_double (int col); 377 public int column_int (int col); 378 public int64 column_int64 (int col); 379 public unowned string column_text (int col); 380 public int column_type (int col); 381 public unowned Value column_value (int col); 382 public unowned string column_name (int index); 383 public unowned string column_database_name (int col); 384 public unowned string column_table_name (int col); 385 public unowned string column_origin_name (int col); 386 public unowned string sql (); 387 } 388 389 namespace Memory { 390 [CCode (cname = "sqlite3_malloc")] 391 public static void* malloc (int n_bytes); 392 [CCode (cname = "sqlite3_realloc")] 393 public static void* realloc (void* mem, int n_bytes); 394 [CCode (cname = "sqlite3_free")] 395 public static void free (void* mem); 396 [CCode (cname = "sqlite3_release_memory")] 397 public static int release (int bytes); 398 [CCode (cname = "sqlite3_memory_used")] 399 public static int64 used (); 400 [CCode (cname = "sqlite3_memory_highwater")] 401 public static int64 highwater (int reset = 0); 402 [Deprecated (since = "3.7.2", replacement = "Sqlite.Memory.soft_heap_limit64")] 403 [CCode (cname = "sqlite3_soft_heap_limit")] 404 public static void soft_heap_limit (int limit); 405 [CCode (cname = "sqlite3_soft_heap_limit64")] 406 public static int64 soft_heap_limit64 (int64 limit = -1); 407 } 408 409 [Compact] 410 [CCode (cname = "sqlite3_mutex")] 411 public class Mutex { 412 [CCode (cname = "sqlite3_mutex_alloc")] 413 public Mutex (int mutex_type = MUTEX_RECURSIVE); 414 public void enter (); 415 public int held (); 416 public int notheld (); 417 public int @try (); 418 public void leave (); 419 } 420 421 [Compact, CCode (cname = "sqlite3_context", cprefix = "sqlite3_")] 422 public class Context { 423 public void result_blob (owned uint8[] data, GLib.DestroyNotify? destroy_notify = GLib.g_free); 424 public void result_double (double value); 425 public void result_error (string value, int error_code); 426 public void result_error_toobig (); 427 public void result_error_nomem (); 428 public void result_error_code (int error_code); 429 public void result_int (int value); 430 public void result_int64 (int64 value); 431 public void result_null (); 432 public void result_text (owned string value, int length = -1, GLib.DestroyNotify? destroy_notify = GLib.g_free); 433 public void result_value (Sqlite.Value value); 434 public void result_zeroblob (int n); 435 436 [CCode (simple_generics = true)] 437 public unowned T user_data<T> (); 438 [CCode (simple_generics = true)] 439 public void set_auxdata<T> (int N, owned T data); 440 [CCode (simple_generics = true)] 441 public unowned T get_auxdata<T> (int N); 442 [CCode (cname = "sqlite3_context_db_handle")] 443 public unowned Database db_handle (); 444 [CCode (cname = "sqlite3_aggregate_context")] 445 public void * aggregate (int n_bytes); 446 } 447 448 [Compact, CCode (cname = "sqlite3_backup", free_function = "sqlite3_backup_finish", cprefix = "sqlite3_backup_")] 449 public class Backup { 450 [CCode (cname = "sqlite3_backup_init")] 451 public Backup (Database dest, string dest_name, Database source, string source_name); 452 public int step (int nPage); 453 public int remaining (); 454 public int pagecount (); 455 } 456 } 457 458