forked from pBlueG/SA-MP-MySQL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
a_mysql.inc.in
258 lines (209 loc) · 8.6 KB
/
a_mysql.inc.in
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
/**
* MySQL plugin @MYSQL_PLUGIN_VERSION@
*/
#if defined mysql_included
#endinput
#endif
#define mysql_included
/**
* Common error codes
*
* Client: http://dev.mysql.com/doc/refman/5.5/en/error-messages-client.html
* Server: http://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html
*/
#define ER_DBACCESS_DENIED_ERROR 1044
#define ER_ACCESS_DENIED_ERROR 1045
#define ER_UNKNOWN_TABLE 1109
#define ER_SYNTAX_ERROR 1149
#define CR_SERVER_GONE_ERROR 2006
#define CR_SERVER_LOST 2013
#define CR_COMMAND_OUT_OF_SYNC 2014
#define CR_SERVER_LOST_EXTENDED 2055
enum E_ORM_ERROR
{
ERROR_INVALID,
ERROR_OK,
ERROR_NO_DATA
};
enum E_MYSQL_GLOBAL_OPTION
{
DUPLICATE_CONNECTIONS,
DUPLICATE_CONNECTION_WARNING
};
enum E_MYSQL_OPTION
{
AUTO_RECONNECT,
MULTI_STATEMENTS,
POOL_SIZE,
SERVER_PORT,
SSL_ENABLE,
SSL_KEY_FILE,
SSL_CERT_FILE,
SSL_CA_FILE,
SSL_CA_PATH,
SSL_CIPHER
};
enum E_MYSQL_FIELD_TYPE
{
MYSQL_TYPE_INVALID = -1,
MYSQL_TYPE_DECIMAL = 0,
MYSQL_TYPE_TINY,
MYSQL_TYPE_SHORT,
MYSQL_TYPE_LONG,
MYSQL_TYPE_FLOAT,
MYSQL_TYPE_DOUBLE,
MYSQL_TYPE_NULL,
MYSQL_TYPE_TIMESTAMP,
MYSQL_TYPE_LONGLONG,
MYSQL_TYPE_INT24,
MYSQL_TYPE_DATE,
MYSQL_TYPE_TIME,
MYSQL_TYPE_DATETIME,
MYSQL_TYPE_YEAR,
MYSQL_TYPE_NEWDATE,
MYSQL_TYPE_VARCHAR,
MYSQL_TYPE_BIT,
MYSQL_TYPE_TIMESTAMP2,
MYSQL_TYPE_DATETIME2,
MYSQL_TYPE_TIME2,
MYSQL_TYPE_JSON = 245,
MYSQL_TYPE_NEWDECIMAL = 246,
MYSQL_TYPE_ENUM = 247,
MYSQL_TYPE_SET = 248,
MYSQL_TYPE_TINY_BLOB = 249,
MYSQL_TYPE_MEDIUM_BLOB = 250,
MYSQL_TYPE_LONG_BLOB = 251,
MYSQL_TYPE_BLOB = 252,
MYSQL_TYPE_VAR_STRING = 253,
MYSQL_TYPE_STRING = 254,
MYSQL_TYPE_GEOMETRY = 255
};
enum E_MYSQL_EXECTIME_UNIT
{
MILLISECONDS,
MICROSECONDS
};
#define MYSQL_DEFAULT_HANDLE MySQL:1
#define MYSQL_INVALID_HANDLE MySQL:0
#define MYSQL_INVALID_CACHE Cache:0
#define MYSQL_INVALID_ORM ORM:0
// ORM functions
native ORM:orm_create(const table[], MySQL:handle = MYSQL_DEFAULT_HANDLE);
native orm_destroy(ORM:id);
native E_ORM_ERROR:orm_errno(ORM:id);
native orm_apply_cache(ORM:id, row_idx, result_idx = 0);
native orm_select(ORM:id, const callback[] = "", const format[] = "", {ORM, Float, _}:...);
native orm_update(ORM:id, const callback[] = "", const format[] = "", {ORM, Float, _}:...);
native orm_insert(ORM:id, const callback[] = "", const format[] = "", {ORM, Float, _}:...);
native orm_delete(ORM:id, const callback[] = "", const format[] = "", {ORM, Float, _}:...);
native orm_load(ORM:id, const callback[] = "", const format[] = "", {ORM, Float, _}:...) = orm_select;
native orm_save(ORM:id, const callback[] = "", const format[] = "", {ORM, Float, _}:...);
native orm_addvar_int(ORM:id, &var, const columnname[]);
native orm_addvar_float(ORM:id, &Float:var, const columnname[]);
native orm_addvar_string(ORM:id, var[], var_maxlen, const columnname[]);
native orm_clear_vars(ORM:id);
native orm_delvar(ORM:id, const columnname[]);
native orm_setkey(ORM:id, const columnname[]);
// MySQL functions
native MySQL:mysql_connect(const host[], const user[], const password[], const database[], MySQLOpt:option_id = MySQLOpt:0);
native MySQL:mysql_connect_file(const file_name[] = "mysql.ini");
native mysql_close(MySQL:handle = MYSQL_DEFAULT_HANDLE);
native mysql_unprocessed_queries(MySQL:handle = MYSQL_DEFAULT_HANDLE);
native mysql_global_options(E_MYSQL_GLOBAL_OPTION:type, value);
native MySQLOpt:mysql_init_options();
native mysql_set_option(MySQLOpt:option_id, E_MYSQL_OPTION:type, ...);
native mysql_pquery(MySQL:handle, const query[], const callback[] = "", const format[] = "", {MySQL, Float,_}:...);
native mysql_tquery(MySQL:handle, const query[], const callback[] = "", const format[] = "", {MySQL, Float,_}:...);
native Cache:mysql_query(MySQL:handle, const query[], bool:use_cache = true);
native mysql_tquery_file(MySQL:handle, const file_path[], const callback[] = "", const format[] = "", {MySQL, Float,_}:...);
native Cache:mysql_query_file(MySQL:handle, const file_path[], bool:use_cache = false);
native mysql_errno(MySQL:handle = MYSQL_DEFAULT_HANDLE);
native mysql_error(destination[], max_len = sizeof(destination), MySQL:handle = MYSQL_DEFAULT_HANDLE);
native mysql_escape_string(const source[], destination[], max_len = sizeof(destination), MySQL:handle = MYSQL_DEFAULT_HANDLE);
native mysql_format(MySQL:handle, output[], max_len, const format[], {MySQL, Float,_}:...);
native mysql_set_charset(const charset[], MySQL:handle = MYSQL_DEFAULT_HANDLE);
native mysql_get_charset(destination[], max_len = sizeof(destination), MySQL:handle = MYSQL_DEFAULT_HANDLE);
native mysql_stat(destination[], max_len = sizeof(destination), MySQL:handle = MYSQL_DEFAULT_HANDLE);
// Cache functions
native cache_get_row_count(&destination);
native cache_get_field_count(&destination);
native cache_get_result_count(&destination);
native cache_get_field_name(field_index, destination[], max_len = sizeof(destination));
native E_MYSQL_FIELD_TYPE:cache_get_field_type(field_index);
native cache_set_result(result_index);
stock cache_num_rows()
{
new row_count;
cache_get_row_count(row_count);
return row_count;
}
stock cache_num_fields()
{
new field_count;
cache_get_field_count(field_count);
return field_count;
}
stock cache_num_results()
{
new result_count;
cache_get_result_count(result_count);
return result_count;
}
// overload macros for cache_get_value natives
#define cache_get_value(%1) (_:MSCGV0:MSCGV1:MSCGV2:cache_get_ovrld_value(%1))
#define MSCGV0:MSCGV1:MSCGV2:cache_get_ovrld_value(%1,"%2",%3) cache_get_value_name(%1,#%2,%3)
#define MSCGV1:MSCGV2:cache_get_ovrld_value(%1,%8string%9:%2,%3) cache_get_value_name(%1,%2,%3)
#define MSCGV2:cache_get_ovrld_value(%1,%2,%3) cache_get_value_index(%1,%2,%3)
#define cache_get_value_int(%1) (_:MSCGVI0:MSCGVI1:MSCGVI2:cache_get_value_int_ovrld(%1))
#define MSCGVI0:MSCGVI1:MSCGVI2:cache_get_value_int_ovrld(%1,"%2",%3) cache_get_value_name_int(%1,#%2,%3)
#define MSCGVI1:MSCGVI2:cache_get_value_int_ovrld(%1,%8string%9:%2,%3) cache_get_value_name_int(%1,%2,%3)
#define MSCGVI2:cache_get_value_int_ovrld(%1,%2,%3) cache_get_value_index_int(%1,%2,%3)
#define cache_get_value_float(%1) (_:MSCGVF0:MSCGVF1:MSCGVF2:cache_get_value_float_ovrld(%1))
#define MSCGVF0:MSCGVF1:MSCGVF2:cache_get_value_float_ovrld(%1,"%2",%3) cache_get_value_name_float(%1,#%2,%3)
#define MSCGVF1:MSCGVF2:cache_get_value_float_ovrld(%1,%8string%9:%2,%3) cache_get_value_name_float(%1,%2,%3)
#define MSCGVF2:cache_get_value_float_ovrld(%1,%2,%3) cache_get_value_index_float(%1,%2,%3)
#define cache_get_value_bool(%1) cache_get_value_int(%1)
#define cache_is_value_null(%1) (_:MSCIVN0:MSCIVN1:MSCIVN2:cache_is_value_null_ovrld(%1))
#define MSCIVN0:MSCIVN1:MSCIVN2:cache_is_value_null_ovrld(%1,"%2",%3) cache_is_value_name_null(%1,#%2,%3)
#define MSCIVN1:MSCIVN2:cache_is_value_null_ovrld(%1,%8string%9:%2,%3) cache_is_value_name_null(%1,%2,%3)
#define MSCIVN2:cache_is_value_null_ovrld(%1,%2,%3) cache_is_value_index_null(%1,%2,%3)
native cache_get_value_index(row_idx, column_idx, destination[], max_len = sizeof(destination));
native cache_get_value_index_int(row_idx, column_idx, &destination);
native cache_get_value_index_float(row_idx, column_idx, &Float:destination);
native cache_get_value_index_bool(row_idx, column_idx, &bool:destination) = cache_get_value_index_int;
native cache_is_value_index_null(row_idx, column_idx, &bool:destination);
native cache_get_value_name(row_idx, const column_name[], destination[], max_len = sizeof(destination));
native cache_get_value_name_int(row_idx, const column_name[], &destination);
native cache_get_value_name_float(row_idx, const column_name[], &Float:destination);
native cache_get_value_name_bool(row_idx, const column_name[], &bool:destination) = cache_get_value_name_int;
native cache_is_value_name_null(row_idx, const column_name[], &bool:destination);
native Cache:cache_save();
native cache_delete(Cache:cache_id);
native cache_set_active(Cache:cache_id);
native cache_unset_active();
native bool:cache_is_any_active();
native bool:cache_is_valid(Cache:cache_id);
native cache_affected_rows();
native cache_insert_id();
native cache_warning_count();
native cache_get_query_exec_time(E_MYSQL_EXECTIME_UNIT:unit = MICROSECONDS);
native cache_get_query_string(destination[], max_len = sizeof(destination));
// Forward declarations
forward OnQueryError(errorid, const error[], const callback[], const query[], MySQL:handle);
// Deprecated functions
#if !defined E_LOGLEVEL
enum E_LOGLEVEL
{
NONE = 0,
DEBUG = 1,
INFO = 2,
WARNING = 4,
ERROR = 8,
ALL = ERROR | WARNING | INFO | DEBUG
};
#endif
#pragma deprecated Configuring log levels is now done through the "log-config.yml" file
stock mysql_log(E_LOGLEVEL:loglevel = ERROR | WARNING)
{
#pragma unused loglevel
}