@amxts/core 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +162 -0
- package/README.ru.md +162 -0
- package/amxmodx/base/include/amxconst.inc +594 -0
- package/amxmodx/base/include/amxmisc.inc +902 -0
- package/amxmodx/base/include/amxmodx.inc +3447 -0
- package/amxmodx/base/include/amxmodx_version.inc +20 -0
- package/amxmodx/base/include/cellarray.inc +525 -0
- package/amxmodx/base/include/cellstack.inc +166 -0
- package/amxmodx/base/include/celltrie.inc +412 -0
- package/amxmodx/base/include/core.inc +202 -0
- package/amxmodx/base/include/csstats.inc +298 -0
- package/amxmodx/base/include/csstats_const.inc +29 -0
- package/amxmodx/base/include/cstrike.inc +1287 -0
- package/amxmodx/base/include/cstrike_const.inc +521 -0
- package/amxmodx/base/include/csx.inc +259 -0
- package/amxmodx/base/include/cvars.inc +547 -0
- package/amxmodx/base/include/datapack.inc +161 -0
- package/amxmodx/base/include/dbi.inc +154 -0
- package/amxmodx/base/include/dodconst.inc +152 -0
- package/amxmodx/base/include/dodfun.inc +152 -0
- package/amxmodx/base/include/dodstats.inc +69 -0
- package/amxmodx/base/include/dodx.inc +161 -0
- package/amxmodx/base/include/engine.inc +1343 -0
- package/amxmodx/base/include/engine_const.inc +310 -0
- package/amxmodx/base/include/engine_stocks.inc +248 -0
- package/amxmodx/base/include/esf.inc +70 -0
- package/amxmodx/base/include/esf_const.inc +74 -0
- package/amxmodx/base/include/fakemeta.inc +1127 -0
- package/amxmodx/base/include/fakemeta_const.inc +793 -0
- package/amxmodx/base/include/fakemeta_stocks.inc +395 -0
- package/amxmodx/base/include/fakemeta_util.inc +882 -0
- package/amxmodx/base/include/file.inc +666 -0
- package/amxmodx/base/include/float.inc +422 -0
- package/amxmodx/base/include/fun.inc +333 -0
- package/amxmodx/base/include/gameconfig.inc +93 -0
- package/amxmodx/base/include/geoip.inc +264 -0
- package/amxmodx/base/include/ham_const.inc +4352 -0
- package/amxmodx/base/include/hamsandwich.inc +439 -0
- package/amxmodx/base/include/hlsdk_const.inc +808 -0
- package/amxmodx/base/include/json.inc +777 -0
- package/amxmodx/base/include/lang.inc +119 -0
- package/amxmodx/base/include/message_const.inc +1130 -0
- package/amxmodx/base/include/message_stocks.inc +161 -0
- package/amxmodx/base/include/messages.inc +604 -0
- package/amxmodx/base/include/newmenus.inc +387 -0
- package/amxmodx/base/include/ns.inc +754 -0
- package/amxmodx/base/include/ns_const.inc +196 -0
- package/amxmodx/base/include/nvault.inc +154 -0
- package/amxmodx/base/include/regex.inc +348 -0
- package/amxmodx/base/include/sockets.inc +183 -0
- package/amxmodx/base/include/sorting.inc +107 -0
- package/amxmodx/base/include/sqlx.inc +582 -0
- package/amxmodx/base/include/string.inc +786 -0
- package/amxmodx/base/include/string_const.inc +156 -0
- package/amxmodx/base/include/string_stocks.inc +325 -0
- package/amxmodx/base/include/textparse_ini.inc +214 -0
- package/amxmodx/base/include/textparse_smc.inc +261 -0
- package/amxmodx/base/include/tfcconst.inc +84 -0
- package/amxmodx/base/include/tfcstats.inc +62 -0
- package/amxmodx/base/include/tfcx.inc +148 -0
- package/amxmodx/base/include/time.inc +118 -0
- package/amxmodx/base/include/tsconst.inc +154 -0
- package/amxmodx/base/include/tsfun.inc +198 -0
- package/amxmodx/base/include/tsstats.inc +65 -0
- package/amxmodx/base/include/tsx.inc +88 -0
- package/amxmodx/base/include/vault.inc +60 -0
- package/amxmodx/base/include/vector.inc +131 -0
- package/amxmodx/base/include/xs.inc +1570 -0
- package/as/amxts.d.ts +153 -0
- package/as/constants.ts +4730 -0
- package/as/effects.ts +1449 -0
- package/as/entities.ts +5482 -0
- package/as/events.ts +3054 -0
- package/as/facade.ts +4639 -0
- package/as/flags.ts +299 -0
- package/as/fs.ts +287 -0
- package/as/hooks.ts +18536 -0
- package/as/kit.ts +25 -0
- package/as/lib/check.ts +86 -0
- package/as/modules/http.ts +184 -0
- package/as/natives.ts +11845 -0
- package/as/os.ts +30 -0
- package/as/promise.ts +1392 -0
- package/as/promise.types.d.ts +82 -0
- package/as/remote.ts +288 -0
- package/as/tsconfig.json +22 -0
- package/as/vector.ts +65 -0
- package/bin/amxts.mjs +10 -0
- package/includes/menu_core.inc +355 -0
- package/includes/order.txt +54 -0
- package/includes/sources.json +27 -0
- package/includes/universal_config.inc +355 -0
- package/lint/oxlint-plugin.mjs +77 -0
- package/node_modules/assemblyscript/LICENSE +201 -0
- package/node_modules/assemblyscript/NOTICE +93 -0
- package/node_modules/assemblyscript/package.json +63 -0
- package/node_modules/assemblyscript/std/README.md +6 -0
- package/node_modules/assemblyscript/std/assembly/array.ts +526 -0
- package/node_modules/assemblyscript/std/assembly/arraybuffer.ts +77 -0
- package/node_modules/assemblyscript/std/assembly/atomics.ts +127 -0
- package/node_modules/assemblyscript/std/assembly/bindings/asyncify.ts +16 -0
- package/node_modules/assemblyscript/std/assembly/bindings/dom.ts +291 -0
- package/node_modules/assemblyscript/std/assembly/bindings/node.ts +6 -0
- package/node_modules/assemblyscript/std/assembly/builtins.ts +2631 -0
- package/node_modules/assemblyscript/std/assembly/compat.ts +2 -0
- package/node_modules/assemblyscript/std/assembly/console.ts +42 -0
- package/node_modules/assemblyscript/std/assembly/crypto.ts +9 -0
- package/node_modules/assemblyscript/std/assembly/dataview.ts +181 -0
- package/node_modules/assemblyscript/std/assembly/date.ts +373 -0
- package/node_modules/assemblyscript/std/assembly/diagnostics.ts +11 -0
- package/node_modules/assemblyscript/std/assembly/error.ts +44 -0
- package/node_modules/assemblyscript/std/assembly/function.ts +38 -0
- package/node_modules/assemblyscript/std/assembly/index.d.ts +2822 -0
- package/node_modules/assemblyscript/std/assembly/iterator.ts +35 -0
- package/node_modules/assemblyscript/std/assembly/map.ts +260 -0
- package/node_modules/assemblyscript/std/assembly/math.ts +3289 -0
- package/node_modules/assemblyscript/std/assembly/memory.ts +123 -0
- package/node_modules/assemblyscript/std/assembly/number.ts +388 -0
- package/node_modules/assemblyscript/std/assembly/object.ts +36 -0
- package/node_modules/assemblyscript/std/assembly/performance.ts +9 -0
- package/node_modules/assemblyscript/std/assembly/polyfills.ts +27 -0
- package/node_modules/assemblyscript/std/assembly/process.ts +50 -0
- package/node_modules/assemblyscript/std/assembly/reference.ts +48 -0
- package/node_modules/assemblyscript/std/assembly/regexp.ts +12 -0
- package/node_modules/assemblyscript/std/assembly/rt/README.md +83 -0
- package/node_modules/assemblyscript/std/assembly/rt/common.ts +81 -0
- package/node_modules/assemblyscript/std/assembly/rt/index-incremental.ts +2 -0
- package/node_modules/assemblyscript/std/assembly/rt/index-minimal.ts +2 -0
- package/node_modules/assemblyscript/std/assembly/rt/index-stub.ts +1 -0
- package/node_modules/assemblyscript/std/assembly/rt/index.d.ts +37 -0
- package/node_modules/assemblyscript/std/assembly/rt/itcms.ts +419 -0
- package/node_modules/assemblyscript/std/assembly/rt/rtrace.ts +15 -0
- package/node_modules/assemblyscript/std/assembly/rt/stub.ts +133 -0
- package/node_modules/assemblyscript/std/assembly/rt/tcms.ts +254 -0
- package/node_modules/assemblyscript/std/assembly/rt/tlsf.ts +592 -0
- package/node_modules/assemblyscript/std/assembly/rt.ts +87 -0
- package/node_modules/assemblyscript/std/assembly/set.ts +220 -0
- package/node_modules/assemblyscript/std/assembly/shared/feature.ts +65 -0
- package/node_modules/assemblyscript/std/assembly/shared/runtime.ts +11 -0
- package/node_modules/assemblyscript/std/assembly/shared/target.ts +11 -0
- package/node_modules/assemblyscript/std/assembly/shared/tsconfig.json +11 -0
- package/node_modules/assemblyscript/std/assembly/shared/typeinfo.ts +72 -0
- package/node_modules/assemblyscript/std/assembly/staticarray.ts +401 -0
- package/node_modules/assemblyscript/std/assembly/string.ts +847 -0
- package/node_modules/assemblyscript/std/assembly/symbol.ts +114 -0
- package/node_modules/assemblyscript/std/assembly/table.ts +16 -0
- package/node_modules/assemblyscript/std/assembly/tsconfig.json +6 -0
- package/node_modules/assemblyscript/std/assembly/typedarray.ts +1945 -0
- package/node_modules/assemblyscript/std/assembly/uri.ts +17 -0
- package/node_modules/assemblyscript/std/assembly/util/bytes.ts +107 -0
- package/node_modules/assemblyscript/std/assembly/util/casemap.ts +497 -0
- package/node_modules/assemblyscript/std/assembly/util/error.ts +54 -0
- package/node_modules/assemblyscript/std/assembly/util/hash.ts +117 -0
- package/node_modules/assemblyscript/std/assembly/util/math.ts +1922 -0
- package/node_modules/assemblyscript/std/assembly/util/memory.ts +290 -0
- package/node_modules/assemblyscript/std/assembly/util/number.ts +873 -0
- package/node_modules/assemblyscript/std/assembly/util/sort.ts +313 -0
- package/node_modules/assemblyscript/std/assembly/util/string.ts +1202 -0
- package/node_modules/assemblyscript/std/assembly/util/uri.ts +275 -0
- package/node_modules/assemblyscript/std/assembly/vector.ts +4 -0
- package/node_modules/assemblyscript/std/assembly.json +16 -0
- package/node_modules/assemblyscript/std/portable/index.d.ts +462 -0
- package/node_modules/assemblyscript/std/portable/index.js +416 -0
- package/node_modules/assemblyscript/std/portable.json +11 -0
- package/node_modules/assemblyscript/std/types/assembly/index.d.ts +1 -0
- package/node_modules/assemblyscript/std/types/assembly/package.json +3 -0
- package/node_modules/assemblyscript/std/types/portable/index.d.ts +1 -0
- package/node_modules/assemblyscript/std/types/portable/package.json +3 -0
- package/node_modules/assemblyscript/tsconfig-base.json +13 -0
- package/package.json +112 -0
- package/runtime/deps/assemblyscript/LICENSE +201 -0
- package/runtime/deps/assemblyscript/NOTICE +93 -0
- package/runtime/deps/assemblyscript/bin/asc.js +35 -0
- package/runtime/deps/assemblyscript/dist/asc.js +25035 -0
- package/runtime/deps/assemblyscript/dist/assemblyscript.js +337 -0
- package/runtime/deps/assemblyscript/node_modules/binaryen/LICENSE +201 -0
- package/runtime/deps/assemblyscript/node_modules/binaryen/index.js +28905 -0
- package/runtime/deps/assemblyscript/node_modules/binaryen/package.json +50 -0
- package/runtime/deps/assemblyscript/node_modules/long/LICENSE +202 -0
- package/runtime/deps/assemblyscript/node_modules/long/index.js +1581 -0
- package/runtime/deps/assemblyscript/node_modules/long/package.json +58 -0
- package/runtime/deps/assemblyscript/package.json +114 -0
- package/runtime/host/amxts.inc +85 -0
- package/runtime/licenses/AMXX-LICENSE.txt +34 -0
- package/runtime/licenses/AssemblyScript-LICENSE +201 -0
- package/runtime/licenses/AssemblyScript-NOTICE +93 -0
- package/runtime/licenses/Binaryen-LICENSE +201 -0
- package/runtime/licenses/Bun-LICENSE.md +84 -0
- package/runtime/licenses/GPL-3.0.txt +674 -0
- package/runtime/licenses/LLVM-LICENSE.TXT +279 -0
- package/runtime/licenses/README.md +25 -0
- package/runtime/licenses/WAMR-LICENSE +219 -0
- package/runtime/natives.txt +1095 -0
- package/runtime/patches/README.md +59 -0
- package/runtime/patches/assemblyscript-0.28.20-amxts.patch +14174 -0
- package/runtime/patches/wamr-2.4.5-amxts.patch +364 -0
- package/scripts/apply-docs.ts +508 -0
- package/scripts/asc.ts +27 -0
- package/scripts/auto-imports.ts +258 -0
- package/scripts/build-wasm.ts +595 -0
- package/scripts/check.ts +93 -0
- package/scripts/compile-cache.ts +179 -0
- package/scripts/compile.ts +401 -0
- package/scripts/docker-server.ts +73 -0
- package/scripts/docs/as/amxts.ts +210 -0
- package/scripts/docs/as/effects.ts +1684 -0
- package/scripts/docs/as/facade.ts +3302 -0
- package/scripts/docs/as/fs.ts +173 -0
- package/scripts/docs/as/lib/check.ts +68 -0
- package/scripts/docs/as/modules/http.ts +66 -0
- package/scripts/docs/as/os.ts +16 -0
- package/scripts/docs/as/promise.ts +132 -0
- package/scripts/docs/as/promise.types.ts +63 -0
- package/scripts/docs/as/vector.ts +48 -0
- package/scripts/docs/entities.ts +2338 -0
- package/scripts/docs/events.ts +245 -0
- package/scripts/docs/game.ts +497 -0
- package/scripts/docs/messages.ts +148 -0
- package/scripts/file-contents.ts +74 -0
- package/scripts/includes.ts +134 -0
- package/scripts/player-fields.ts +866 -0
- package/scripts/plugin-cache.ts +92 -0
- package/scripts/plugin-natives.ts +1157 -0
- package/scripts/prebuilt.ts +268 -0
- package/scripts/prepare.ts +134 -0
- package/scripts/project.ts +973 -0
- package/scripts/run.ts +28 -0
- package/scripts/shared-modules.ts +906 -0
- package/scripts/system.ts +33 -0
- package/scripts/tracked-fs.ts +115 -0
- package/scripts/typed-configs.ts +788 -0
- package/scripts/ui.ts +77 -0
- package/src/cli-api.mjs +175 -0
- package/src/parser/include-parser.ts +506 -0
- package/src/system.mjs +155 -0
- package/src/testing/compile-cache.ts +31 -0
- package/src/testing/compile.ts +222 -0
- package/src/testing/coroutines.ts +191 -0
- package/src/testing/index.ts +39 -0
- package/src/testing/kits.ts +55 -0
- package/src/testing/memory.ts +125 -0
- package/src/testing/natives.ts +925 -0
- package/src/testing/server.ts +1874 -0
- package/src/testing/setup.ts +63 -0
- package/src/testing/tables.ts +139 -0
- package/src/types.ts +51 -0
|
@@ -0,0 +1,582 @@
|
|
|
1
|
+
// vim: set ts=4 sw=4 tw=99 noet:
|
|
2
|
+
//
|
|
3
|
+
// AMX Mod X, based on AMX Mod by Aleksander Naszko ("OLO").
|
|
4
|
+
// Copyright (C) The AMX Mod X Development Team.
|
|
5
|
+
//
|
|
6
|
+
// This software is licensed under the GNU General Public License, version 3 or higher.
|
|
7
|
+
// Additional exceptions apply. For full license details, see LICENSE.txt or visit:
|
|
8
|
+
// https://alliedmods.net/amxmodx-license
|
|
9
|
+
|
|
10
|
+
//
|
|
11
|
+
// SQLX - Newer SQL Database API
|
|
12
|
+
//
|
|
13
|
+
|
|
14
|
+
#if defined _sqlx_included
|
|
15
|
+
#endinput
|
|
16
|
+
#endif
|
|
17
|
+
#define _sqlx_included
|
|
18
|
+
|
|
19
|
+
//eh..
|
|
20
|
+
#define SQL_NumRows SQL_NumResults
|
|
21
|
+
|
|
22
|
+
#pragma reqclass sqlx
|
|
23
|
+
#if !defined AMXMODX_NOAUTOLOAD
|
|
24
|
+
#pragma defclasslib sqlx mysql
|
|
25
|
+
#endif
|
|
26
|
+
|
|
27
|
+
enum Handle
|
|
28
|
+
{
|
|
29
|
+
Empty_Handle
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Creates a connection information tuple. This tuple must be passed
|
|
34
|
+
* into connection routines.
|
|
35
|
+
*
|
|
36
|
+
* @note Freeing the tuple is not necessary, but is a good idea if you create
|
|
37
|
+
* many of them. You can cache these handles globally.
|
|
38
|
+
* @note This does not connect to the DB; it only caches the connection information.
|
|
39
|
+
*
|
|
40
|
+
* @param host Database host
|
|
41
|
+
* @param user Database user
|
|
42
|
+
* @param pass Database password
|
|
43
|
+
* @param db Database name to use
|
|
44
|
+
* @param timeout Specifies how long connections should wait before giving up.
|
|
45
|
+
* If <= 0, the default of 60s is used.
|
|
46
|
+
*
|
|
47
|
+
* @return A newly created tuple handle to be used in connection routines.
|
|
48
|
+
*/
|
|
49
|
+
native Handle:SQL_MakeDbTuple(const host[], const user[], const pass[], const db[], timeout=0);
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Frees an SQL handle.
|
|
54
|
+
*
|
|
55
|
+
* @note The handle can be to anything (tuple, connection, query, results, etc).
|
|
56
|
+
* @note If you free the database connection handle, it closes the connection as well.
|
|
57
|
+
*
|
|
58
|
+
* @param h Handle to be freed.
|
|
59
|
+
*
|
|
60
|
+
* @noreturn
|
|
61
|
+
*/
|
|
62
|
+
native SQL_FreeHandle(Handle:h);
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Opens a database connection.
|
|
67
|
+
*
|
|
68
|
+
* @param cn_tuple Tuple handle, returned from SQL_MakeDbTuple().
|
|
69
|
+
* @param errcode An error code set by reference.
|
|
70
|
+
* @param error String where error string will be stored.
|
|
71
|
+
* @param maxlength Maximum length of the error buffer.
|
|
72
|
+
*
|
|
73
|
+
* @return Returns an SQL connection handle, which must be freed.
|
|
74
|
+
* Returns Empty_Handle on failure.
|
|
75
|
+
* @error Invalid info tuple handle.
|
|
76
|
+
*/
|
|
77
|
+
native Handle:SQL_Connect(Handle:cn_tuple, &errcode, error[], maxlength);
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Sets the character set of the current connection.
|
|
82
|
+
* Like SET NAMES .. in mysql, but stays after connection problems.
|
|
83
|
+
*
|
|
84
|
+
* @note If a connection tuple is supplied, this should be called before SQL_Connect or SQL_ThreadQuery.
|
|
85
|
+
* @note The change will remain until you call this function with another value.
|
|
86
|
+
* @note This native does nothing in SQLite.
|
|
87
|
+
*
|
|
88
|
+
* Example: "utf8", "latin1"
|
|
89
|
+
*
|
|
90
|
+
* @param h Database or connection tuple Handle.
|
|
91
|
+
* @param charset The character set string to change to.
|
|
92
|
+
*
|
|
93
|
+
* @return True, if character set was changed, false otherwise.
|
|
94
|
+
*/
|
|
95
|
+
native bool:SQL_SetCharset(Handle:h, const charset[]);
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Prepares a query.
|
|
100
|
+
*
|
|
101
|
+
* @note This does not actually do a query!
|
|
102
|
+
*
|
|
103
|
+
* @param db Connection handle, returned from SQL_Connect().
|
|
104
|
+
* @param fmt Query string. Can be formated with format specifiers.
|
|
105
|
+
* @param ... Additional format specifiers used to format the query.
|
|
106
|
+
*
|
|
107
|
+
* @return Returns an SQL query handle, which must always be freed.
|
|
108
|
+
* Returns Empty_Handle on failure.
|
|
109
|
+
*/
|
|
110
|
+
native Handle:SQL_PrepareQuery(Handle:db, const fmt[], any:...);
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Back-quotes characters in a string for database querying.
|
|
115
|
+
*
|
|
116
|
+
* @note The buffer's maximum size should be 2*strlen(string) to catch all scenarios.
|
|
117
|
+
*
|
|
118
|
+
* @param db Database handle for localization, or Empty_Handle
|
|
119
|
+
* for when a handle is not available.
|
|
120
|
+
* @param buffer Buffer to copy to.
|
|
121
|
+
* @param buflen Maximum size of the buffer.
|
|
122
|
+
* @param string String to backquote (should not overlap buffer).
|
|
123
|
+
*
|
|
124
|
+
* @return Length of new string, or -1 on failure.
|
|
125
|
+
* @error Invalid database handle.
|
|
126
|
+
*/
|
|
127
|
+
native SQL_QuoteString(Handle:db, buffer[], buflen, const string[]);
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Back-quotes characters in a string for database querying.
|
|
131
|
+
* Note: The buffer's maximum size should be 2*strlen(string) to catch
|
|
132
|
+
* all scenarios.
|
|
133
|
+
*
|
|
134
|
+
* @param db Database handle for localization, or Empty_Handle
|
|
135
|
+
* for when a handle is not available.
|
|
136
|
+
* @param buffer Buffer to copy to.
|
|
137
|
+
* @param buflen Maximum size of the buffer.
|
|
138
|
+
* @param fmt Format of string to backquote (should not overlap buffer).
|
|
139
|
+
* @param ... Format arguments.
|
|
140
|
+
*
|
|
141
|
+
* @return Length of new string, or -1 on failure.
|
|
142
|
+
*/
|
|
143
|
+
native SQL_QuoteStringFmt(Handle:db, buffer[], buflen, const fmt[], any:...);
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Threaded query states. Used to check the state of a complete threaded query.
|
|
148
|
+
*/
|
|
149
|
+
#define TQUERY_CONNECT_FAILED -2
|
|
150
|
+
#define TQUERY_QUERY_FAILED -1
|
|
151
|
+
#define TQUERY_SUCCESS 0
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Prepares and executes a threaded query.
|
|
155
|
+
* @note The handler should look like:
|
|
156
|
+
* public QueryHandler(failstate, Handle:query, error[], errnum, data[], size, Float:queuetime)
|
|
157
|
+
* failstate - One of the three TQUERY_ defines.
|
|
158
|
+
* query - Handle to the query, do not free it.
|
|
159
|
+
* error - An error message, if any.
|
|
160
|
+
* errnum - An error code, if any.
|
|
161
|
+
* data - Data array you passed in.
|
|
162
|
+
* size - Size of the data array you passed in.
|
|
163
|
+
* queuetime - Amount of gametime that passed while the query was resolving.
|
|
164
|
+
* @note This will not interrupt gameplay in the event of a poor/lossed
|
|
165
|
+
* connection, however, the interface is more complicated and
|
|
166
|
+
* asynchronous. Furthermore, a new connection/disconnection is
|
|
167
|
+
* made for each query to simplify driver support.
|
|
168
|
+
* @note The handle does not need to be freed.
|
|
169
|
+
*
|
|
170
|
+
* @param db_tuple Tuple handle, returned from SQL_MakeDbTuple().
|
|
171
|
+
* @param handler A function to be called when the query finishes. It has to be public.
|
|
172
|
+
* @param query The query string.
|
|
173
|
+
* @param data Additional data array that will be passed to the handler function.
|
|
174
|
+
* @param dataSize The size of the additional data array.
|
|
175
|
+
*
|
|
176
|
+
* @noreturn
|
|
177
|
+
* @error Thread worker was unable to start.
|
|
178
|
+
* Invalid info tuple handle.
|
|
179
|
+
* Handler function not found.
|
|
180
|
+
*/
|
|
181
|
+
native SQL_ThreadQuery(Handle:db_tuple, const handler[], const query[], const data[]="", dataSize=0);
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Executes an already prepared query.
|
|
186
|
+
*
|
|
187
|
+
* @note You can call this multiple times as long as its parent connection is kept open.
|
|
188
|
+
* Each time the result set from the previous call will be freed.
|
|
189
|
+
*
|
|
190
|
+
* @param query Handle of a prepared query to be executed.
|
|
191
|
+
*
|
|
192
|
+
* @return 1 if the query succeeded, 0 if the query failed.
|
|
193
|
+
* @error Invalid query handle.
|
|
194
|
+
*/
|
|
195
|
+
native SQL_Execute(Handle:query);
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Gets information about a failed query error.
|
|
200
|
+
*
|
|
201
|
+
* @param query Handle of a query to extract the error from.
|
|
202
|
+
* @param error Buffer where to store the error string.
|
|
203
|
+
* @param maxlength The maximum length of the output buffer.
|
|
204
|
+
*
|
|
205
|
+
* @return The error code.
|
|
206
|
+
*/
|
|
207
|
+
native SQL_QueryError(Handle:query, error[], maxlength);
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Checks whether there are more results to be read.
|
|
212
|
+
*
|
|
213
|
+
* @param query Handle of a query to check.
|
|
214
|
+
*
|
|
215
|
+
* @return 1 if there are more results, 0 otherwise.
|
|
216
|
+
* @error Invalid query handle.
|
|
217
|
+
*/
|
|
218
|
+
native SQL_MoreResults(Handle:query);
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Tells whether a specific column in the current row is NULL or not.
|
|
223
|
+
*
|
|
224
|
+
* @param query Handle of a query to check.
|
|
225
|
+
* @param column Which column to check for NULL.
|
|
226
|
+
*
|
|
227
|
+
* @return 1 if the column is NULL, 0 otherwise.
|
|
228
|
+
* @error Invalid query handle.
|
|
229
|
+
* No result set in this query.
|
|
230
|
+
* Invalid column.
|
|
231
|
+
*/
|
|
232
|
+
native SQL_IsNull(Handle:query, column);
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Retrieves the current result.
|
|
237
|
+
*
|
|
238
|
+
* @note A successful query starts at the first result, so you should not call
|
|
239
|
+
* SQL_NextRow() first.
|
|
240
|
+
*
|
|
241
|
+
* @note Example how to get different types of values:
|
|
242
|
+
* new num = SQL_ReadResult(query, 0)
|
|
243
|
+
* new Float:num2
|
|
244
|
+
* new string[32]
|
|
245
|
+
* SQL_ReadResult(query, 1, num2)
|
|
246
|
+
* SQL_ReadResult(query, 2, string, charsmax(string))
|
|
247
|
+
*
|
|
248
|
+
* @param query Handle of a query to read results from.
|
|
249
|
+
* @param column Which column to get the value from.
|
|
250
|
+
* @param ... Passing no extra arguments - returns an integer.
|
|
251
|
+
* Passing one extra argument - returns a float in the first extra argument
|
|
252
|
+
* Passing two extra params - returns a string in the first argument
|
|
253
|
+
* with a maximum string length in the second argument.
|
|
254
|
+
*
|
|
255
|
+
* @return If no extra arguments are passed, returns an integer value.
|
|
256
|
+
* @error Invalid query handle.
|
|
257
|
+
*/
|
|
258
|
+
native SQL_ReadResult(Handle:query, column, any:...);
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Advances to the next result (row).
|
|
263
|
+
*
|
|
264
|
+
* @param query Handle of a query.
|
|
265
|
+
*
|
|
266
|
+
* @noreturn
|
|
267
|
+
* @error Invalid query handle.
|
|
268
|
+
* No result set in this query.
|
|
269
|
+
*/
|
|
270
|
+
native SQL_NextRow(Handle:query);
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Returns the number of affected rows by a query.
|
|
275
|
+
*
|
|
276
|
+
* @param query Handle of a query to check.
|
|
277
|
+
*
|
|
278
|
+
* @return The number of affected rows.
|
|
279
|
+
* @error Invalid query handle.
|
|
280
|
+
*/
|
|
281
|
+
native SQL_AffectedRows(Handle:query);
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* The number of retrieved rows (results) after a query.
|
|
286
|
+
*
|
|
287
|
+
* @param query Handle of a query to check.
|
|
288
|
+
*
|
|
289
|
+
* @return The number of retrieved rows by the query.
|
|
290
|
+
* @error Invalid query handle.
|
|
291
|
+
*/
|
|
292
|
+
native SQL_NumResults(Handle:query);
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* Returns the total number of columns.
|
|
297
|
+
*
|
|
298
|
+
* @param query Handle of a query to check.
|
|
299
|
+
*
|
|
300
|
+
* @return The number of retrieved columns by the query.
|
|
301
|
+
* @error Invalid query handle.
|
|
302
|
+
* No result set in this query.
|
|
303
|
+
*/
|
|
304
|
+
native SQL_NumColumns(Handle:query);
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* Retrieves the name of a column by its index.
|
|
309
|
+
*
|
|
310
|
+
* @param query Handle of a query.
|
|
311
|
+
* @param num The number (index) of a column to retrieve the name from.
|
|
312
|
+
* @param name Buffer where to store the column's name.
|
|
313
|
+
* @param maxlength Maximum length of the output buffer.
|
|
314
|
+
*
|
|
315
|
+
* @noreturn
|
|
316
|
+
* @error Invalid query handle.
|
|
317
|
+
* No result set in this query.
|
|
318
|
+
* Invalid column index.
|
|
319
|
+
*/
|
|
320
|
+
native SQL_FieldNumToName(Handle:query, num, name[], maxlength);
|
|
321
|
+
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* Retrieves the number of a named column.
|
|
325
|
+
*
|
|
326
|
+
* @param query Handle of a query.
|
|
327
|
+
* @param name Name to search for.
|
|
328
|
+
*
|
|
329
|
+
* @return Column index if found (>= 0); -1 otherwise.
|
|
330
|
+
* @error Invalid query handle.
|
|
331
|
+
* No result set in this query.
|
|
332
|
+
*/
|
|
333
|
+
native SQL_FieldNameToNum(Handle:query, const name[]);
|
|
334
|
+
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* Rewinds a result set to the first row.
|
|
338
|
+
*
|
|
339
|
+
* @param query Handle of a query to rewind the result set of.
|
|
340
|
+
*
|
|
341
|
+
* @noreturn
|
|
342
|
+
* @error Invalid query handle.
|
|
343
|
+
* No result set in this query.
|
|
344
|
+
*/
|
|
345
|
+
native SQL_Rewind(Handle:query);
|
|
346
|
+
|
|
347
|
+
|
|
348
|
+
/**
|
|
349
|
+
* Retrieves the instert ID of the latest INSERT query.
|
|
350
|
+
*
|
|
351
|
+
* @param query Handle of a query.
|
|
352
|
+
*
|
|
353
|
+
* @return The insert ID of the latest INSERT query.
|
|
354
|
+
* @error Invalid query handle.
|
|
355
|
+
*/
|
|
356
|
+
native SQL_GetInsertId(Handle:query);
|
|
357
|
+
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* Retrieves which driver is this plugin currently bound to.
|
|
361
|
+
*
|
|
362
|
+
* @param driver Buffer to store the driver name in.
|
|
363
|
+
* @param maxlen Maximum length of the output buffer.
|
|
364
|
+
*
|
|
365
|
+
* @noreturn
|
|
366
|
+
*/
|
|
367
|
+
native SQL_GetAffinity(driver[], maxlen);
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* Sets driver affinity. You can use this to force a particular driver implementation.
|
|
372
|
+
* This will automatically change all SQL natives in your plugin to be "bound" to
|
|
373
|
+
* the module in question.
|
|
374
|
+
*
|
|
375
|
+
* @note Using this while you have open handles to another database type will
|
|
376
|
+
* cause problems. I.e., you cannot open a handle, switch affinity,
|
|
377
|
+
* then close the handle with a different driver.
|
|
378
|
+
* @note Switching affinity is an O(n * m) operation, where n is the number of
|
|
379
|
+
* SQL natives and m is the number of used natives in total.
|
|
380
|
+
* @note Intuitive programmers will note that this causes problems for
|
|
381
|
+
* threaded queries. You will have to either force your script to work
|
|
382
|
+
* under one affinity, or to pack the affinity type into the query data,
|
|
383
|
+
* check it against the current, then set the new affinity if necessary.
|
|
384
|
+
* Then, restore the old one for safety.
|
|
385
|
+
*
|
|
386
|
+
* @param driver The name of a driver to use.
|
|
387
|
+
*
|
|
388
|
+
* @return If no module with the given name is found, returns 0.
|
|
389
|
+
* Unless your plugin is bult to handle different driver
|
|
390
|
+
* types at once, you should let this error pass.
|
|
391
|
+
*/
|
|
392
|
+
native SQL_SetAffinity(const driver[]);
|
|
393
|
+
|
|
394
|
+
/**
|
|
395
|
+
* Returns the original query string that a query handle used.
|
|
396
|
+
*
|
|
397
|
+
* @param query Handle of a query.
|
|
398
|
+
* @param buffer Buffer where to put the query string in.
|
|
399
|
+
* @param maxlength The maximum length of the output buffer.
|
|
400
|
+
*
|
|
401
|
+
* @noreturn
|
|
402
|
+
* @error Invalid query handle.
|
|
403
|
+
*/
|
|
404
|
+
native SQL_GetQueryString(Handle:query, buffer[], maxlength);
|
|
405
|
+
|
|
406
|
+
/**
|
|
407
|
+
* For queries which return multiple result sets, this advances to the next
|
|
408
|
+
* result set if one is available. Otherwise, the current result set is
|
|
409
|
+
* destroyed and will no longer be accessible.
|
|
410
|
+
*
|
|
411
|
+
* @note This function will always return false on SQLite, and when using threaded
|
|
412
|
+
* queries in MySQL. Nonetheless, it has the same effect of removing the last
|
|
413
|
+
* result set.
|
|
414
|
+
*
|
|
415
|
+
* @param query Query Handle.
|
|
416
|
+
*
|
|
417
|
+
* @return True on success, false on failure.
|
|
418
|
+
* @error Invalid query handle.
|
|
419
|
+
* No result set in this query.
|
|
420
|
+
*/
|
|
421
|
+
native bool:SQL_NextResultSet(Handle:query);
|
|
422
|
+
|
|
423
|
+
|
|
424
|
+
/**
|
|
425
|
+
* This function can be used to find out if a table in a SQLite database exists.
|
|
426
|
+
*
|
|
427
|
+
* @param db Connection handle returned from SQL_Connect().
|
|
428
|
+
* @param table The table name to check for.
|
|
429
|
+
*
|
|
430
|
+
* @return True if it exists, false otherwise.
|
|
431
|
+
*/
|
|
432
|
+
stock bool:sqlite_TableExists(Handle:db, const table[])
|
|
433
|
+
{
|
|
434
|
+
new Handle:query = SQL_PrepareQuery(
|
|
435
|
+
db,
|
|
436
|
+
"SELECT name FROM sqlite_master WHERE type='table' AND name='%s' LIMIT 1;",
|
|
437
|
+
table);
|
|
438
|
+
|
|
439
|
+
if (!SQL_Execute(query) || !SQL_NumResults(query))
|
|
440
|
+
{
|
|
441
|
+
SQL_FreeHandle(query);
|
|
442
|
+
return false;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
SQL_FreeHandle(query);
|
|
446
|
+
|
|
447
|
+
return true;
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
/**
|
|
451
|
+
* Use this for executing a query where you don't care about the result.
|
|
452
|
+
*
|
|
453
|
+
* @param db Connection handle returned from SQL_Connect().
|
|
454
|
+
* @param query The query string.
|
|
455
|
+
* @param error If an error occurs, it will be placed into this buffer.
|
|
456
|
+
* @param maxlength Maximum length of the error buffer.
|
|
457
|
+
* @param rows Optional. If put, retrieves the number of rows the query returned.
|
|
458
|
+
*
|
|
459
|
+
* @return 1 on success, 0 on failure.
|
|
460
|
+
*/
|
|
461
|
+
stock SQL_SimpleQuery(Handle:db, const query[], error[]="", maxlength=0, &rows=0)
|
|
462
|
+
{
|
|
463
|
+
new Handle:hQuery = SQL_PrepareQuery(db, "%s", query);
|
|
464
|
+
|
|
465
|
+
if (!SQL_Execute(hQuery))
|
|
466
|
+
{
|
|
467
|
+
SQL_QueryError(hQuery, error, maxlength);
|
|
468
|
+
SQL_FreeHandle(hQuery);
|
|
469
|
+
return 0;
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
rows = SQL_NumResults(hQuery);
|
|
473
|
+
|
|
474
|
+
SQL_FreeHandle(hQuery);
|
|
475
|
+
|
|
476
|
+
return 1;
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
|
|
480
|
+
/**
|
|
481
|
+
* Use this for executing a query where you don't care about the result.
|
|
482
|
+
*
|
|
483
|
+
* @note Differs from SQL_SimpleQuery() because the query can be formated.
|
|
484
|
+
*
|
|
485
|
+
* @param db Connection handle returned from SQL_Connect().
|
|
486
|
+
* @param error If an error occurs, it will be placed into this buffer.
|
|
487
|
+
* @param maxlength The maximum length of the error buffer.
|
|
488
|
+
* @param rows Optional. If put, retrieves the number of rows the query returned.
|
|
489
|
+
* @param fmt The query string that can be formated with format specifiers.
|
|
490
|
+
* @param ... Additional arguments for formating the query.
|
|
491
|
+
*
|
|
492
|
+
* @return 1 on success, 0 on failure.
|
|
493
|
+
*/
|
|
494
|
+
stock SQL_SimpleQueryFmt(Handle:db, error[]="", maxlength=0, &rows=0, const fmt[], any:...)
|
|
495
|
+
{
|
|
496
|
+
static query_buf[2048];
|
|
497
|
+
vformat(query_buf, 2047, fmt, 6);
|
|
498
|
+
|
|
499
|
+
new Handle:hQuery = SQL_PrepareQuery(db, "%s", query_buf);
|
|
500
|
+
|
|
501
|
+
if (!SQL_Execute(hQuery))
|
|
502
|
+
{
|
|
503
|
+
SQL_QueryError(hQuery, error, maxlength);
|
|
504
|
+
SQL_FreeHandle(hQuery);
|
|
505
|
+
return 0;
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
rows = SQL_NumResults(hQuery);
|
|
509
|
+
|
|
510
|
+
SQL_FreeHandle(hQuery);
|
|
511
|
+
|
|
512
|
+
return 1;
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
/**
|
|
516
|
+
* Use this for executing a query and not caring about the error.
|
|
517
|
+
*
|
|
518
|
+
* @param db A connection handle returned from SQL_Connect().
|
|
519
|
+
* @param queryfmt The query string that can be formated with format specifiers.
|
|
520
|
+
* @pram ... Additional arguments for formating the query.
|
|
521
|
+
*
|
|
522
|
+
* @return -1 on error.
|
|
523
|
+
* >= 0 on success (with the number of affected rows).
|
|
524
|
+
*/
|
|
525
|
+
stock SQL_QueryAndIgnore(Handle:db, const queryfmt[], any:...)
|
|
526
|
+
{
|
|
527
|
+
static query[4096];
|
|
528
|
+
new Handle:hQuery;
|
|
529
|
+
new ret;
|
|
530
|
+
|
|
531
|
+
vformat(query, sizeof(query)-1, queryfmt, 3);
|
|
532
|
+
|
|
533
|
+
hQuery = SQL_PrepareQuery(db, "%s", query);
|
|
534
|
+
|
|
535
|
+
if (SQL_Execute(hQuery))
|
|
536
|
+
{
|
|
537
|
+
ret = SQL_AffectedRows(hQuery);
|
|
538
|
+
} else {
|
|
539
|
+
ret = -1;
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
SQL_FreeHandle(hQuery);
|
|
543
|
+
|
|
544
|
+
return ret;
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
/**
|
|
548
|
+
* Use this for making a standard DB Tuple, using AMXX's database info cvars.
|
|
549
|
+
*
|
|
550
|
+
* @param timeout Specifies how long connections should wait before giving up.
|
|
551
|
+
* If 0, the value is read from "amx_sql_timeout" cvar.
|
|
552
|
+
*
|
|
553
|
+
* @return A newly created tuple handle to be used in connection routines.
|
|
554
|
+
*/
|
|
555
|
+
stock Handle:SQL_MakeStdTuple(timeout = 0)
|
|
556
|
+
{
|
|
557
|
+
static host[64], user[32], pass[32], db[128];
|
|
558
|
+
static get_type[12], set_type[12];
|
|
559
|
+
|
|
560
|
+
get_cvar_string("amx_sql_host", host, 63);
|
|
561
|
+
get_cvar_string("amx_sql_user", user, 31);
|
|
562
|
+
get_cvar_string("amx_sql_pass", pass, 31);
|
|
563
|
+
get_cvar_string("amx_sql_type", set_type, 11);
|
|
564
|
+
get_cvar_string("amx_sql_db", db, 127);
|
|
565
|
+
|
|
566
|
+
if (timeout <= 0)
|
|
567
|
+
{
|
|
568
|
+
timeout = get_cvar_num("amx_sql_timeout");
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
SQL_GetAffinity(get_type, 12);
|
|
572
|
+
|
|
573
|
+
if (!equali(get_type, set_type))
|
|
574
|
+
{
|
|
575
|
+
if (!SQL_SetAffinity(set_type))
|
|
576
|
+
{
|
|
577
|
+
log_amx("Failed to set affinity from %s to %s.", get_type, set_type);
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
return SQL_MakeDbTuple(host, user, pass, db, timeout);
|
|
582
|
+
}
|