-
Notifications
You must be signed in to change notification settings - Fork 16
/
omp_database.inc
431 lines (385 loc) · 20.4 KB
/
omp_database.inc
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
#if defined _INC_omp_database
#endinput
#endif
#define _INC_omp_database
/**
* <library name="omp_database" summary="open.mp SQLite functions.">
* <license>
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at http://mozilla.org/MPL/2.0/.
*
* The original code is copyright (c) 2023, open.mp team and contributors.
* </license>
* <summary pawndoc="true">
* This library uses the enhanced <em>pawndoc.xsl</em> from
* <a href="https://github.com/pawn-lang/pawndoc">pawn-lang/pawndoc</a>.
* This XSL has features such as library and markdown support, and will not
* render this message when used.
* </summary>
* </library>
*/
/// <p/>
#pragma tabsize 4
/// <p/>
/**
* <library>omp_database</library>
*/
enum SQLITE_OPEN:__SQLITE_OPEN
{
UNKNOWN_SQLITE_OPEN = -1,
SQLITE_OPEN_READONLY = 0x00000001,
SQLITE_OPEN_READWRITE = 0x00000002,
SQLITE_OPEN_CREATE = 0x00000004,
SQLITE_OPEN_DELETEONCLOSE = 0x00000008, // Requires VFS.
SQLITE_OPEN_EXCLUSIVE = 0x00000010, // Requires VFS.
SQLITE_OPEN_AUTOPROXY = 0x00000020, // Requires VFS.
SQLITE_OPEN_URI = 0x00000040,
SQLITE_OPEN_MEMORY = 0x00000080,
SQLITE_OPEN_MAIN_DB = 0x00000100, // Requires VFS.
SQLITE_OPEN_TEMP_DB = 0x00000200, // Requires VFS.
SQLITE_OPEN_TRANSIENT_DB = 0x00000400, // Requires VFS.
SQLITE_OPEN_MAIN_JOURNAL = 0x00000800, // Requires VFS.
SQLITE_OPEN_TEMP_JOURNAL = 0x00001000, // Requires VFS.
SQLITE_OPEN_SUBJOURNAL = 0x00002000, // Requires VFS.
SQLITE_OPEN_SUPER_JOURNAL = 0x00004000, // Requires VFS.
SQLITE_OPEN_NOMUTEX = 0x00008000,
SQLITE_OPEN_FULLMUTEX = 0x00010000,
SQLITE_OPEN_SHAREDCACHE = 0x00020000,
SQLITE_OPEN_PRIVATECACHE = 0x00040000,
SQLITE_OPEN_WAL = 0x00080000, // Requires VFS.
SQLITE_OPEN_NOFOLLOW = 0x01000000,
SQLITE_OPEN_EXRESCODE = 0x02000000
}
static stock SQLITE_OPEN:_@SQLITE_OPEN() { return __SQLITE_OPEN; }
#define UNKNOWN_SQLITE_OPEN (SQLITE_OPEN:-1)
#define SQLITE_OPEN_READONLY (SQLITE_OPEN:0x00000001)
#define SQLITE_OPEN_READWRITE (SQLITE_OPEN:0x00000002)
#define SQLITE_OPEN_CREATE (SQLITE_OPEN:0x00000004)
#define SQLITE_OPEN_DELETEONCLOSE (SQLITE_OPEN:0x00000008) // Requires VFS.
#define SQLITE_OPEN_EXCLUSIVE (SQLITE_OPEN:0x00000010) // Requires VFS.
#define SQLITE_OPEN_AUTOPROXY (SQLITE_OPEN:0x00000020) // Requires VFS.
#define SQLITE_OPEN_URI (SQLITE_OPEN:0x00000040)
#define SQLITE_OPEN_MEMORY (SQLITE_OPEN:0x00000080)
#define SQLITE_OPEN_MAIN_DB (SQLITE_OPEN:0x00000100) // Requires VFS.
#define SQLITE_OPEN_TEMP_DB (SQLITE_OPEN:0x00000200) // Requires VFS.
#define SQLITE_OPEN_TRANSIENT_DB (SQLITE_OPEN:0x00000400) // Requires VFS.
#define SQLITE_OPEN_MAIN_JOURNAL (SQLITE_OPEN:0x00000800) // Requires VFS.
#define SQLITE_OPEN_TEMP_JOURNAL (SQLITE_OPEN:0x00001000) // Requires VFS.
#define SQLITE_OPEN_SUBJOURNAL (SQLITE_OPEN:0x00002000) // Requires VFS.
#define SQLITE_OPEN_SUPER_JOURNAL (SQLITE_OPEN:0x00004000) // Requires VFS.
#define SQLITE_OPEN_NOMUTEX (SQLITE_OPEN:0x00008000)
#define SQLITE_OPEN_FULLMUTEX (SQLITE_OPEN:0x00010000)
#define SQLITE_OPEN_SHAREDCACHE (SQLITE_OPEN:0x00020000)
#define SQLITE_OPEN_PRIVATECACHE (SQLITE_OPEN:0x00040000)
#define SQLITE_OPEN_WAL (SQLITE_OPEN:0x00080000) // Requires VFS.
#define SQLITE_OPEN_NOFOLLOW (SQLITE_OPEN:0x01000000)
#define SQLITE_OPEN_EXRESCODE (SQLITE_OPEN:0x02000000)
/*
888b 88 88
8888b 88 ,d ""
88 `8b 88 88
88 `8b 88 ,adPPYYba, MM88MMM 88 8b d8 ,adPPYba, ,adPPYba,
88 `8b 88 "" `Y8 88 88 `8b d8' a8P_____88 I8[ ""
88 `8b 88 ,adPPPPP88 88 88 `8b d8' 8PP""""""" `"Y8ba,
88 `8888 88, ,88 88, 88 `8b,d8' "8b, ,aa aa ]8I
88 `888 `"8bbdP"Y8 "Y888 88 "8" `"Ybbd8"' `"YbbdP"'
*/
/**
* <library>omp_database</library>
* <summary>This function is used to open a connection to a SQLite database, which is inside the <b><c>/scriptfiles</c></b>
* folder.</summary>
* <param name="name">File name of the database</param>
* <remarks>
* It will create a new SQLite database, if there is no SQLite database with the same file name available.<br
* />
* <b>Close</b> your database connection with <a href="#db_close">db_close</a>!
* </remarks>
* <returns>Returns index (starting at <b><c>1</c></b>) of the database connection .</returns>
*/
native DB:DB_Open(const name[], SQLITE_OPEN:flags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE);
/**
* <library>omp_database</library>
* <summary>Closes an SQLite database that was opened with <a href="#db_open">db_open</a>.</summary>
* <param name="db">The handle of the database connection to close (returned by <a href="#db_open">db_open</a>)</param>
* <remarks>Using an <b>invalid handle</b> will crash your server! Get a <b>valid handle</b> by using
* <a href="#db_open">db_open</a>. But it's protected against <b><c>NULL</c></b> references</remarks>
* <returns>
* <b><c>1</c></b>: The function executed successfully.<br />
* <b><c>0</c></b>: The function failed to execute. May mean that the database handle specified is
* not open.
* </returns>
*/
native bool:DB_Close(DB:db);
/**
* <library>omp_database</library>
* <summary>This function is used to execute an SQL query on an opened SQLite database.</summary>
* <param name="db">The database handle to query</param>
* <param name="query">The query to execute. May be optionally formatted.</param>
* <remarks><b>Always</b> free the result by using <a href="#db_free_result">db_free_result</a>!</remarks>
* <returns>The query result index (<b>starting at 1</b>).</returns>
*/
native DBResult:DB_ExecuteQuery(DB:db, const query[], OPEN_MP_TAGS:...);
/**
* <library>omp_database</library>
* <summary>Frees result memory allocated from <a href="#db_query">db_query</a>.</summary>
* <param name="result">The result to free</param>
* <returns>If <b><c>DBResult:dbhandle</c></b> is a valid handle, it returns <b><c>1</c></b>, otherwise
* <b><c>0</c></b> if <b><c>DBResult:dbhandle</c></b> is a <b><c>NULL</c></b> reference.</returns>
*/
native bool:DB_FreeResultSet(DBResult:result);
/**
* <library>omp_database</library>
* <summary>Returns the number of rows from a <a href="#db_query">db_query</a>.</summary>
* <param name="result">The result of <a href="#db_query">db_query</a></param>
* <remarks>Using an <b>invalid handle</b> will crash your server! Get a <b>valid handle</b> by using
* <a href="#db_open">db_open</a>. But it's protected against <b><c>NULL</c></b> references</remarks>
* <returns>The number of rows in the result.</returns>
*/
native DB_GetRowCount(DBResult:result);
/**
* <library>omp_database</library>
* <summary>Moves to the next row of the result allocated from <a href="#db_query">db_query</a>.</summary>
* <param name="result">The result of <a href="#db_query">db_query</a></param>
* <remarks>Using an <b>invalid handle</b> will crash your server! Get a <b>valid handle</b> by using
* <a href="#db_open">db_open</a>. But it's protected against <b><c>NULL</c></b> references</remarks>
* <returns>Returns <b><c>1</c></b> on success, otherwise <b><c>0</c></b> if <b><c>DBResult:result</c></b>
* is a <b><c>NULL</c></b> reference or the last row is reached.</returns>
*/
native bool:DB_SelectNextRow(DBResult:result);
/**
* <library>omp_database</library>
* <summary>Get the number of fields in a result.</summary>
* <param name="result">The result of <a href="#db_query">db_query</a></param>
* <remarks>Using an <b>invalid handle</b> will crash your server! Get a <b>valid handle</b> by using
* <a href="#db_open">db_open</a>. But it's protected against <b><c>NULL</c></b> references</remarks>
* <returns>The number of fields in the result.</returns>
*/
native DB_GetFieldCount(DBResult:result);
/**
* <library>omp_database</library>
* <summary>Returns the name of a field at a particular index.</summary>
* <param name="result">The result to get the data from; returned by <a href="#db_query">db_query</a></param>
* <param name="field">The index of the field to get the name of</param>
* <param name="output">The returned value</param>
* <param name="size">The max length of the field</param>
* <remarks>Using an <b>invalid handle</b> will crash your server! Get a <b>valid handle</b> by using
* <a href="#db_open">db_open</a>. But it's protected against <b><c>NULL</c></b> references</remarks>
* <returns>Returns <b><c>1</c></b>, if the function was successful, otherwise <b><c>0</c></b> if <b><c>DBResult:result</c></b>
* is a <b><c>NULL</c></b> reference or the column index not available.</returns>
*/
native bool:DB_GetFieldName(DBResult:result, field, output[], size = sizeof (output));
/**
* <library>omp_database</library>
* <summary>Get the content of a field from <a href="#db_query">db_query</a>.</summary>
* <param name="result">The result to get the data from</param>
* <param name="field">The field to get the data from</param>
* <param name="output">The returned value</param>
* <param name="size">The max length of the field</param>
* <remarks>Using an <b>invalid handle</b> will crash your server! Get a <b>valid handle</b> by using
* <a href="#db_open">db_open</a>. But it's protected against <b><c>NULL</c></b> references</remarks>
* <returns>Returns <b><c>1</c></b> if successful, otherwise <b><c>0</c></b> if <b><c>DBResult:result</c></b>
* is a <b><c>NULL</c></b> reference or the column index not available.</returns>
*/
native bool:DB_GetFieldString(DBResult:result, field, output[], size = sizeof (output));
/**
* <library>omp_database</library>
* <summary>Get the content of a field as an integer from <a href="#db_query">db_query</a>.</summary>
* <param name="result">The result to get the data from</param>
* <param name="field">The field to get the data from (optional=<b><c>0</c></b>)</param>
* <remarks>Using an <b>invalid handle</b> will crash your server! Get a <b>valid handle</b> by using
* <a href="#db_open">db_open</a>. But it's protected against <b><c>NULL</c></b> references</remarks>
* <returns>Retrieved value as integer (number).</returns>
*/
native DB_GetFieldInt(DBResult:result, field = 0);
/**
* <library>omp_database</library>
* <summary>Get the content of a field as a float from db_query.</summary>
* <param name="result">The result to get the data from</param>
* <param name="field">The field to get the data from (optional=<b><c>0</c></b>)</param>
* <remarks>Using an <b>invalid handle</b> will crash your server! Get a <b>valid handle</b> by using
* <a href="#db_open">db_open</a>. But it's protected against <b><c>NULL</c></b> references</remarks>
* <returns>Retrieved value as floating point number.</returns>
*/
native Float:DB_GetFieldFloat(DBResult:result, field = 0);
/**
* <library>omp_database</library>
* <summary>Get the contents of field with specified name.</summary>
* <param name="result">The result to get the data from</param>
* <param name="field">The fieldname to get the data from</param>
* <param name="output">The returned value</param>
* <param name="size">The max length of the field</param>
* <remarks>Using an <b>invalid handle</b> will crash your server! Get a <b>valid handle</b> by using
* <a href="#db_open">db_open</a>. But it's protected against <b><c>NULL</c></b> references</remarks>
* <returns>Returns <b><c>1</c></b> if successful, otherwise <b><c>0</c></b> if <b><c>DBResult:result</c></b>
* is a <b><c>NULL</c></b> reference or the column index not available.</returns>
*/
native bool:DB_GetFieldStringByName(DBResult:result, const field[], output[], size = sizeof (output));
/**
* <library>omp_database</library>
* <summary>Get the contents of field as an integer with specified name.</summary>
* <param name="result">The result to get the data from</param>
* <param name="field">The fieldname to get the data from</param>
* <remarks>Using an <b>invalid handle</b> will crash your server! Get a <b>valid handle</b> by using
* <a href="#db_open">db_open</a>. But it's protected against <b><c>NULL</c></b> references</remarks>
* <returns>Retrieved value as integer (number).</returns>
*/
native DB_GetFieldIntByName(DBResult:result, const field[]);
/**
* <library>omp_database</library>
* <summary>Get the contents of field as a float with specified name.</summary>
* <param name="result">The result to get the data from</param>
* <param name="field">The fieldname to get the data from</param>
* <remarks>Using an <b>invalid handle</b> will crash your server! Get a <b>valid handle</b> by using
* <a href="#db_open">db_open</a>. But it's protected against <b><c>NULL</c></b> references</remarks>
* <returns>Retrieved value as floating point number.</returns>
*/
native Float:DB_GetFieldFloatByName(DBResult:result, const field[]);
/**
* <library>omp_database</library>
* <summary>Get memory handle for an SQLite database that was opened with <a href="#db_open">db_open</a>.</summary>
* <param name="db">The index of the database connection (returned by <a href="#db_open">db_open</a>)</param>
* <returns>Returns the memory handle for a specified database.</returns>
*/
native DB_GetMemHandle(DB:db);
/**
* <library>omp_database</library>
* <summary>Get <b>memory handle</b> for an SQLite query that was executed with <a href="#db_query">db_query</a>.</summary>
* <param name="result">The index of the query (returned by <a href="#db_query">db_query</a>)</param>
* <returns>Returns the memory handle for a specified query.</returns>
*/
native DB_GetLegacyDBResult(DBResult:result);
/**
* <library>omp_database</library>
*/
native DB_GetDatabaseConnectionCount();
/**
* <library>omp_database</library>
*/
native DB_GetDatabaseResultSetCount();
/**
* <library>omp_database</library>
*/
#if !defined LEGACY_SCRIPTING_API
#pragma deprecated Use `DB_Open`. To silence this warning define `LEGACY_SCRIPTING_API` or define `SAMP_COMPAT` for general SA-MP API compatibility.
#endif
native DB:db_open(const name[]) = DB_Open;
/**
* <library>omp_database</library>
*/
#if !defined LEGACY_SCRIPTING_API
#pragma deprecated Use `DB_Close`. To silence this warning define `LEGACY_SCRIPTING_API` or define `SAMP_COMPAT` for general SA-MP API compatibility.
#endif
native bool:db_close(DB:db) = DB_Close;
/**
* <library>omp_database</library>
*/
#if !defined LEGACY_SCRIPTING_API
#pragma deprecated Use `DB_ExecuteQuery`. To silence this warning define `LEGACY_SCRIPTING_API` or define `SAMP_COMPAT` for general SA-MP API compatibility.
#endif
native DBResult:db_query(DB:db, const query[]) = DB_ExecuteQuery;
/**
* <library>omp_database</library>
*/
#if !defined LEGACY_SCRIPTING_API
#pragma deprecated Use `DB_FreeResultSet`. To silence this warning define `LEGACY_SCRIPTING_API` or define `SAMP_COMPAT` for general SA-MP API compatibility.
#endif
native bool:db_free_result(DBResult:result) = DB_FreeResultSet;
/**
* <library>omp_database</library>
*/
#if !defined LEGACY_SCRIPTING_API
#pragma deprecated Use `DB_GetRowCount`. To silence this warning define `LEGACY_SCRIPTING_API` or define `SAMP_COMPAT` for general SA-MP API compatibility.
#endif
native db_num_rows(DBResult:result) = DB_GetRowCount;
/**
* <library>omp_database</library>
*/
#if !defined LEGACY_SCRIPTING_API
#pragma deprecated Use `DB_SelectNextRow`. To silence this warning define `LEGACY_SCRIPTING_API` or define `SAMP_COMPAT` for general SA-MP API compatibility.
#endif
native bool:db_next_row(DBResult:result) = DB_SelectNextRow;
/**
* <library>omp_database</library>
*/
#if !defined LEGACY_SCRIPTING_API
#pragma deprecated Use `DB_GetFieldCount`. To silence this warning define `LEGACY_SCRIPTING_API` or define `SAMP_COMPAT` for general SA-MP API compatibility.
#endif
native db_num_fields(DBResult:result) = DB_GetFieldCount;
/**
* <library>omp_database</library>
*/
#if !defined LEGACY_SCRIPTING_API
#pragma deprecated Use `DB_GetFieldName`. To silence this warning define `LEGACY_SCRIPTING_API` or define `SAMP_COMPAT` for general SA-MP API compatibility.
#endif
native bool:db_field_name(DBResult:result, field, output[], size = sizeof (output)) = DB_GetFieldName;
/**
* <library>omp_database</library>
*/
#if !defined LEGACY_SCRIPTING_API
#pragma deprecated Use `DB_GetFieldString`. To silence this warning define `LEGACY_SCRIPTING_API` or define `SAMP_COMPAT` for general SA-MP API compatibility.
#endif
native bool:db_get_field(DBResult:result, field, output[], size = sizeof (output)) = DB_GetFieldString;
/**
* <library>omp_database</library>
*/
#if !defined LEGACY_SCRIPTING_API
#pragma deprecated Use `DB_GetFieldInt`. To silence this warning define `LEGACY_SCRIPTING_API` or define `SAMP_COMPAT` for general SA-MP API compatibility.
#endif
native db_get_field_int(DBResult:result, field = 0) = DB_GetFieldInt;
/**
* <library>omp_database</library>
*/
#if !defined LEGACY_SCRIPTING_API
#pragma deprecated Use `DB_GetFieldFloat`. To silence this warning define `LEGACY_SCRIPTING_API` or define `SAMP_COMPAT` for general SA-MP API compatibility.
#endif
native Float:db_get_field_float(DBResult:result, field = 0) = DB_GetFieldFloat;
/**
* <library>omp_database</library>
*/
#if !defined LEGACY_SCRIPTING_API
#pragma deprecated Use `DB_GetFieldStringByName`. To silence this warning define `LEGACY_SCRIPTING_API` or define `SAMP_COMPAT` for general SA-MP API compatibility.
#endif
native bool:db_get_field_assoc(DBResult:result, const field[], output[], size = sizeof (output)) = DB_GetFieldStringByName;
/**
* <library>omp_database</library>
*/
#if !defined LEGACY_SCRIPTING_API
#pragma deprecated Use `DB_GetFieldIntByName`. To silence this warning define `LEGACY_SCRIPTING_API` or define `SAMP_COMPAT` for general SA-MP API compatibility.
#endif
native db_get_field_assoc_int(DBResult:result, const field[]) = DB_GetFieldIntByName;
/**
* <library>omp_database</library>
*/
#if !defined LEGACY_SCRIPTING_API
#pragma deprecated Use `DB_GetFieldFloatByName`. To silence this warning define `LEGACY_SCRIPTING_API` or define `SAMP_COMPAT` for general SA-MP API compatibility.
#endif
native Float:db_get_field_assoc_float(DBResult:result, const field[]) = DB_GetFieldFloatByName;
/**
* <library>omp_database</library>
*/
#if !defined LEGACY_SCRIPTING_API
#pragma deprecated Use `DB_GetMemHandle`. To silence this warning define `LEGACY_SCRIPTING_API` or define `SAMP_COMPAT` for general SA-MP API compatibility.
#endif
native db_get_mem_handle(DB:db) = DB_GetMemHandle;
/**
* <library>omp_database</library>
*/
#if !defined LEGACY_SCRIPTING_API
#pragma deprecated Use `DB_GetLegacyDBResult`. To silence this warning define `LEGACY_SCRIPTING_API` or define `SAMP_COMPAT` for general SA-MP API compatibility.
#endif
native db_get_result_mem_handle(DBResult:result) = DB_GetLegacyDBResult;
/**
* <library>omp_database</library>
*/
#if !defined LEGACY_SCRIPTING_API
#pragma deprecated Use `DB_GetDatabaseConnectionCount`. To silence this warning define `LEGACY_SCRIPTING_API` or define `SAMP_COMPAT` for general SA-MP API compatibility.
#endif
native db_debug_openfiles() = DB_GetDatabaseConnectionCount;
/**
* <library>omp_database</library>
*/
#if !defined LEGACY_SCRIPTING_API
#pragma deprecated Use `DB_GetDatabaseResultSetCount`. To silence this warning define `LEGACY_SCRIPTING_API` or define `SAMP_COMPAT` for general SA-MP API compatibility.
#endif
native db_debug_openresults() = DB_GetDatabaseResultSetCount;