c9d3e266cd2fa71d5e82d135ea79b2366f7604df
[cinaest] / vapi / sqlite3.vapi
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                 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 ();
37
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 progress_handler (int n_opcodes, Sqlite.ProgressCallback? progress_handler);
50                 public void commit_hook (CommitCallback? commit_hook);
51                 public void rollback_hook (RollbackCallback? rollback_hook);
52         }
53
54         [CCode (instance_pos = 0)]
55         public delegate void TraceCallback (string message);
56         [CCode (instance_pos = 0)]
57         public delegate void ProfileCallback (string sql, uint64 time);
58         public delegate int ProgressCallback ();
59         public delegate int CommitCallback ();
60         public delegate void RollbackCallback ();
61
62         /* Dynamically Typed Value Object */
63         [Compact]
64         [CCode (cname = "sqlite3_value")]
65         public class Value {
66                 [CCode (cname = "sqlite3_value_blob")]
67                 public void* to_blob ();
68                 [CCode (cname = "sqlite3_value_bytes")]
69                 public int to_bytes ();
70                 [CCode (cname = "sqlite3_value_double")]
71                 public double to_double ();
72                 [CCode (cname = "sqlite3_value_int")]
73                 public int to_int ();
74                 [CCode (cname = "sqlite3_value_int64")]
75                 public int64 to_int64 ();
76                 [CCode (cname = "sqlite3_value_text")]
77                 public weak string to_text ();
78                 [CCode (cname = "sqlite3_value_type")]
79                 public int to_type ();
80                 [CCode (cname = "sqlite3_value_numeric_type")]
81                 public int to_numeric_type ();
82         }
83
84         [CCode (cname = "sqlite3_callback", instance_pos = 0)]
85         public delegate int Callback (int n_columns, [CCode (array_length = false)] string[] values, [CCode (array_length = false)] string[] column_names);
86
87         [CCode (cname = "SQLITE_OK")]
88         public const int OK;
89         [CCode (cname = "SQLITE_ERROR")]
90         public const int ERROR;
91         [CCode (cname = "SQLITE_INTERNAL")]
92         public const int INTERNAL;
93         [CCode (cname = "SQLITE_PERM")]
94         public const int PERM;
95         [CCode (cname = "SQLITE_ABORT")]
96         public const int ABORT;
97         [CCode (cname = "SQLITE_BUSY")]
98         public const int BUSY;
99         [CCode (cname = "SQLITE_LOCKED")]
100         public const int LOCKED;
101         [CCode (cname = "SQLITE_NOMEM")]
102         public const int NOMEM;
103         [CCode (cname = "SQLITE_READONLY")]
104         public const int READONLY;
105         [CCode (cname = "SQLITE_INTERRUPT")]
106         public const int INTERRUPT;
107         [CCode (cname = "SQLITE_IOERR")]
108         public const int IOERR;
109         [CCode (cname = "SQLITE_CORRUPT")]
110         public const int CORRUPT;
111         [CCode (cname = "SQLITE_NOTFOUND")]
112         public const int NOTFOUND;
113         [CCode (cname = "SQLITE_FULL")]
114         public const int FULL;
115         [CCode (cname = "SQLITE_CANTOPEN")]
116         public const int CANTOPEN;
117         [CCode (cname = "SQLITE_PROTOCOL")]
118         public const int PROTOCOL;
119         [CCode (cname = "SQLITE_EMPTY")]
120         public const int EMPTY;
121         [CCode (cname = "SQLITE_SCHEMA")]
122         public const int SCHEMA;
123         [CCode (cname = "SQLITE_TOOBIG")]
124         public const int TOOBIG;
125         [CCode (cname = "SQLITE_CONSTRAINT")]
126         public const int CONSTRAINT;
127         [CCode (cname = "SQLITE_MISMATCH")]
128         public const int MISMATCH;
129         [CCode (cname = "SQLITE_MISUSE")]
130         public const int MISUSE;
131         [CCode (cname = "SQLITE_NOLFS")]
132         public const int NOLFS;
133         [CCode (cname = "SQLITE_AUTH")]
134         public const int AUTH;
135         [CCode (cname = "SQLITE_FORMAT")]
136         public const int FORMAT;
137         [CCode (cname = "SQLITE_RANGE")]
138         public const int RANGE;
139         [CCode (cname = "SQLITE_NOTADB")]
140         public const int NOTADB;
141         [CCode (cname = "SQLITE_ROW")]
142         public const int ROW;
143         [CCode (cname = "SQLITE_DONE")]
144         public const int DONE;
145         [CCode (cname = "SQLITE_OPEN_READONLY")]
146         public const int OPEN_READONLY;
147         [CCode (cname = "SQLITE_OPEN_READWRITE")]
148         public const int OPEN_READWRITE;
149         [CCode (cname = "SQLITE_OPEN_CREATE")]
150         public const int OPEN_CREATE;
151         [CCode (cname = "SQLITE_INTEGER")]
152         public const int INTEGER;
153         [CCode (cname = "SQLITE_FLOAT")]
154         public const int FLOAT;
155         [CCode (cname = "SQLITE_BLOB")]
156         public const int BLOB;
157         [CCode (cname = "SQLITE_NULL")]
158         public const int NULL;
159         [CCode (cname = "SQLITE3_TEXT")]
160         public const int TEXT;
161         [CCode (cname = "SQLITE_MUTEX_FAST")]
162         public const int MUTEX_FAST;
163         [CCode (cname = "SQLITE_MUTEX_RECURSIVE")]
164         public const int MUTEX_RECURSIVE;
165
166         /* SQL Statement Object */
167         [Compact]
168         [CCode (free_function = "sqlite3_finalize", cname = "sqlite3_stmt", cprefix = "sqlite3_")]
169         public class Statement {
170                 public int bind_parameter_count ();
171                 public int bind_parameter_index (string name);
172                 public weak string bind_parameter_name (int index);
173                 public int clear_bindings ();
174                 public int column_count ();
175                 public int data_count ();
176                 public weak Database db_handle ();
177                 public int reset ();
178                 public int step ();
179                 public int bind_blob (int index, void* value, int n, GLib.DestroyNotify destroy_notify);
180                 public int bind_double (int index, double value);
181                 public int bind_int (int index, int value);
182                 public int bind_int64 (int index, int64 value);
183                 public int bind_null (int index);
184                 public int bind_text (int index, owned string value, int n = -1, GLib.DestroyNotify destroy_notify = GLib.g_free);
185                 public int bind_value (int index, Value value);
186                 public int bind_zeroblob (int index, int n);
187                 public void* column_blob (int col);
188                 public int column_bytes (int col);
189                 public double column_double (int col);
190                 public int column_int (int col);
191                 public int64 column_int64 (int col);
192                 public weak string column_text (int col);
193                 public int column_type (int col);
194                 public weak Value column_value (int col);
195                 public weak string column_name (int index);
196                 public weak string sql ();
197         }
198
199         [Compact]
200         [CCode (cname = "sqlite3_mutex")]
201         public class Mutex {
202                 [CCode (cname = "sqlite3_mutex_alloc")]
203                 public Mutex (int mutex_type = MUTEX_RECURSIVE);
204                 public void enter ();
205                 public int @try ();
206                 public void leave ();
207         }
208 }
209