diff options
Diffstat (limited to 'common/unqlite/unqlite.h')
-rw-r--r-- | common/unqlite/unqlite.h | 949 |
1 files changed, 0 insertions, 949 deletions
diff --git a/common/unqlite/unqlite.h b/common/unqlite/unqlite.h deleted file mode 100644 index bf7ee50..0000000 --- a/common/unqlite/unqlite.h +++ /dev/null | |||
@@ -1,949 +0,0 @@ | |||
1 | /* This file was automatically generated. Do not edit (Except for compile time directives)! */ | ||
2 | #ifndef _UNQLITE_H_ | ||
3 | #define _UNQLITE_H_ | ||
4 | /* | ||
5 | * Symisc UnQLite: An Embeddable NoSQL (Post Modern) Database Engine. | ||
6 | * Copyright (C) 2012-2013, Symisc Systems http://unqlite.org/ | ||
7 | * Version 1.1.6 | ||
8 | * For information on licensing, redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES | ||
9 | * please contact Symisc Systems via: | ||
10 | * legal@symisc.net | ||
11 | * licensing@symisc.net | ||
12 | * contact@symisc.net | ||
13 | * or visit: | ||
14 | * http://unqlite.org/licensing.html | ||
15 | */ | ||
16 | /* | ||
17 | * Copyright (C) 2012, 2013 Symisc Systems, S.U.A.R.L [M.I.A.G Mrad Chems Eddine <chm@symisc.net>]. | ||
18 | * All rights reserved. | ||
19 | * | ||
20 | * Redistribution and use in source and binary forms, with or without | ||
21 | * modification, are permitted provided that the following conditions | ||
22 | * are met: | ||
23 | * 1. Redistributions of source code must retain the above copyright | ||
24 | * notice, this list of conditions and the following disclaimer. | ||
25 | * 2. Redistributions in binary form must reproduce the above copyright | ||
26 | * notice, this list of conditions and the following disclaimer in the | ||
27 | * documentation and/or other materials provided with the distribution. | ||
28 | * | ||
29 | * THIS SOFTWARE IS PROVIDED BY SYMISC SYSTEMS ``AS IS'' AND ANY EXPRESS | ||
30 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
31 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR | ||
32 | * NON-INFRINGEMENT, ARE DISCLAIMED. IN NO EVENT SHALL SYMISC SYSTEMS | ||
33 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
34 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
35 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR | ||
36 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | ||
37 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE | ||
38 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN | ||
39 | * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
40 | */ | ||
41 | /* $SymiscID: unqlite.h v1.1 UNIX|WIN32/64 2012-11-02 02:10 stable <chm@symisc.net> $ */ | ||
42 | #include <stdarg.h> /* needed for the definition of va_list */ | ||
43 | /* | ||
44 | * Compile time engine version, signature, identification in the symisc source tree | ||
45 | * and copyright notice. | ||
46 | * Each macro have an equivalent C interface associated with it that provide the same | ||
47 | * information but are associated with the library instead of the header file. | ||
48 | * Refer to [unqlite_lib_version()], [unqlite_lib_signature()], [unqlite_lib_ident()] and | ||
49 | * [unqlite_lib_copyright()] for more information. | ||
50 | */ | ||
51 | /* | ||
52 | * The UNQLITE_VERSION C preprocessor macroevaluates to a string literal | ||
53 | * that is the unqlite version in the format "X.Y.Z" where X is the major | ||
54 | * version number and Y is the minor version number and Z is the release | ||
55 | * number. | ||
56 | */ | ||
57 | #define UNQLITE_VERSION "1.1.6" | ||
58 | /* | ||
59 | * The UNQLITE_VERSION_NUMBER C preprocessor macro resolves to an integer | ||
60 | * with the value (X*1000000 + Y*1000 + Z) where X, Y, and Z are the same | ||
61 | * numbers used in [UNQLITE_VERSION]. | ||
62 | */ | ||
63 | #define UNQLITE_VERSION_NUMBER 1001006 | ||
64 | /* | ||
65 | * The UNQLITE_SIG C preprocessor macro evaluates to a string | ||
66 | * literal which is the public signature of the unqlite engine. | ||
67 | * This signature could be included for example in a host-application | ||
68 | * generated Server MIME header as follows: | ||
69 | * Server: YourWebServer/x.x unqlite/x.x.x \r\n | ||
70 | */ | ||
71 | #define UNQLITE_SIG "unqlite/1.1.6" | ||
72 | /* | ||
73 | * UnQLite identification in the Symisc source tree: | ||
74 | * Each particular check-in of a particular software released | ||
75 | * by symisc systems have an unique identifier associated with it. | ||
76 | * This macro hold the one associated with unqlite. | ||
77 | */ | ||
78 | #define UNQLITE_IDENT "unqlite:b172a1e2c3f62fb35c8e1fb2795121f82356cad6" | ||
79 | /* | ||
80 | * Copyright notice. | ||
81 | * If you have any questions about the licensing situation, please | ||
82 | * visit http://unqlite.org/licensing.html | ||
83 | * or contact Symisc Systems via: | ||
84 | * legal@symisc.net | ||
85 | * licensing@symisc.net | ||
86 | * contact@symisc.net | ||
87 | */ | ||
88 | #define UNQLITE_COPYRIGHT "Copyright (C) Symisc Systems, S.U.A.R.L [Mrad Chems Eddine <chm@symisc.net>] 2012-2013, http://unqlite.org/" | ||
89 | |||
90 | /* Forward declaration to public objects */ | ||
91 | typedef struct unqlite_io_methods unqlite_io_methods; | ||
92 | typedef struct unqlite_kv_methods unqlite_kv_methods; | ||
93 | typedef struct unqlite_kv_engine unqlite_kv_engine; | ||
94 | typedef struct jx9_io_stream unqlite_io_stream; | ||
95 | typedef struct jx9_context unqlite_context; | ||
96 | typedef struct jx9_value unqlite_value; | ||
97 | typedef struct unqlite_vfs unqlite_vfs; | ||
98 | typedef struct unqlite_vm unqlite_vm; | ||
99 | typedef struct unqlite unqlite; | ||
100 | /* | ||
101 | * ------------------------------ | ||
102 | * Compile time directives | ||
103 | * ------------------------------ | ||
104 | * For most purposes, UnQLite can be built just fine using the default compilation options. | ||
105 | * However, if required, the compile-time options documented below can be used to omit UnQLite | ||
106 | * features (resulting in a smaller compiled library size) or to change the default values | ||
107 | * of some parameters. | ||
108 | * Every effort has been made to ensure that the various combinations of compilation options | ||
109 | * work harmoniously and produce a working library. | ||
110 | * | ||
111 | * UNQLITE_ENABLE_THREADS | ||
112 | * This option controls whether or not code is included in UnQLite to enable it to operate | ||
113 | * safely in a multithreaded environment. The default is not. All mutexing code is omitted | ||
114 | * and it is unsafe to use UnQLite in a multithreaded program. When compiled with the | ||
115 | * UNQLITE_ENABLE_THREADS directive enabled, UnQLite can be used in a multithreaded program | ||
116 | * and it is safe to share the same virtual machine and engine handle between two or more threads. | ||
117 | * The value of UNQLITE_ENABLE_THREADS can be determined at run-time using the unqlite_lib_is_threadsafe() | ||
118 | * interface. | ||
119 | * When UnQLite has been compiled with threading support then the threading mode can be altered | ||
120 | * at run-time using the unqlite_lib_config() interface together with one of these verbs: | ||
121 | * UNQLITE_LIB_CONFIG_THREAD_LEVEL_SINGLE | ||
122 | * UNQLITE_LIB_CONFIG_THREAD_LEVEL_MULTI | ||
123 | * Platforms others than Windows and UNIX systems must install their own mutex subsystem via | ||
124 | * unqlite_lib_config() with a configuration verb set to UNQLITE_LIB_CONFIG_USER_MUTEX. | ||
125 | * Otherwise the library is not threadsafe. | ||
126 | * Note that you must link UnQLite with the POSIX threads library under UNIX systems (i.e: -lpthread). | ||
127 | * | ||
128 | * Options To Omit/Enable Features | ||
129 | * | ||
130 | * The following options can be used to reduce the size of the compiled library by omitting optional | ||
131 | * features. This is probably only useful in embedded systems where space is especially tight, as even | ||
132 | * with all features included the UnQLite library is relatively small. Don't forget to tell your | ||
133 | * compiler to optimize for binary size! (the -Os option if using GCC). Telling your compiler | ||
134 | * to optimize for size usually has a much larger impact on library footprint than employing | ||
135 | * any of these compile-time options. | ||
136 | * | ||
137 | * JX9_DISABLE_BUILTIN_FUNC | ||
138 | * Jx9 is shipped with more than 312 built-in functions suitable for most purposes like | ||
139 | * string and INI processing, ZIP extracting, Base64 encoding/decoding, JSON encoding/decoding | ||
140 | * and so forth. | ||
141 | * If this directive is enabled, then all built-in Jx9 functions are omitted from the build. | ||
142 | * Note that special functions such as db_create(), db_store(), db_fetch(), etc. are not omitted | ||
143 | * from the build and are not affected by this directive. | ||
144 | * | ||
145 | * JX9_ENABLE_MATH_FUNC | ||
146 | * If this directive is enabled, built-in math functions such as sqrt(), abs(), log(), ceil(), etc. | ||
147 | * are included in the build. Note that you may need to link UnQLite with the math library in same | ||
148 | * Linux/BSD flavor (i.e: -lm). | ||
149 | * | ||
150 | * JX9_DISABLE_DISK_IO | ||
151 | * If this directive is enabled, built-in VFS functions such as chdir(), mkdir(), chroot(), unlink(), | ||
152 | * sleep(), etc. are omitted from the build. | ||
153 | * | ||
154 | * UNQLITE_ENABLE_JX9_HASH_IO | ||
155 | * If this directive is enabled, built-in hash functions such as md5(), sha1(), md5_file(), crc32(), etc. | ||
156 | * are included in the build. | ||
157 | */ | ||
158 | /* Symisc public definitions */ | ||
159 | #if !defined(SYMISC_STANDARD_DEFS) | ||
160 | #define SYMISC_STANDARD_DEFS | ||
161 | #if defined (_WIN32) || defined (WIN32) || defined(__MINGW32__) || defined (_MSC_VER) || defined (_WIN32_WCE) | ||
162 | /* Windows Systems */ | ||
163 | #if !defined(__WINNT__) | ||
164 | #define __WINNT__ | ||
165 | #endif | ||
166 | /* | ||
167 | * Determine if we are dealing with WindowsCE - which has a much | ||
168 | * reduced API. | ||
169 | */ | ||
170 | #if defined(_WIN32_WCE) | ||
171 | #ifndef __WIN_CE__ | ||
172 | #define __WIN_CE__ | ||
173 | #endif /* __WIN_CE__ */ | ||
174 | #endif /* _WIN32_WCE */ | ||
175 | #else | ||
176 | /* | ||
177 | * By default we will assume that we are compiling on a UNIX systems. | ||
178 | * Otherwise the OS_OTHER directive must be defined. | ||
179 | */ | ||
180 | #if !defined(OS_OTHER) | ||
181 | #if !defined(__UNIXES__) | ||
182 | #define __UNIXES__ | ||
183 | #endif /* __UNIXES__ */ | ||
184 | #else | ||
185 | #endif /* OS_OTHER */ | ||
186 | #endif /* __WINNT__/__UNIXES__ */ | ||
187 | #if defined(_MSC_VER) || defined(__BORLANDC__) | ||
188 | typedef signed __int64 sxi64; /* 64 bits(8 bytes) signed int64 */ | ||
189 | typedef unsigned __int64 sxu64; /* 64 bits(8 bytes) unsigned int64 */ | ||
190 | #else | ||
191 | typedef signed long long int sxi64; /* 64 bits(8 bytes) signed int64 */ | ||
192 | typedef unsigned long long int sxu64; /* 64 bits(8 bytes) unsigned int64 */ | ||
193 | #endif /* _MSC_VER */ | ||
194 | /* Signature of the consumer routine */ | ||
195 | typedef int (*ProcConsumer)(const void *, unsigned int, void *); | ||
196 | /* Forward reference */ | ||
197 | typedef struct SyMutexMethods SyMutexMethods; | ||
198 | typedef struct SyMemMethods SyMemMethods; | ||
199 | typedef struct SyString SyString; | ||
200 | typedef struct syiovec syiovec; | ||
201 | typedef struct SyMutex SyMutex; | ||
202 | typedef struct Sytm Sytm; | ||
203 | /* Scatter and gather array. */ | ||
204 | struct syiovec | ||
205 | { | ||
206 | #if defined (__WINNT__) | ||
207 | /* Same fields type and offset as WSABUF structure defined one winsock2 header */ | ||
208 | unsigned long nLen; | ||
209 | char *pBase; | ||
210 | #else | ||
211 | void *pBase; | ||
212 | unsigned long nLen; | ||
213 | #endif | ||
214 | }; | ||
215 | struct SyString | ||
216 | { | ||
217 | const char *zString; /* Raw string (may not be null terminated) */ | ||
218 | unsigned int nByte; /* Raw string length */ | ||
219 | }; | ||
220 | /* Time structure. */ | ||
221 | struct Sytm | ||
222 | { | ||
223 | int tm_sec; /* seconds (0 - 60) */ | ||
224 | int tm_min; /* minutes (0 - 59) */ | ||
225 | int tm_hour; /* hours (0 - 23) */ | ||
226 | int tm_mday; /* day of month (1 - 31) */ | ||
227 | int tm_mon; /* month of year (0 - 11) */ | ||
228 | int tm_year; /* year + 1900 */ | ||
229 | int tm_wday; /* day of week (Sunday = 0) */ | ||
230 | int tm_yday; /* day of year (0 - 365) */ | ||
231 | int tm_isdst; /* is summer time in effect? */ | ||
232 | char *tm_zone; /* abbreviation of timezone name */ | ||
233 | long tm_gmtoff; /* offset from UTC in seconds */ | ||
234 | }; | ||
235 | /* Convert a tm structure (struct tm *) found in <time.h> to a Sytm structure */ | ||
236 | #define STRUCT_TM_TO_SYTM(pTM, pSYTM) \ | ||
237 | (pSYTM)->tm_hour = (pTM)->tm_hour;\ | ||
238 | (pSYTM)->tm_min = (pTM)->tm_min;\ | ||
239 | (pSYTM)->tm_sec = (pTM)->tm_sec;\ | ||
240 | (pSYTM)->tm_mon = (pTM)->tm_mon;\ | ||
241 | (pSYTM)->tm_mday = (pTM)->tm_mday;\ | ||
242 | (pSYTM)->tm_year = (pTM)->tm_year + 1900;\ | ||
243 | (pSYTM)->tm_yday = (pTM)->tm_yday;\ | ||
244 | (pSYTM)->tm_wday = (pTM)->tm_wday;\ | ||
245 | (pSYTM)->tm_isdst = (pTM)->tm_isdst;\ | ||
246 | (pSYTM)->tm_gmtoff = 0;\ | ||
247 | (pSYTM)->tm_zone = 0; | ||
248 | |||
249 | /* Convert a SYSTEMTIME structure (LPSYSTEMTIME: Windows Systems only ) to a Sytm structure */ | ||
250 | #define SYSTEMTIME_TO_SYTM(pSYSTIME, pSYTM) \ | ||
251 | (pSYTM)->tm_hour = (pSYSTIME)->wHour;\ | ||
252 | (pSYTM)->tm_min = (pSYSTIME)->wMinute;\ | ||
253 | (pSYTM)->tm_sec = (pSYSTIME)->wSecond;\ | ||
254 | (pSYTM)->tm_mon = (pSYSTIME)->wMonth - 1;\ | ||
255 | (pSYTM)->tm_mday = (pSYSTIME)->wDay;\ | ||
256 | (pSYTM)->tm_year = (pSYSTIME)->wYear;\ | ||
257 | (pSYTM)->tm_yday = 0;\ | ||
258 | (pSYTM)->tm_wday = (pSYSTIME)->wDayOfWeek;\ | ||
259 | (pSYTM)->tm_gmtoff = 0;\ | ||
260 | (pSYTM)->tm_isdst = -1;\ | ||
261 | (pSYTM)->tm_zone = 0; | ||
262 | |||
263 | /* Dynamic memory allocation methods. */ | ||
264 | struct SyMemMethods | ||
265 | { | ||
266 | void * (*xAlloc)(unsigned int); /* [Required:] Allocate a memory chunk */ | ||
267 | void * (*xRealloc)(void *, unsigned int); /* [Required:] Re-allocate a memory chunk */ | ||
268 | void (*xFree)(void *); /* [Required:] Release a memory chunk */ | ||
269 | unsigned int (*xChunkSize)(void *); /* [Optional:] Return chunk size */ | ||
270 | int (*xInit)(void *); /* [Optional:] Initialization callback */ | ||
271 | void (*xRelease)(void *); /* [Optional:] Release callback */ | ||
272 | void *pUserData; /* [Optional:] First argument to xInit() and xRelease() */ | ||
273 | }; | ||
274 | /* Out of memory callback signature. */ | ||
275 | typedef int (*ProcMemError)(void *); | ||
276 | /* Mutex methods. */ | ||
277 | struct SyMutexMethods | ||
278 | { | ||
279 | int (*xGlobalInit)(void); /* [Optional:] Global mutex initialization */ | ||
280 | void (*xGlobalRelease)(void); /* [Optional:] Global Release callback () */ | ||
281 | SyMutex * (*xNew)(int); /* [Required:] Request a new mutex */ | ||
282 | void (*xRelease)(SyMutex *); /* [Optional:] Release a mutex */ | ||
283 | void (*xEnter)(SyMutex *); /* [Required:] Enter mutex */ | ||
284 | int (*xTryEnter)(SyMutex *); /* [Optional:] Try to enter a mutex */ | ||
285 | void (*xLeave)(SyMutex *); /* [Required:] Leave a locked mutex */ | ||
286 | }; | ||
287 | #if defined (_MSC_VER) || defined (__MINGW32__) || defined (__GNUC__) && defined (__declspec) | ||
288 | #define SX_APIIMPORT __declspec(dllimport) | ||
289 | #define SX_APIEXPORT __declspec(dllexport) | ||
290 | #else | ||
291 | #define SX_APIIMPORT | ||
292 | #define SX_APIEXPORT | ||
293 | #endif | ||
294 | /* Standard return values from Symisc public interfaces */ | ||
295 | #define SXRET_OK 0 /* Not an error */ | ||
296 | #define SXERR_MEM (-1) /* Out of memory */ | ||
297 | #define SXERR_IO (-2) /* IO error */ | ||
298 | #define SXERR_EMPTY (-3) /* Empty field */ | ||
299 | #define SXERR_LOCKED (-4) /* Locked operation */ | ||
300 | #define SXERR_ORANGE (-5) /* Out of range value */ | ||
301 | #define SXERR_NOTFOUND (-6) /* Item not found */ | ||
302 | #define SXERR_LIMIT (-7) /* Limit reached */ | ||
303 | #define SXERR_MORE (-8) /* Need more input */ | ||
304 | #define SXERR_INVALID (-9) /* Invalid parameter */ | ||
305 | #define SXERR_ABORT (-10) /* User callback request an operation abort */ | ||
306 | #define SXERR_EXISTS (-11) /* Item exists */ | ||
307 | #define SXERR_SYNTAX (-12) /* Syntax error */ | ||
308 | #define SXERR_UNKNOWN (-13) /* Unknown error */ | ||
309 | #define SXERR_BUSY (-14) /* Busy operation */ | ||
310 | #define SXERR_OVERFLOW (-15) /* Stack or buffer overflow */ | ||
311 | #define SXERR_WILLBLOCK (-16) /* Operation will block */ | ||
312 | #define SXERR_NOTIMPLEMENTED (-17) /* Operation not implemented */ | ||
313 | #define SXERR_EOF (-18) /* End of input */ | ||
314 | #define SXERR_PERM (-19) /* Permission error */ | ||
315 | #define SXERR_NOOP (-20) /* No-op */ | ||
316 | #define SXERR_FORMAT (-21) /* Invalid format */ | ||
317 | #define SXERR_NEXT (-22) /* Not an error */ | ||
318 | #define SXERR_OS (-23) /* System call return an error */ | ||
319 | #define SXERR_CORRUPT (-24) /* Corrupted pointer */ | ||
320 | #define SXERR_CONTINUE (-25) /* Not an error: Operation in progress */ | ||
321 | #define SXERR_NOMATCH (-26) /* No match */ | ||
322 | #define SXERR_RESET (-27) /* Operation reset */ | ||
323 | #define SXERR_DONE (-28) /* Not an error */ | ||
324 | #define SXERR_SHORT (-29) /* Buffer too short */ | ||
325 | #define SXERR_PATH (-30) /* Path error */ | ||
326 | #define SXERR_TIMEOUT (-31) /* Timeout */ | ||
327 | #define SXERR_BIG (-32) /* Too big for processing */ | ||
328 | #define SXERR_RETRY (-33) /* Retry your call */ | ||
329 | #define SXERR_IGNORE (-63) /* Ignore */ | ||
330 | #endif /* SYMISC_PUBLIC_DEFS */ | ||
331 | /* | ||
332 | * Marker for exported interfaces. | ||
333 | */ | ||
334 | #define UNQLITE_APIEXPORT SX_APIEXPORT | ||
335 | /* | ||
336 | * If compiling for a processor that lacks floating point | ||
337 | * support, substitute integer for floating-point. | ||
338 | */ | ||
339 | #ifdef UNQLITE_OMIT_FLOATING_POINT | ||
340 | typedef sxi64 uqlite_real; | ||
341 | #else | ||
342 | typedef double unqlite_real; | ||
343 | #endif | ||
344 | typedef sxi64 unqlite_int64; | ||
345 | /* Standard UnQLite return values */ | ||
346 | #define UNQLITE_OK SXRET_OK /* Successful result */ | ||
347 | /* Beginning of error codes */ | ||
348 | #define UNQLITE_NOMEM SXERR_MEM /* Out of memory */ | ||
349 | #define UNQLITE_ABORT SXERR_ABORT /* Another thread have released this instance */ | ||
350 | #define UNQLITE_IOERR SXERR_IO /* IO error */ | ||
351 | #define UNQLITE_CORRUPT SXERR_CORRUPT /* Corrupt pointer */ | ||
352 | #define UNQLITE_LOCKED SXERR_LOCKED /* Forbidden Operation */ | ||
353 | #define UNQLITE_BUSY SXERR_BUSY /* The database file is locked */ | ||
354 | #define UNQLITE_DONE SXERR_DONE /* Operation done */ | ||
355 | #define UNQLITE_PERM SXERR_PERM /* Permission error */ | ||
356 | #define UNQLITE_NOTIMPLEMENTED SXERR_NOTIMPLEMENTED /* Method not implemented by the underlying Key/Value storage engine */ | ||
357 | #define UNQLITE_NOTFOUND SXERR_NOTFOUND /* No such record */ | ||
358 | #define UNQLITE_NOOP SXERR_NOOP /* No such method */ | ||
359 | #define UNQLITE_INVALID SXERR_INVALID /* Invalid parameter */ | ||
360 | #define UNQLITE_EOF SXERR_EOF /* End Of Input */ | ||
361 | #define UNQLITE_UNKNOWN SXERR_UNKNOWN /* Unknown configuration option */ | ||
362 | #define UNQLITE_LIMIT SXERR_LIMIT /* Database limit reached */ | ||
363 | #define UNQLITE_EXISTS SXERR_EXISTS /* Record exists */ | ||
364 | #define UNQLITE_EMPTY SXERR_EMPTY /* Empty record */ | ||
365 | #define UNQLITE_COMPILE_ERR (-70) /* Compilation error */ | ||
366 | #define UNQLITE_VM_ERR (-71) /* Virtual machine error */ | ||
367 | #define UNQLITE_FULL (-73) /* Full database (unlikely) */ | ||
368 | #define UNQLITE_CANTOPEN (-74) /* Unable to open the database file */ | ||
369 | #define UNQLITE_READ_ONLY (-75) /* Read only Key/Value storage engine */ | ||
370 | #define UNQLITE_LOCKERR (-76) /* Locking protocol error */ | ||
371 | /* end-of-error-codes */ | ||
372 | /* | ||
373 | * Database Handle Configuration Commands. | ||
374 | * | ||
375 | * The following set of constants are the available configuration verbs that can | ||
376 | * be used by the host-application to configure an UnQLite database handle. | ||
377 | * These constants must be passed as the second argument to [unqlite_config()]. | ||
378 | * | ||
379 | * Each options require a variable number of arguments. | ||
380 | * The [unqlite_config()] interface will return UNQLITE_OK on success, any other | ||
381 | * return value indicates failure. | ||
382 | * For a full discussion on the configuration verbs and their expected | ||
383 | * parameters, please refer to this page: | ||
384 | * http://unqlite.org/c_api/unqlite_config.html | ||
385 | */ | ||
386 | #define UNQLITE_CONFIG_JX9_ERR_LOG 1 /* TWO ARGUMENTS: const char **pzBuf, int *pLen */ | ||
387 | #define UNQLITE_CONFIG_MAX_PAGE_CACHE 2 /* ONE ARGUMENT: int nMaxPage */ | ||
388 | #define UNQLITE_CONFIG_ERR_LOG 3 /* TWO ARGUMENTS: const char **pzBuf, int *pLen */ | ||
389 | #define UNQLITE_CONFIG_KV_ENGINE 4 /* ONE ARGUMENT: const char *zKvName */ | ||
390 | #define UNQLITE_CONFIG_DISABLE_AUTO_COMMIT 5 /* NO ARGUMENTS */ | ||
391 | #define UNQLITE_CONFIG_GET_KV_NAME 6 /* ONE ARGUMENT: const char **pzPtr */ | ||
392 | /* | ||
393 | * UnQLite/Jx9 Virtual Machine Configuration Commands. | ||
394 | * | ||
395 | * The following set of constants are the available configuration verbs that can | ||
396 | * be used by the host-application to configure the Jx9 (Via UnQLite) Virtual machine. | ||
397 | * These constants must be passed as the second argument to the [unqlite_vm_config()] | ||
398 | * interface. | ||
399 | * Each options require a variable number of arguments. | ||
400 | * The [unqlite_vm_config()] interface will return UNQLITE_OK on success, any other return | ||
401 | * value indicates failure. | ||
402 | * There are many options but the most importants are: UNQLITE_VM_CONFIG_OUTPUT which install | ||
403 | * a VM output consumer callback, UNQLITE_VM_CONFIG_HTTP_REQUEST which parse and register | ||
404 | * a HTTP request and UNQLITE_VM_CONFIG_ARGV_ENTRY which populate the $argv array. | ||
405 | * For a full discussion on the configuration verbs and their expected parameters, please | ||
406 | * refer to this page: | ||
407 | * http://unqlite.org/c_api/unqlite_vm_config.html | ||
408 | */ | ||
409 | #define UNQLITE_VM_CONFIG_OUTPUT 1 /* TWO ARGUMENTS: int (*xConsumer)(const void *pOut, unsigned int nLen, void *pUserData), void *pUserData */ | ||
410 | #define UNQLITE_VM_CONFIG_IMPORT_PATH 2 /* ONE ARGUMENT: const char *zIncludePath */ | ||
411 | #define UNQLITE_VM_CONFIG_ERR_REPORT 3 /* NO ARGUMENTS: Report all run-time errors in the VM output */ | ||
412 | #define UNQLITE_VM_CONFIG_RECURSION_DEPTH 4 /* ONE ARGUMENT: int nMaxDepth */ | ||
413 | #define UNQLITE_VM_OUTPUT_LENGTH 5 /* ONE ARGUMENT: unsigned int *pLength */ | ||
414 | #define UNQLITE_VM_CONFIG_CREATE_VAR 6 /* TWO ARGUMENTS: const char *zName, unqlite_value *pValue */ | ||
415 | #define UNQLITE_VM_CONFIG_HTTP_REQUEST 7 /* TWO ARGUMENTS: const char *zRawRequest, int nRequestLength */ | ||
416 | #define UNQLITE_VM_CONFIG_SERVER_ATTR 8 /* THREE ARGUMENTS: const char *zKey, const char *zValue, int nLen */ | ||
417 | #define UNQLITE_VM_CONFIG_ENV_ATTR 9 /* THREE ARGUMENTS: const char *zKey, const char *zValue, int nLen */ | ||
418 | #define UNQLITE_VM_CONFIG_EXEC_VALUE 10 /* ONE ARGUMENT: unqlite_value **ppValue */ | ||
419 | #define UNQLITE_VM_CONFIG_IO_STREAM 11 /* ONE ARGUMENT: const unqlite_io_stream *pStream */ | ||
420 | #define UNQLITE_VM_CONFIG_ARGV_ENTRY 12 /* ONE ARGUMENT: const char *zValue */ | ||
421 | #define UNQLITE_VM_CONFIG_EXTRACT_OUTPUT 13 /* TWO ARGUMENTS: const void **ppOut, unsigned int *pOutputLen */ | ||
422 | /* | ||
423 | * Storage engine configuration commands. | ||
424 | * | ||
425 | * The following set of constants are the available configuration verbs that can | ||
426 | * be used by the host-application to configure the underlying storage engine (i.e Hash, B+tree, R+tree). | ||
427 | * These constants must be passed as the first argument to [unqlite_kv_config()]. | ||
428 | * Each options require a variable number of arguments. | ||
429 | * The [unqlite_kv_config()] interface will return UNQLITE_OK on success, any other return | ||
430 | * value indicates failure. | ||
431 | * For a full discussion on the configuration verbs and their expected parameters, please | ||
432 | * refer to this page: | ||
433 | * http://unqlite.org/c_api/unqlite_kv_config.html | ||
434 | */ | ||
435 | #define UNQLITE_KV_CONFIG_HASH_FUNC 1 /* ONE ARGUMENT: unsigned int (*xHash)(const void *,unsigned int) */ | ||
436 | #define UNQLITE_KV_CONFIG_CMP_FUNC 2 /* ONE ARGUMENT: int (*xCmp)(const void *,const void *,unsigned int) */ | ||
437 | /* | ||
438 | * Global Library Configuration Commands. | ||
439 | * | ||
440 | * The following set of constants are the available configuration verbs that can | ||
441 | * be used by the host-application to configure the whole library. | ||
442 | * These constants must be passed as the first argument to [unqlite_lib_config()]. | ||
443 | * | ||
444 | * Each options require a variable number of arguments. | ||
445 | * The [unqlite_lib_config()] interface will return UNQLITE_OK on success, any other return | ||
446 | * value indicates failure. | ||
447 | * Notes: | ||
448 | * The default configuration is recommended for most applications and so the call to | ||
449 | * [unqlite_lib_config()] is usually not necessary. It is provided to support rare | ||
450 | * applications with unusual needs. | ||
451 | * The [unqlite_lib_config()] interface is not threadsafe. The application must insure that | ||
452 | * no other [unqlite_*()] interfaces are invoked by other threads while [unqlite_lib_config()] | ||
453 | * is running. Furthermore, [unqlite_lib_config()] may only be invoked prior to library | ||
454 | * initialization using [unqlite_lib_init()] or [unqlite_init()] or after shutdown | ||
455 | * by [unqlite_lib_shutdown()]. If [unqlite_lib_config()] is called after [unqlite_lib_init()] | ||
456 | * or [unqlite_init()] and before [unqlite_lib_shutdown()] then it will return UNQLITE_LOCKED. | ||
457 | * For a full discussion on the configuration verbs and their expected parameters, please | ||
458 | * refer to this page: | ||
459 | * http://unqlite.org/c_api/unqlite_lib.html | ||
460 | */ | ||
461 | #define UNQLITE_LIB_CONFIG_USER_MALLOC 1 /* ONE ARGUMENT: const SyMemMethods *pMemMethods */ | ||
462 | #define UNQLITE_LIB_CONFIG_MEM_ERR_CALLBACK 2 /* TWO ARGUMENTS: int (*xMemError)(void *), void *pUserData */ | ||
463 | #define UNQLITE_LIB_CONFIG_USER_MUTEX 3 /* ONE ARGUMENT: const SyMutexMethods *pMutexMethods */ | ||
464 | #define UNQLITE_LIB_CONFIG_THREAD_LEVEL_SINGLE 4 /* NO ARGUMENTS */ | ||
465 | #define UNQLITE_LIB_CONFIG_THREAD_LEVEL_MULTI 5 /* NO ARGUMENTS */ | ||
466 | #define UNQLITE_LIB_CONFIG_VFS 6 /* ONE ARGUMENT: const unqlite_vfs *pVfs */ | ||
467 | #define UNQLITE_LIB_CONFIG_STORAGE_ENGINE 7 /* ONE ARGUMENT: unqlite_kv_methods *pStorage */ | ||
468 | #define UNQLITE_LIB_CONFIG_PAGE_SIZE 8 /* ONE ARGUMENT: int iPageSize */ | ||
469 | /* | ||
470 | * These bit values are intended for use in the 3rd parameter to the [unqlite_open()] interface | ||
471 | * and in the 4th parameter to the xOpen method of the [unqlite_vfs] object. | ||
472 | */ | ||
473 | #define UNQLITE_OPEN_READONLY 0x00000001 /* Read only mode. Ok for [unqlite_open] */ | ||
474 | #define UNQLITE_OPEN_READWRITE 0x00000002 /* Ok for [unqlite_open] */ | ||
475 | #define UNQLITE_OPEN_CREATE 0x00000004 /* Ok for [unqlite_open] */ | ||
476 | #define UNQLITE_OPEN_EXCLUSIVE 0x00000008 /* VFS only */ | ||
477 | #define UNQLITE_OPEN_TEMP_DB 0x00000010 /* VFS only */ | ||
478 | #define UNQLITE_OPEN_NOMUTEX 0x00000020 /* Ok for [unqlite_open] */ | ||
479 | #define UNQLITE_OPEN_OMIT_JOURNALING 0x00000040 /* Omit journaling for this database. Ok for [unqlite_open] */ | ||
480 | #define UNQLITE_OPEN_IN_MEMORY 0x00000080 /* An in memory database. Ok for [unqlite_open]*/ | ||
481 | #define UNQLITE_OPEN_MMAP 0x00000100 /* Obtain a memory view of the whole file. Ok for [unqlite_open] */ | ||
482 | /* | ||
483 | * Synchronization Type Flags | ||
484 | * | ||
485 | * When UnQLite invokes the xSync() method of an [unqlite_io_methods] object it uses | ||
486 | * a combination of these integer values as the second argument. | ||
487 | * | ||
488 | * When the UNQLITE_SYNC_DATAONLY flag is used, it means that the sync operation only | ||
489 | * needs to flush data to mass storage. Inode information need not be flushed. | ||
490 | * If the lower four bits of the flag equal UNQLITE_SYNC_NORMAL, that means to use normal | ||
491 | * fsync() semantics. If the lower four bits equal UNQLITE_SYNC_FULL, that means to use | ||
492 | * Mac OS X style fullsync instead of fsync(). | ||
493 | */ | ||
494 | #define UNQLITE_SYNC_NORMAL 0x00002 | ||
495 | #define UNQLITE_SYNC_FULL 0x00003 | ||
496 | #define UNQLITE_SYNC_DATAONLY 0x00010 | ||
497 | /* | ||
498 | * File Locking Levels | ||
499 | * | ||
500 | * UnQLite uses one of these integer values as the second | ||
501 | * argument to calls it makes to the xLock() and xUnlock() methods | ||
502 | * of an [unqlite_io_methods] object. | ||
503 | */ | ||
504 | #define UNQLITE_LOCK_NONE 0 | ||
505 | #define UNQLITE_LOCK_SHARED 1 | ||
506 | #define UNQLITE_LOCK_RESERVED 2 | ||
507 | #define UNQLITE_LOCK_PENDING 3 | ||
508 | #define UNQLITE_LOCK_EXCLUSIVE 4 | ||
509 | /* | ||
510 | * CAPIREF: OS Interface: Open File Handle | ||
511 | * | ||
512 | * An [unqlite_file] object represents an open file in the [unqlite_vfs] OS interface | ||
513 | * layer. | ||
514 | * Individual OS interface implementations will want to subclass this object by appending | ||
515 | * additional fields for their own use. The pMethods entry is a pointer to an | ||
516 | * [unqlite_io_methods] object that defines methods for performing | ||
517 | * I/O operations on the open file. | ||
518 | */ | ||
519 | typedef struct unqlite_file unqlite_file; | ||
520 | struct unqlite_file { | ||
521 | const unqlite_io_methods *pMethods; /* Methods for an open file. MUST BE FIRST */ | ||
522 | }; | ||
523 | /* | ||
524 | * CAPIREF: OS Interface: File Methods Object | ||
525 | * | ||
526 | * Every file opened by the [unqlite_vfs] xOpen method populates an | ||
527 | * [unqlite_file] object (or, more commonly, a subclass of the | ||
528 | * [unqlite_file] object) with a pointer to an instance of this object. | ||
529 | * This object defines the methods used to perform various operations | ||
530 | * against the open file represented by the [unqlite_file] object. | ||
531 | * | ||
532 | * If the xOpen method sets the unqlite_file.pMethods element | ||
533 | * to a non-NULL pointer, then the unqlite_io_methods.xClose method | ||
534 | * may be invoked even if the xOpen reported that it failed. The | ||
535 | * only way to prevent a call to xClose following a failed xOpen | ||
536 | * is for the xOpen to set the unqlite_file.pMethods element to NULL. | ||
537 | * | ||
538 | * The flags argument to xSync may be one of [UNQLITE_SYNC_NORMAL] or | ||
539 | * [UNQLITE_SYNC_FULL]. The first choice is the normal fsync(). | ||
540 | * The second choice is a Mac OS X style fullsync. The [UNQLITE_SYNC_DATAONLY] | ||
541 | * flag may be ORed in to indicate that only the data of the file | ||
542 | * and not its inode needs to be synced. | ||
543 | * | ||
544 | * The integer values to xLock() and xUnlock() are one of | ||
545 | * | ||
546 | * UNQLITE_LOCK_NONE | ||
547 | * UNQLITE_LOCK_SHARED | ||
548 | * UNQLITE_LOCK_RESERVED | ||
549 | * UNQLITE_LOCK_PENDING | ||
550 | * UNQLITE_LOCK_EXCLUSIVE | ||
551 | * | ||
552 | * xLock() increases the lock. xUnlock() decreases the lock. | ||
553 | * The xCheckReservedLock() method checks whether any database connection, | ||
554 | * either in this process or in some other process, is holding a RESERVED, | ||
555 | * PENDING, or EXCLUSIVE lock on the file. It returns true if such a lock exists | ||
556 | * and false otherwise. | ||
557 | * | ||
558 | * The xSectorSize() method returns the sector size of the device that underlies | ||
559 | * the file. The sector size is the minimum write that can be performed without | ||
560 | * disturbing other bytes in the file. | ||
561 | * | ||
562 | */ | ||
563 | struct unqlite_io_methods { | ||
564 | int iVersion; /* Structure version number (currently 1) */ | ||
565 | int (*xClose)(unqlite_file*); | ||
566 | int (*xRead)(unqlite_file*, void*, unqlite_int64 iAmt, unqlite_int64 iOfst); | ||
567 | int (*xWrite)(unqlite_file*, const void*, unqlite_int64 iAmt, unqlite_int64 iOfst); | ||
568 | int (*xTruncate)(unqlite_file*, unqlite_int64 size); | ||
569 | int (*xSync)(unqlite_file*, int flags); | ||
570 | int (*xFileSize)(unqlite_file*, unqlite_int64 *pSize); | ||
571 | int (*xLock)(unqlite_file*, int); | ||
572 | int (*xUnlock)(unqlite_file*, int); | ||
573 | int (*xCheckReservedLock)(unqlite_file*, int *pResOut); | ||
574 | int (*xSectorSize)(unqlite_file*); | ||
575 | }; | ||
576 | /* | ||
577 | * CAPIREF: OS Interface Object | ||
578 | * | ||
579 | * An instance of the unqlite_vfs object defines the interface between | ||
580 | * the UnQLite core and the underlying operating system. The "vfs" | ||
581 | * in the name of the object stands for "Virtual File System". | ||
582 | * | ||
583 | * Only a single vfs can be registered within the UnQLite core. | ||
584 | * Vfs registration is done using the [unqlite_lib_config()] interface | ||
585 | * with a configuration verb set to UNQLITE_LIB_CONFIG_VFS. | ||
586 | * Note that Windows and UNIX (Linux, FreeBSD, Solaris, Mac OS X, etc.) users | ||
587 | * does not have to worry about registering and installing a vfs since UnQLite | ||
588 | * come with a built-in vfs for these platforms that implements most the methods | ||
589 | * defined below. | ||
590 | * | ||
591 | * Clients running on exotic systems (ie: Other than Windows and UNIX systems) | ||
592 | * must register their own vfs in order to be able to use the UnQLite library. | ||
593 | * | ||
594 | * The value of the iVersion field is initially 1 but may be larger in | ||
595 | * future versions of UnQLite. | ||
596 | * | ||
597 | * The szOsFile field is the size of the subclassed [unqlite_file] structure | ||
598 | * used by this VFS. mxPathname is the maximum length of a pathname in this VFS. | ||
599 | * | ||
600 | * At least szOsFile bytes of memory are allocated by UnQLite to hold the [unqlite_file] | ||
601 | * structure passed as the third argument to xOpen. The xOpen method does not have to | ||
602 | * allocate the structure; it should just fill it in. Note that the xOpen method must | ||
603 | * set the unqlite_file.pMethods to either a valid [unqlite_io_methods] object or to NULL. | ||
604 | * xOpen must do this even if the open fails. UnQLite expects that the unqlite_file.pMethods | ||
605 | * element will be valid after xOpen returns regardless of the success or failure of the | ||
606 | * xOpen call. | ||
607 | * | ||
608 | */ | ||
609 | struct unqlite_vfs { | ||
610 | const char *zName; /* Name of this virtual file system [i.e: Windows, UNIX, etc.] */ | ||
611 | int iVersion; /* Structure version number (currently 1) */ | ||
612 | int szOsFile; /* Size of subclassed unqlite_file */ | ||
613 | int mxPathname; /* Maximum file pathname length */ | ||
614 | int (*xOpen)(unqlite_vfs*, const char *zName, unqlite_file*,unsigned int flags); | ||
615 | int (*xDelete)(unqlite_vfs*, const char *zName, int syncDir); | ||
616 | int (*xAccess)(unqlite_vfs*, const char *zName, int flags, int *pResOut); | ||
617 | int (*xFullPathname)(unqlite_vfs*, const char *zName,int buf_len,char *zBuf); | ||
618 | int (*xTmpDir)(unqlite_vfs*,char *zBuf,int buf_len); | ||
619 | int (*xSleep)(unqlite_vfs*, int microseconds); | ||
620 | int (*xCurrentTime)(unqlite_vfs*,Sytm *pOut); | ||
621 | int (*xGetLastError)(unqlite_vfs*, int, char *); | ||
622 | }; | ||
623 | /* | ||
624 | * Flags for the xAccess VFS method | ||
625 | * | ||
626 | * These integer constants can be used as the third parameter to | ||
627 | * the xAccess method of an [unqlite_vfs] object. They determine | ||
628 | * what kind of permissions the xAccess method is looking for. | ||
629 | * With UNQLITE_ACCESS_EXISTS, the xAccess method | ||
630 | * simply checks whether the file exists. | ||
631 | * With UNQLITE_ACCESS_READWRITE, the xAccess method | ||
632 | * checks whether the named directory is both readable and writable | ||
633 | * (in other words, if files can be added, removed, and renamed within | ||
634 | * the directory). | ||
635 | * The UNQLITE_ACCESS_READWRITE constant is currently used only by the | ||
636 | * [temp_store_directory pragma], though this could change in a future | ||
637 | * release of UnQLite. | ||
638 | * With UNQLITE_ACCESS_READ, the xAccess method | ||
639 | * checks whether the file is readable. The UNQLITE_ACCESS_READ constant is | ||
640 | * currently unused, though it might be used in a future release of | ||
641 | * UnQLite. | ||
642 | */ | ||
643 | #define UNQLITE_ACCESS_EXISTS 0 | ||
644 | #define UNQLITE_ACCESS_READWRITE 1 | ||
645 | #define UNQLITE_ACCESS_READ 2 | ||
646 | /* | ||
647 | * The type used to represent a page number. The first page in a file | ||
648 | * is called page 1. 0 is used to represent "not a page". | ||
649 | * A page number is an unsigned 64-bit integer. | ||
650 | */ | ||
651 | typedef sxu64 pgno; | ||
652 | /* | ||
653 | * A database disk page is represented by an instance | ||
654 | * of the follwoing structure. | ||
655 | */ | ||
656 | typedef struct unqlite_page unqlite_page; | ||
657 | struct unqlite_page | ||
658 | { | ||
659 | unsigned char *zData; /* Content of this page */ | ||
660 | void *pUserData; /* Extra content */ | ||
661 | pgno pgno; /* Page number for this page */ | ||
662 | }; | ||
663 | /* | ||
664 | * UnQLite handle to the underlying Key/Value Storage Engine (See below). | ||
665 | */ | ||
666 | typedef void * unqlite_kv_handle; | ||
667 | /* | ||
668 | * UnQLite pager IO methods. | ||
669 | * | ||
670 | * An instance of the following structure define the exported methods of the UnQLite pager | ||
671 | * to the underlying Key/Value storage engine. | ||
672 | */ | ||
673 | typedef struct unqlite_kv_io unqlite_kv_io; | ||
674 | struct unqlite_kv_io | ||
675 | { | ||
676 | unqlite_kv_handle pHandle; /* UnQLite handle passed as the first parameter to the | ||
677 | * method defined below. | ||
678 | */ | ||
679 | unqlite_kv_methods *pMethods; /* Underlying storage engine */ | ||
680 | /* Pager methods */ | ||
681 | int (*xGet)(unqlite_kv_handle,pgno,unqlite_page **); | ||
682 | int (*xLookup)(unqlite_kv_handle,pgno,unqlite_page **); | ||
683 | int (*xNew)(unqlite_kv_handle,unqlite_page **); | ||
684 | int (*xWrite)(unqlite_page *); | ||
685 | int (*xDontWrite)(unqlite_page *); | ||
686 | int (*xDontJournal)(unqlite_page *); | ||
687 | int (*xDontMkHot)(unqlite_page *); | ||
688 | int (*xPageRef)(unqlite_page *); | ||
689 | int (*xPageUnref)(unqlite_page *); | ||
690 | int (*xPageSize)(unqlite_kv_handle); | ||
691 | int (*xReadOnly)(unqlite_kv_handle); | ||
692 | unsigned char * (*xTmpPage)(unqlite_kv_handle); | ||
693 | void (*xSetUnpin)(unqlite_kv_handle,void (*xPageUnpin)(void *)); | ||
694 | void (*xSetReload)(unqlite_kv_handle,void (*xPageReload)(void *)); | ||
695 | void (*xErr)(unqlite_kv_handle,const char *); | ||
696 | }; | ||
697 | /* | ||
698 | * Key/Value Storage Engine Cursor Object | ||
699 | * | ||
700 | * An instance of a subclass of the following object defines a cursor | ||
701 | * used to scan through a key-value storage engine. | ||
702 | */ | ||
703 | typedef struct unqlite_kv_cursor unqlite_kv_cursor; | ||
704 | struct unqlite_kv_cursor | ||
705 | { | ||
706 | unqlite_kv_engine *pStore; /* Must be first */ | ||
707 | /* Subclasses will typically add additional fields */ | ||
708 | }; | ||
709 | /* | ||
710 | * Possible seek positions. | ||
711 | */ | ||
712 | #define UNQLITE_CURSOR_MATCH_EXACT 1 | ||
713 | #define UNQLITE_CURSOR_MATCH_LE 2 | ||
714 | #define UNQLITE_CURSOR_MATCH_GE 3 | ||
715 | /* | ||
716 | * Key/Value Storage Engine. | ||
717 | * | ||
718 | * A Key-Value storage engine is defined by an instance of the following | ||
719 | * object. | ||
720 | * UnQLite works with run-time interchangeable storage engines (i.e. Hash, B+Tree, R+Tree, LSM, etc.). | ||
721 | * The storage engine works with key/value pairs where both the key | ||
722 | * and the value are byte arrays of arbitrary length and with no restrictions on content. | ||
723 | * UnQLite come with two built-in KV storage engine: A Virtual Linear Hash (VLH) storage | ||
724 | * engine is used for persistent on-disk databases with O(1) lookup time and an in-memory | ||
725 | * hash-table or Red-black tree storage engine is used for in-memory databases. | ||
726 | * Future versions of UnQLite might add other built-in storage engines (i.e. LSM). | ||
727 | * Registration of a Key/Value storage engine at run-time is done via [unqlite_lib_config()] | ||
728 | * with a configuration verb set to UNQLITE_LIB_CONFIG_STORAGE_ENGINE. | ||
729 | */ | ||
730 | struct unqlite_kv_engine | ||
731 | { | ||
732 | const unqlite_kv_io *pIo; /* IO methods: MUST be first */ | ||
733 | /* Subclasses will typically add additional fields */ | ||
734 | }; | ||
735 | /* | ||
736 | * Key/Value Storage Engine Virtual Method Table. | ||
737 | * | ||
738 | * Key/Value storage engine methods is defined by an instance of the following | ||
739 | * object. | ||
740 | * Registration of a Key/Value storage engine at run-time is done via [unqlite_lib_config()] | ||
741 | * with a configuration verb set to UNQLITE_LIB_CONFIG_STORAGE_ENGINE. | ||
742 | */ | ||
743 | struct unqlite_kv_methods | ||
744 | { | ||
745 | const char *zName; /* Storage engine name [i.e. Hash, B+tree, LSM, R-tree, Mem, etc.]*/ | ||
746 | int szKv; /* 'unqlite_kv_engine' subclass size */ | ||
747 | int szCursor; /* 'unqlite_kv_cursor' subclass size */ | ||
748 | int iVersion; /* Structure version, currently 1 */ | ||
749 | /* Storage engine methods */ | ||
750 | int (*xInit)(unqlite_kv_engine *,int iPageSize); | ||
751 | void (*xRelease)(unqlite_kv_engine *); | ||
752 | int (*xConfig)(unqlite_kv_engine *,int op,va_list ap); | ||
753 | int (*xOpen)(unqlite_kv_engine *,pgno); | ||
754 | int (*xReplace)( | ||
755 | unqlite_kv_engine *, | ||
756 | const void *pKey,int nKeyLen, | ||
757 | const void *pData,unqlite_int64 nDataLen | ||
758 | ); | ||
759 | int (*xAppend)( | ||
760 | unqlite_kv_engine *, | ||
761 | const void *pKey,int nKeyLen, | ||
762 | const void *pData,unqlite_int64 nDataLen | ||
763 | ); | ||
764 | void (*xCursorInit)(unqlite_kv_cursor *); | ||
765 | int (*xSeek)(unqlite_kv_cursor *,const void *pKey,int nByte,int iPos); /* Mandatory */ | ||
766 | int (*xFirst)(unqlite_kv_cursor *); | ||
767 | int (*xLast)(unqlite_kv_cursor *); | ||
768 | int (*xValid)(unqlite_kv_cursor *); | ||
769 | int (*xNext)(unqlite_kv_cursor *); | ||
770 | int (*xPrev)(unqlite_kv_cursor *); | ||
771 | int (*xDelete)(unqlite_kv_cursor *); | ||
772 | int (*xKeyLength)(unqlite_kv_cursor *,int *); | ||
773 | int (*xKey)(unqlite_kv_cursor *,int (*xConsumer)(const void *,unsigned int,void *),void *pUserData); | ||
774 | int (*xDataLength)(unqlite_kv_cursor *,unqlite_int64 *); | ||
775 | int (*xData)(unqlite_kv_cursor *,int (*xConsumer)(const void *,unsigned int,void *),void *pUserData); | ||
776 | void (*xReset)(unqlite_kv_cursor *); | ||
777 | void (*xCursorRelease)(unqlite_kv_cursor *); | ||
778 | }; | ||
779 | /* | ||
780 | * UnQLite journal file suffix. | ||
781 | */ | ||
782 | #ifndef UNQLITE_JOURNAL_FILE_SUFFIX | ||
783 | #define UNQLITE_JOURNAL_FILE_SUFFIX "_unqlite_journal" | ||
784 | #endif | ||
785 | /* | ||
786 | * Call Context - Error Message Serverity Level. | ||
787 | * | ||
788 | * The following constans are the allowed severity level that can | ||
789 | * passed as the second argument to the [unqlite_context_throw_error()] or | ||
790 | * [unqlite_context_throw_error_format()] interfaces. | ||
791 | * Refer to the official documentation for additional information. | ||
792 | */ | ||
793 | #define UNQLITE_CTX_ERR 1 /* Call context error such as unexpected number of arguments, invalid types and so on. */ | ||
794 | #define UNQLITE_CTX_WARNING 2 /* Call context Warning */ | ||
795 | #define UNQLITE_CTX_NOTICE 3 /* Call context Notice */ | ||
796 | /* | ||
797 | * C-API-REF: Please refer to the official documentation for interfaces | ||
798 | * purpose and expected parameters. | ||
799 | */ | ||
800 | |||
801 | /* Database Engine Handle */ | ||
802 | UNQLITE_APIEXPORT int unqlite_open(unqlite **ppDB,const char *zFilename,unsigned int iMode); | ||
803 | UNQLITE_APIEXPORT int unqlite_config(unqlite *pDb,int nOp,...); | ||
804 | UNQLITE_APIEXPORT int unqlite_close(unqlite *pDb); | ||
805 | |||
806 | /* Key/Value (KV) Store Interfaces */ | ||
807 | UNQLITE_APIEXPORT int unqlite_kv_store(unqlite *pDb,const void *pKey,int nKeyLen,const void *pData,unqlite_int64 nDataLen); | ||
808 | UNQLITE_APIEXPORT int unqlite_kv_append(unqlite *pDb,const void *pKey,int nKeyLen,const void *pData,unqlite_int64 nDataLen); | ||
809 | UNQLITE_APIEXPORT int unqlite_kv_store_fmt(unqlite *pDb,const void *pKey,int nKeyLen,const char *zFormat,...); | ||
810 | UNQLITE_APIEXPORT int unqlite_kv_append_fmt(unqlite *pDb,const void *pKey,int nKeyLen,const char *zFormat,...); | ||
811 | UNQLITE_APIEXPORT int unqlite_kv_fetch(unqlite *pDb,const void *pKey,int nKeyLen,void *pBuf,unqlite_int64 /* in|out */*pBufLen); | ||
812 | UNQLITE_APIEXPORT int unqlite_kv_fetch_callback(unqlite *pDb,const void *pKey, | ||
813 | int nKeyLen,int (*xConsumer)(const void *,unsigned int,void *),void *pUserData); | ||
814 | UNQLITE_APIEXPORT int unqlite_kv_delete(unqlite *pDb,const void *pKey,int nKeyLen); | ||
815 | UNQLITE_APIEXPORT int unqlite_kv_config(unqlite *pDb,int iOp,...); | ||
816 | |||
817 | /* Document (JSON) Store Interfaces powered by the Jx9 Scripting Language */ | ||
818 | UNQLITE_APIEXPORT int unqlite_compile(unqlite *pDb,const char *zJx9,int nByte,unqlite_vm **ppOut); | ||
819 | UNQLITE_APIEXPORT int unqlite_compile_file(unqlite *pDb,const char *zPath,unqlite_vm **ppOut); | ||
820 | UNQLITE_APIEXPORT int unqlite_vm_config(unqlite_vm *pVm,int iOp,...); | ||
821 | UNQLITE_APIEXPORT int unqlite_vm_exec(unqlite_vm *pVm); | ||
822 | UNQLITE_APIEXPORT int unqlite_vm_reset(unqlite_vm *pVm); | ||
823 | UNQLITE_APIEXPORT int unqlite_vm_release(unqlite_vm *pVm); | ||
824 | UNQLITE_APIEXPORT int unqlite_vm_dump(unqlite_vm *pVm, int (*xConsumer)(const void *, unsigned int, void *), void *pUserData); | ||
825 | UNQLITE_APIEXPORT unqlite_value * unqlite_vm_extract_variable(unqlite_vm *pVm,const char *zVarname); | ||
826 | |||
827 | /* Cursor Iterator Interfaces */ | ||
828 | UNQLITE_APIEXPORT int unqlite_kv_cursor_init(unqlite *pDb,unqlite_kv_cursor **ppOut); | ||
829 | UNQLITE_APIEXPORT int unqlite_kv_cursor_release(unqlite *pDb,unqlite_kv_cursor *pCur); | ||
830 | UNQLITE_APIEXPORT int unqlite_kv_cursor_seek(unqlite_kv_cursor *pCursor,const void *pKey,int nKeyLen,int iPos); | ||
831 | UNQLITE_APIEXPORT int unqlite_kv_cursor_first_entry(unqlite_kv_cursor *pCursor); | ||
832 | UNQLITE_APIEXPORT int unqlite_kv_cursor_last_entry(unqlite_kv_cursor *pCursor); | ||
833 | UNQLITE_APIEXPORT int unqlite_kv_cursor_valid_entry(unqlite_kv_cursor *pCursor); | ||
834 | UNQLITE_APIEXPORT int unqlite_kv_cursor_next_entry(unqlite_kv_cursor *pCursor); | ||
835 | UNQLITE_APIEXPORT int unqlite_kv_cursor_prev_entry(unqlite_kv_cursor *pCursor); | ||
836 | UNQLITE_APIEXPORT int unqlite_kv_cursor_key(unqlite_kv_cursor *pCursor,void *pBuf,int *pnByte); | ||
837 | UNQLITE_APIEXPORT int unqlite_kv_cursor_key_callback(unqlite_kv_cursor *pCursor,int (*xConsumer)(const void *,unsigned int,void *),void *pUserData); | ||
838 | UNQLITE_APIEXPORT int unqlite_kv_cursor_data(unqlite_kv_cursor *pCursor,void *pBuf,unqlite_int64 *pnData); | ||
839 | UNQLITE_APIEXPORT int unqlite_kv_cursor_data_callback(unqlite_kv_cursor *pCursor,int (*xConsumer)(const void *,unsigned int,void *),void *pUserData); | ||
840 | UNQLITE_APIEXPORT int unqlite_kv_cursor_delete_entry(unqlite_kv_cursor *pCursor); | ||
841 | UNQLITE_APIEXPORT int unqlite_kv_cursor_reset(unqlite_kv_cursor *pCursor); | ||
842 | |||
843 | /* Manual Transaction Manager */ | ||
844 | UNQLITE_APIEXPORT int unqlite_begin(unqlite *pDb); | ||
845 | UNQLITE_APIEXPORT int unqlite_commit(unqlite *pDb); | ||
846 | UNQLITE_APIEXPORT int unqlite_rollback(unqlite *pDb); | ||
847 | |||
848 | /* Utility interfaces */ | ||
849 | UNQLITE_APIEXPORT int unqlite_util_load_mmaped_file(const char *zFile,void **ppMap,unqlite_int64 *pFileSize); | ||
850 | UNQLITE_APIEXPORT int unqlite_util_release_mmaped_file(void *pMap,unqlite_int64 iFileSize); | ||
851 | UNQLITE_APIEXPORT int unqlite_util_random_string(unqlite *pDb,char *zBuf,unsigned int buf_size); | ||
852 | UNQLITE_APIEXPORT unsigned int unqlite_util_random_num(unqlite *pDb); | ||
853 | |||
854 | /* In-process extending interfaces */ | ||
855 | UNQLITE_APIEXPORT int unqlite_create_function(unqlite_vm *pVm,const char *zName,int (*xFunc)(unqlite_context *,int,unqlite_value **),void *pUserData); | ||
856 | UNQLITE_APIEXPORT int unqlite_delete_function(unqlite_vm *pVm, const char *zName); | ||
857 | UNQLITE_APIEXPORT int unqlite_create_constant(unqlite_vm *pVm,const char *zName,void (*xExpand)(unqlite_value *, void *),void *pUserData); | ||
858 | UNQLITE_APIEXPORT int unqlite_delete_constant(unqlite_vm *pVm, const char *zName); | ||
859 | |||
860 | /* On Demand Object allocation interfaces */ | ||
861 | UNQLITE_APIEXPORT unqlite_value * unqlite_vm_new_scalar(unqlite_vm *pVm); | ||
862 | UNQLITE_APIEXPORT unqlite_value * unqlite_vm_new_array(unqlite_vm *pVm); | ||
863 | UNQLITE_APIEXPORT int unqlite_vm_release_value(unqlite_vm *pVm,unqlite_value *pValue); | ||
864 | UNQLITE_APIEXPORT unqlite_value * unqlite_context_new_scalar(unqlite_context *pCtx); | ||
865 | UNQLITE_APIEXPORT unqlite_value * unqlite_context_new_array(unqlite_context *pCtx); | ||
866 | UNQLITE_APIEXPORT void unqlite_context_release_value(unqlite_context *pCtx,unqlite_value *pValue); | ||
867 | |||
868 | /* Dynamically Typed Value Object Management Interfaces */ | ||
869 | UNQLITE_APIEXPORT int unqlite_value_int(unqlite_value *pVal, int iValue); | ||
870 | UNQLITE_APIEXPORT int unqlite_value_int64(unqlite_value *pVal, unqlite_int64 iValue); | ||
871 | UNQLITE_APIEXPORT int unqlite_value_bool(unqlite_value *pVal, int iBool); | ||
872 | UNQLITE_APIEXPORT int unqlite_value_null(unqlite_value *pVal); | ||
873 | UNQLITE_APIEXPORT int unqlite_value_double(unqlite_value *pVal, double Value); | ||
874 | UNQLITE_APIEXPORT int unqlite_value_string(unqlite_value *pVal, const char *zString, int nLen); | ||
875 | UNQLITE_APIEXPORT int unqlite_value_string_format(unqlite_value *pVal, const char *zFormat,...); | ||
876 | UNQLITE_APIEXPORT int unqlite_value_reset_string_cursor(unqlite_value *pVal); | ||
877 | UNQLITE_APIEXPORT int unqlite_value_resource(unqlite_value *pVal, void *pUserData); | ||
878 | UNQLITE_APIEXPORT int unqlite_value_release(unqlite_value *pVal); | ||
879 | |||
880 | /* Foreign Function Parameter Values */ | ||
881 | UNQLITE_APIEXPORT int unqlite_value_to_int(unqlite_value *pValue); | ||
882 | UNQLITE_APIEXPORT int unqlite_value_to_bool(unqlite_value *pValue); | ||
883 | UNQLITE_APIEXPORT unqlite_int64 unqlite_value_to_int64(unqlite_value *pValue); | ||
884 | UNQLITE_APIEXPORT double unqlite_value_to_double(unqlite_value *pValue); | ||
885 | UNQLITE_APIEXPORT const char * unqlite_value_to_string(unqlite_value *pValue, int *pLen); | ||
886 | UNQLITE_APIEXPORT void * unqlite_value_to_resource(unqlite_value *pValue); | ||
887 | UNQLITE_APIEXPORT int unqlite_value_compare(unqlite_value *pLeft, unqlite_value *pRight, int bStrict); | ||
888 | |||
889 | /* Setting The Result Of A Foreign Function */ | ||
890 | UNQLITE_APIEXPORT int unqlite_result_int(unqlite_context *pCtx, int iValue); | ||
891 | UNQLITE_APIEXPORT int unqlite_result_int64(unqlite_context *pCtx, unqlite_int64 iValue); | ||
892 | UNQLITE_APIEXPORT int unqlite_result_bool(unqlite_context *pCtx, int iBool); | ||
893 | UNQLITE_APIEXPORT int unqlite_result_double(unqlite_context *pCtx, double Value); | ||
894 | UNQLITE_APIEXPORT int unqlite_result_null(unqlite_context *pCtx); | ||
895 | UNQLITE_APIEXPORT int unqlite_result_string(unqlite_context *pCtx, const char *zString, int nLen); | ||
896 | UNQLITE_APIEXPORT int unqlite_result_string_format(unqlite_context *pCtx, const char *zFormat, ...); | ||
897 | UNQLITE_APIEXPORT int unqlite_result_value(unqlite_context *pCtx, unqlite_value *pValue); | ||
898 | UNQLITE_APIEXPORT int unqlite_result_resource(unqlite_context *pCtx, void *pUserData); | ||
899 | |||
900 | /* Dynamically Typed Value Object Query Interfaces */ | ||
901 | UNQLITE_APIEXPORT int unqlite_value_is_int(unqlite_value *pVal); | ||
902 | UNQLITE_APIEXPORT int unqlite_value_is_float(unqlite_value *pVal); | ||
903 | UNQLITE_APIEXPORT int unqlite_value_is_bool(unqlite_value *pVal); | ||
904 | UNQLITE_APIEXPORT int unqlite_value_is_string(unqlite_value *pVal); | ||
905 | UNQLITE_APIEXPORT int unqlite_value_is_null(unqlite_value *pVal); | ||
906 | UNQLITE_APIEXPORT int unqlite_value_is_numeric(unqlite_value *pVal); | ||
907 | UNQLITE_APIEXPORT int unqlite_value_is_callable(unqlite_value *pVal); | ||
908 | UNQLITE_APIEXPORT int unqlite_value_is_scalar(unqlite_value *pVal); | ||
909 | UNQLITE_APIEXPORT int unqlite_value_is_json_array(unqlite_value *pVal); | ||
910 | UNQLITE_APIEXPORT int unqlite_value_is_json_object(unqlite_value *pVal); | ||
911 | UNQLITE_APIEXPORT int unqlite_value_is_resource(unqlite_value *pVal); | ||
912 | UNQLITE_APIEXPORT int unqlite_value_is_empty(unqlite_value *pVal); | ||
913 | |||
914 | /* JSON Array/Object Management Interfaces */ | ||
915 | UNQLITE_APIEXPORT unqlite_value * unqlite_array_fetch(unqlite_value *pArray, const char *zKey, int nByte); | ||
916 | UNQLITE_APIEXPORT int unqlite_array_walk(unqlite_value *pArray, int (*xWalk)(unqlite_value *, unqlite_value *, void *), void *pUserData); | ||
917 | UNQLITE_APIEXPORT int unqlite_array_add_elem(unqlite_value *pArray, unqlite_value *pKey, unqlite_value *pValue); | ||
918 | UNQLITE_APIEXPORT int unqlite_array_add_strkey_elem(unqlite_value *pArray, const char *zKey, unqlite_value *pValue); | ||
919 | UNQLITE_APIEXPORT int unqlite_array_count(unqlite_value *pArray); | ||
920 | |||
921 | /* Call Context Handling Interfaces */ | ||
922 | UNQLITE_APIEXPORT int unqlite_context_output(unqlite_context *pCtx, const char *zString, int nLen); | ||
923 | UNQLITE_APIEXPORT int unqlite_context_output_format(unqlite_context *pCtx,const char *zFormat, ...); | ||
924 | UNQLITE_APIEXPORT int unqlite_context_throw_error(unqlite_context *pCtx, int iErr, const char *zErr); | ||
925 | UNQLITE_APIEXPORT int unqlite_context_throw_error_format(unqlite_context *pCtx, int iErr, const char *zFormat, ...); | ||
926 | UNQLITE_APIEXPORT unsigned int unqlite_context_random_num(unqlite_context *pCtx); | ||
927 | UNQLITE_APIEXPORT int unqlite_context_random_string(unqlite_context *pCtx, char *zBuf, int nBuflen); | ||
928 | UNQLITE_APIEXPORT void * unqlite_context_user_data(unqlite_context *pCtx); | ||
929 | UNQLITE_APIEXPORT int unqlite_context_push_aux_data(unqlite_context *pCtx, void *pUserData); | ||
930 | UNQLITE_APIEXPORT void * unqlite_context_peek_aux_data(unqlite_context *pCtx); | ||
931 | UNQLITE_APIEXPORT unsigned int unqlite_context_result_buf_length(unqlite_context *pCtx); | ||
932 | UNQLITE_APIEXPORT const char * unqlite_function_name(unqlite_context *pCtx); | ||
933 | |||
934 | /* Call Context Memory Management Interfaces */ | ||
935 | UNQLITE_APIEXPORT void * unqlite_context_alloc_chunk(unqlite_context *pCtx,unsigned int nByte,int ZeroChunk,int AutoRelease); | ||
936 | UNQLITE_APIEXPORT void * unqlite_context_realloc_chunk(unqlite_context *pCtx,void *pChunk,unsigned int nByte); | ||
937 | UNQLITE_APIEXPORT void unqlite_context_free_chunk(unqlite_context *pCtx,void *pChunk); | ||
938 | |||
939 | /* Global Library Management Interfaces */ | ||
940 | UNQLITE_APIEXPORT int unqlite_lib_config(int nConfigOp,...); | ||
941 | UNQLITE_APIEXPORT int unqlite_lib_init(void); | ||
942 | UNQLITE_APIEXPORT int unqlite_lib_shutdown(void); | ||
943 | UNQLITE_APIEXPORT int unqlite_lib_is_threadsafe(void); | ||
944 | UNQLITE_APIEXPORT const char * unqlite_lib_version(void); | ||
945 | UNQLITE_APIEXPORT const char * unqlite_lib_signature(void); | ||
946 | UNQLITE_APIEXPORT const char * unqlite_lib_ident(void); | ||
947 | UNQLITE_APIEXPORT const char * unqlite_lib_copyright(void); | ||
948 | |||
949 | #endif /* _UNQLITE_H_ */ | ||