1
0

a_mysqll.inc 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. /**
  2. * MySQL plugin R41-4
  3. */
  4. #if defined mysql_included
  5. #endinput
  6. #endif
  7. #define mysql_included
  8. /**
  9. * Common error codes
  10. *
  11. * Client: http://dev.mysql.com/doc/refman/5.5/en/error-messages-client.html
  12. * Server: http://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html
  13. */
  14. #define ER_DBACCESS_DENIED_ERROR 1044
  15. #define ER_ACCESS_DENIED_ERROR 1045
  16. #define ER_UNKNOWN_TABLE 1109
  17. #define ER_SYNTAX_ERROR 1149
  18. #define CR_SERVER_GONE_ERROR 2006
  19. #define CR_SERVER_LOST 2013
  20. #define CR_COMMAND_OUT_OF_SYNC 2014
  21. #define CR_SERVER_LOST_EXTENDED 2055
  22. #if !defined E_LOGLEVEL
  23. enum E_LOGLEVEL
  24. {
  25. NONE = 0,
  26. DEBUG = 1,
  27. INFO = 2,
  28. WARNING = 4,
  29. ERROR = 8,
  30. ALL = ERROR | WARNING | INFO | DEBUG
  31. };
  32. #endif
  33. enum E_ORM_ERROR
  34. {
  35. ERROR_INVALID,
  36. ERROR_OK,
  37. ERROR_NO_DATA
  38. };
  39. enum E_MYSQL_GLOBAL_OPTION
  40. {
  41. DUPLICATE_CONNECTIONS,
  42. DUPLICATE_CONNECTION_WARNING
  43. };
  44. enum E_MYSQL_OPTION
  45. {
  46. AUTO_RECONNECT,
  47. MULTI_STATEMENTS,
  48. POOL_SIZE,
  49. SERVER_PORT,
  50. SSL_ENABLE,
  51. SSL_KEY_FILE,
  52. SSL_CERT_FILE,
  53. SSL_CA_FILE,
  54. SSL_CA_PATH,
  55. SSL_CIPHER
  56. };
  57. enum E_MYSQL_FIELD_TYPE
  58. {
  59. MYSQL_TYPE_INVALID = -1,
  60. MYSQL_TYPE_DECIMAL = 0,
  61. MYSQL_TYPE_TINY,
  62. MYSQL_TYPE_SHORT,
  63. MYSQL_TYPE_LONG,
  64. MYSQL_TYPE_FLOAT,
  65. MYSQL_TYPE_DOUBLE,
  66. MYSQL_TYPE_NULL,
  67. MYSQL_TYPE_TIMESTAMP,
  68. MYSQL_TYPE_LONGLONG,
  69. MYSQL_TYPE_INT24,
  70. MYSQL_TYPE_DATE,
  71. MYSQL_TYPE_TIME,
  72. MYSQL_TYPE_DATETIME,
  73. MYSQL_TYPE_YEAR,
  74. MYSQL_TYPE_NEWDATE,
  75. MYSQL_TYPE_VARCHAR,
  76. MYSQL_TYPE_BIT,
  77. MYSQL_TYPE_TIMESTAMP2,
  78. MYSQL_TYPE_DATETIME2,
  79. MYSQL_TYPE_TIME2,
  80. MYSQL_TYPE_JSON = 245,
  81. MYSQL_TYPE_NEWDECIMAL = 246,
  82. MYSQL_TYPE_ENUM = 247,
  83. MYSQL_TYPE_SET = 248,
  84. MYSQL_TYPE_TINY_BLOB = 249,
  85. MYSQL_TYPE_MEDIUM_BLOB = 250,
  86. MYSQL_TYPE_LONG_BLOB = 251,
  87. MYSQL_TYPE_BLOB = 252,
  88. MYSQL_TYPE_VAR_STRING = 253,
  89. MYSQL_TYPE_STRING = 254,
  90. MYSQL_TYPE_GEOMETRY = 255
  91. };
  92. enum E_MYSQL_EXECTIME_UNIT
  93. {
  94. MILLISECONDS,
  95. MICROSECONDS
  96. };
  97. #define MYSQL_DEFAULT_HANDLE MySQL:1
  98. #define MYSQL_INVALID_HANDLE MySQL:0
  99. #define MYSQL_INVALID_CACHE Cache:0
  100. #define MYSQL_INVALID_ORM ORM:0
  101. // ORM functions
  102. native ORM:orm_create(const table[], MySQL:handle = MYSQL_DEFAULT_HANDLE);
  103. native orm_destroy(ORM:id);
  104. native E_ORM_ERROR:orm_errno(ORM:id);
  105. native orm_apply_cache(ORM:id, row_idx, result_idx = 0);
  106. native orm_select(ORM:id, const callback[] = "", const format[] = "", {Float, _}:...);
  107. native orm_update(ORM:id, const callback[] = "", const format[] = "", {Float, _}:...);
  108. native orm_insert(ORM:id, const callback[] = "", const format[] = "", {Float, _}:...);
  109. native orm_delete(ORM:id, const callback[] = "", const format[] = "", {Float, _}:...);
  110. native orm_load(ORM:id, const callback[] = "", const format[] = "", {Float, _}:...) = orm_select;
  111. native orm_save(ORM:id, const callback[] = "", const format[] = "", {Float, _}:...);
  112. native orm_addvar_int(ORM:id, &var, const columnname[]);
  113. native orm_addvar_float(ORM:id, &Float:var, const columnname[]);
  114. native orm_addvar_string(ORM:id, var[], var_maxlen, const columnname[]);
  115. native orm_clear_vars(ORM:id);
  116. native orm_delvar(ORM:id, const columnname[]);
  117. native orm_setkey(ORM:id, const columnname[]);
  118. // MySQL functions
  119. native mysql_log(E_LOGLEVEL:loglevel = ERROR | WARNING);
  120. native MySQL:mysql_connect(const host[], const user[], const password[], const database[], MySQLOpt:option_id = MySQLOpt:0);
  121. native MySQL:mysql_connect_file(const file_name[] = "mysql.ini");
  122. native mysql_close(MySQL:handle = MYSQL_DEFAULT_HANDLE);
  123. native mysql_unprocessed_queries(MySQL:handle = MYSQL_DEFAULT_HANDLE);
  124. native mysql_global_options(E_MYSQL_GLOBAL_OPTION:type, value);
  125. native MySQLOpt:mysql_init_options();
  126. native mysql_set_option(MySQLOpt:option_id, E_MYSQL_OPTION:type, ...);
  127. native mysql_pquery(MySQL:handle, const query[], const callback[] = "", const format[] = "", {Float,_}:...);
  128. native mysql_tquery(MySQL:handle, const query[], const callback[] = "", const format[] = "", {Float,_}:...);
  129. native Cache:mysql_query(MySQL:handle, const query[], bool:use_cache = true);
  130. native mysql_tquery_file(MySQL:handle, const file_path[], const callback[] = "", const format[] = "", {Float,_}:...);
  131. native Cache:mysql_query_file(MySQL:handle, const file_path[], bool:use_cache = false);
  132. native mysql_errno(MySQL:handle = MYSQL_DEFAULT_HANDLE);
  133. native mysql_error(destination[], max_len = sizeof(destination), MySQL:handle = MYSQL_DEFAULT_HANDLE);
  134. native mysql_escape_string(const source[], destination[], max_len = sizeof(destination), MySQL:handle = MYSQL_DEFAULT_HANDLE);
  135. native mysql_format(MySQL:handle, output[], max_len, const format[], {Float,_}:...);
  136. native mysql_set_charset(const charset[], MySQL:handle = MYSQL_DEFAULT_HANDLE);
  137. native mysql_get_charset(destination[], max_len = sizeof(destination), MySQL:handle = MYSQL_DEFAULT_HANDLE);
  138. native mysql_stat(destination[], max_len = sizeof(destination), MySQL:handle = MYSQL_DEFAULT_HANDLE);
  139. // Cache functions
  140. native cache_get_row_count(&destination);
  141. native cache_get_field_count(&destination);
  142. native cache_get_result_count(&destination);
  143. native cache_get_field_name(field_index, destination[], max_len = sizeof(destination));
  144. native E_MYSQL_FIELD_TYPE:cache_get_field_type(field_index);
  145. native cache_set_result(result_index);
  146. stock cache_num_rows()
  147. {
  148. new row_count;
  149. cache_get_row_count(row_count);
  150. return row_count;
  151. }
  152. stock cache_num_fields()
  153. {
  154. new field_count;
  155. cache_get_field_count(field_count);
  156. return field_count;
  157. }
  158. stock cache_num_results()
  159. {
  160. new result_count;
  161. cache_get_result_count(result_count);
  162. return result_count;
  163. }
  164. // overload macros for cache_get_value natives
  165. #define cache_get_value(%1) (_:MSCGV0:MSCGV1:MSCGV2:cache_get_ovrld_value(%1))
  166. #define MSCGV0:MSCGV1:MSCGV2:cache_get_ovrld_value(%1,"%2",%3) cache_get_value_name(%1,#%2,%3)
  167. #define MSCGV1:MSCGV2:cache_get_ovrld_value(%1,%8string%9:%2,%3) cache_get_value_name(%1,%2,%3)
  168. #define MSCGV2:cache_get_ovrld_value(%1,%2,%3) cache_get_value_index(%1,%2,%3)
  169. #define cache_get_value_int(%1) (_:MSCGVI0:MSCGVI1:MSCGVI2:cache_get_value_int_ovrld(%1))
  170. #define MSCGVI0:MSCGVI1:MSCGVI2:cache_get_value_int_ovrld(%1,"%2",%3) cache_get_value_name_int(%1,#%2,%3)
  171. #define MSCGVI1:MSCGVI2:cache_get_value_int_ovrld(%1,%8string%9:%2,%3) cache_get_value_name_int(%1,%2,%3)
  172. #define MSCGVI2:cache_get_value_int_ovrld(%1,%2,%3) cache_get_value_index_int(%1,%2,%3)
  173. #define cache_get_value_float(%1) (_:MSCGVF0:MSCGVF1:MSCGVF2:cache_get_value_float_ovrld(%1))
  174. #define MSCGVF0:MSCGVF1:MSCGVF2:cache_get_value_float_ovrld(%1,"%2",%3) cache_get_value_name_float(%1,#%2,%3)
  175. #define MSCGVF1:MSCGVF2:cache_get_value_float_ovrld(%1,%8string%9:%2,%3) cache_get_value_name_float(%1,%2,%3)
  176. #define MSCGVF2:cache_get_value_float_ovrld(%1,%2,%3) cache_get_value_index_float(%1,%2,%3)
  177. #define cache_get_value_bool(%1) cache_get_value_int(%1)
  178. #define cache_is_value_null(%1) (_:MSCIVN0:MSCIVN1:MSCIVN2:cache_is_value_null_ovrld(%1))
  179. #define MSCIVN0:MSCIVN1:MSCIVN2:cache_is_value_null_ovrld(%1,"%2",%3) cache_is_value_name_null(%1,#%2,%3)
  180. #define MSCIVN1:MSCIVN2:cache_is_value_null_ovrld(%1,%8string%9:%2,%3) cache_is_value_name_null(%1,%2,%3)
  181. #define MSCIVN2:cache_is_value_null_ovrld(%1,%2,%3) cache_is_value_index_null(%1,%2,%3)
  182. native cache_get_value_index(row_idx, column_idx, destination[], max_len = sizeof(destination));
  183. native cache_get_value_index_int(row_idx, column_idx, &destination);
  184. native cache_get_value_index_float(row_idx, column_idx, &Float:destination);
  185. /*
  186. native cache_get_value_index_bool(row_idx, column_idx, &bool:destination);
  187. */
  188. stock cache_get_value_index_bool(row_idx, column_idx, &bool:destination)
  189. {
  190. return cache_get_value_index_int(row_idx, column_idx, _:destination);
  191. }
  192. native cache_is_value_index_null(row_idx, column_idx, &bool:destination);
  193. native cache_get_value_name(row_idx, const column_name[], destination[], max_len = sizeof(destination));
  194. native cache_get_value_name_int(row_idx, const column_name[], &destination);
  195. native cache_get_value_name_float(row_idx, const column_name[], &Float:destination);
  196. /*
  197. native cache_get_value_name_bool(row_idx, const column_name[], &bool:destination);
  198. */
  199. stock cache_get_value_name_bool(row_idx, const column_name[], &bool:destination)
  200. {
  201. return cache_get_value_name_int(row_idx, column_name, _:destination);
  202. }
  203. native cache_is_value_name_null(row_idx, const column_name[], &bool:destination);
  204. native Cache:cache_save();
  205. native cache_delete(Cache:cache_id);
  206. native cache_set_active(Cache:cache_id);
  207. native cache_unset_active();
  208. native bool:cache_is_any_active();
  209. native bool:cache_is_valid(Cache:cache_id);
  210. native cache_affected_rows();
  211. native cache_insert_id();
  212. native cache_warning_count();
  213. native cache_get_query_exec_time(E_MYSQL_EXECTIME_UNIT:unit = MICROSECONDS);
  214. native cache_get_query_string(destination[], max_len = sizeof(destination));
  215. // Forward declarations
  216. forward OnQueryError(errorid, const error[], const callback[], const query[], MySQL:handle);