Advertisement
Guest User

Untitled

a guest
Jan 2nd, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.75 KB | None | 0 0
  1. /**
  2. * MySQL plugin R31
  3. */
  4.  
  5. #if defined mysql_included
  6. #endinput
  7. #endif
  8. #define mysql_included
  9.  
  10. /**
  11. * Common error codes
  12. *
  13. * Client: http://dev.mysql.com/doc/refman/5.1/en/error-messages-client.html
  14. * Server: http://dev.mysql.com/doc/refman/5.1/en/error-messages-server.html
  15. */
  16.  
  17. #define ER_DBACCESS_DENIED_ERROR 1044
  18. #define ER_ACCESS_DENIED_ERROR 1045
  19. #define ER_UNKNOWN_TABLE 1109
  20. #define ER_SYNTAX_ERROR 1149
  21. #define CR_SERVER_GONE_ERROR 2006
  22. #define CR_SERVER_LOST 2013
  23. #define CR_COMMAND_OUT_OF_SYNC 2014
  24. #define CR_SERVER_LOST_EXTENDED 2055
  25.  
  26. enum e_LogLevel {
  27. LOG_NONE = 0,
  28. LOG_ERROR = 1,
  29. LOG_WARNING = 2,
  30. LOG_DEBUG = 4
  31. };
  32.  
  33. enum e_LogType {
  34. LOG_TYPE_TEXT = 1,
  35. LOG_TYPE_HTML = 2
  36. };
  37.  
  38.  
  39. #define mysql_insert_id cache_insert_id
  40. #define mysql_affected_rows cache_affected_rows
  41. #define mysql_warning_count cache_warning_count
  42. #define mysql_real_escape_string mysql_escape_string
  43.  
  44. // cache_get_field
  45. #define cache_get_field(%0) cache_get_field_name(%0)
  46.  
  47. // mysql_function_query(conHandle, query[], bool:cache, callback[], format[], {Float,_}:...);
  48. #define mysql_function_query(%0,%1,%2,%3,"%4"%5) mysql_tquery(%0,%1,%3,#%4%5)
  49.  
  50. // mysql_fetch_row(destination)
  51. #define mysql_fetch_row(%1) mysql_fetch_row_format(%1,"|")
  52.  
  53. // mysql_next_row()
  54. #define mysql_next_row() mysql_retrieve_row()
  55.  
  56. // mysql_get_field(fieldname, destination)
  57. #define mysql_get_field(%1,%2) mysql_fetch_field_row(%2,%1)
  58.  
  59. // ismysqlnull(string[])
  60. #define ismysqlnull(%1) \
  61. (strcmp(%1,"NULL",false)==0)
  62.  
  63.  
  64.  
  65. // Natives
  66. native mysql_log(loglevel = LOG_ERROR | LOG_WARNING, logtype = LOG_TYPE_TEXT);
  67. native mysql_connect(const host[], const user[], const database[], const password[], port = 3306, bool:autoreconnect = true);
  68. native mysql_close(connectionHandle = 1, bool:wait = true);
  69. native mysql_reconnect(connectionHandle = 1);
  70.  
  71. native mysql_errno(connectionHandle = 1);
  72. native mysql_escape_string(const source[], destination[], connectionHandle = 1, max_len=sizeof(destination));
  73. native mysql_format(connectionHandle, output[], len, format[], {Float,_}:...);
  74. native mysql_tquery(connectionHandle, query[], callback[], format[], {Float,_}:...);
  75. /*
  76. native mysql_function_query(conHandle, query[], bool:cache, callback[], format[], {Float,_}:...); //DEPRECATED
  77. */
  78.  
  79. native mysql_stat(destination[], connectionHandle = 1, max_len=sizeof(destination));
  80. native mysql_get_charset(destination[], connectionHandle = 1, max_len=sizeof(destination));
  81. native mysql_set_charset(charset[], connectionHandle = 1);
  82.  
  83.  
  84.  
  85. // Cache functions.
  86. native cache_get_data(&num_rows, &num_fields, connectionHandle = 1);
  87. native cache_get_field_name(field_index, destination[], connectionHandle = 1, max_len=sizeof(destination));
  88.  
  89. native cache_get_row(row, idx, destination[], connectionHandle = 1, max_len=sizeof(destination));
  90. native cache_get_row_int(row, idx, connectionHandle = 1);
  91. native Float:cache_get_row_float(row, idx, connectionHandle = 1);
  92.  
  93. native cache_get_field_content(row, const field_name[], destination[], connectionHandle = 1, max_len=sizeof(destination));
  94. native cache_get_field_content_int(row, const field_name[], connectionHandle = 1);
  95. native Float:cache_get_field_content_float(row, const field_name[], connectionHandle = 1);
  96.  
  97. native cache_save(connectionHandle = 1);
  98. native cache_delete(cacheID, connectionHandle = 1);
  99. native cache_set_active(cacheID, connectionHandle = 1);
  100.  
  101. native cache_affected_rows(connectionHandle = 1);
  102. native cache_insert_id(connectionHandle = 1);
  103. native cache_warning_count(connectionHandle = 1);
  104.  
  105.  
  106. #if defined MYSQL_USE_YINLINE
  107. #include <YSI\y_inline.inc>
  108.  
  109. new g_MySQL_InlineData[500][E_CALLBACK_DATA];
  110. new g_MySQL_InlineCounter = 0;
  111.  
  112. stock MySQL_Internal_SaveInline(callback:CB) {
  113. new InlineData[E_CALLBACK_DATA];
  114. if (Callback_Get(CB, InlineData))
  115. {
  116. g_MySQL_InlineCounter++;
  117. g_MySQL_InlineData[g_MySQL_InlineCounter] = InlineData;
  118. }
  119. }
  120.  
  121. #define mysql_tquery_inline(%0,%1,%2,"%3"%4) \
  122. MySQL_Internal_SaveInline(%2); \
  123. mysql_tquery(%0,%1,"FJ37DH3JG_MYSQL_INTERNAL","d"#%3,g_MySQL_InlineCounter%4)
  124.  
  125.  
  126. forward FJ37DH3JG_MYSQL_INTERNAL(...);
  127. public FJ37DH3JG_MYSQL_INTERNAL(...) {
  128. new VarArray[32];
  129. new AddressArray[32];
  130. for(new i=0; i < numargs()-1; ++i) {
  131. VarArray[i] = getarg(i+1);
  132. AddressArray[i] = AMX_GetRelativeAddress(VarArray[i]);
  133. }
  134. Callback_Array(g_MySQL_InlineData[getarg(0)], AddressArray);
  135. }
  136. #endif
  137.  
  138. // Wrappers for cache functions
  139. stock mysql_reload(connectionHandle = 1) {
  140. mysql_tquery(connectionHandle, "FLUSH PRIVILEGES", "", "");
  141. return 1;
  142. }
  143.  
  144. static RowIndex[20];
  145. static bool:RetrieveRow[20];
  146. stock mysql_store_result(connectionHandle = 1) {
  147. RowIndex[connectionHandle] = 0;
  148. RetrieveRow[connectionHandle] = false;
  149.  
  150. }
  151. stock mysql_free_result(connectionHandle = 1) {
  152. #pragma unused connectionHandle
  153. }
  154. stock mysql_num_rows(connectionHandle = 1) {
  155. new Rows, Fields;
  156. cache_get_data(Rows, Fields, connectionHandle);
  157. return Rows;
  158. }
  159. stock mysql_num_fields(connectionHandle = 1) {
  160. new Rows, Fields;
  161. cache_get_data(Rows, Fields, connectionHandle);
  162. return Fields;
  163. }
  164. stock mysql_retrieve_row(connectionHandle = 1) {
  165. if(RetrieveRow[connectionHandle] != false)
  166. RowIndex[connectionHandle]++;
  167. else
  168. RetrieveRow[connectionHandle] = true;
  169.  
  170. if(RowIndex[connectionHandle] >= mysql_num_rows(connectionHandle))
  171. return 0;
  172. return 1;
  173. }
  174. stock mysql_data_seek(offset, connectionHandle = 1) {
  175. new Rows = mysql_num_rows(connectionHandle);
  176. if(offset < 0)
  177. offset = 0;
  178. else if(offset >= Rows)
  179. offset = Rows-1;
  180. RowIndex[connectionHandle] = offset;
  181. }
  182. stock mysql_fetch_field(number, destination[], connectionHandle = 1, max_len=sizeof(destination)) {
  183. strdel(destination, 0, max_len-1);
  184. return cache_get_field(number, destination, connectionHandle, max_len);
  185. }
  186. stock mysql_fetch_field_row(destination[], const fieldname[], connectionHandle = 1, max_len=sizeof(destination)) {
  187. strdel(destination, 0, max_len-1);
  188. new RIDX = RowIndex[connectionHandle];
  189. cache_get_field_content(RIDX < 0 ? 0 : RIDX, fieldname, destination, connectionHandle, max_len);
  190. }
  191. stock mysql_fetch_row_format(destination[], const delimiter[] = "|", connectionHandle = 1, max_len=sizeof(destination)) {
  192. strdel(destination, 0, max_len-1);
  193. new Fields = mysql_num_fields(connectionHandle);
  194. for(new f=0; f < Fields; f++) {
  195. if(f != 0) {
  196. strcat(destination, delimiter, max_len);
  197.  
  198. }
  199. new row_val_tmp[512];
  200. new RIDX = RowIndex[connectionHandle];
  201. cache_get_row(RIDX < 0 ? 0 : RIDX, f, row_val_tmp, connectionHandle);
  202. if(f == 0)
  203. strins(destination, row_val_tmp, 0, max_len);
  204. else
  205. strcat(destination, row_val_tmp, max_len);
  206. }
  207. }
  208.  
  209.  
  210.  
  211. // Forward declarations.
  212. forward OnQueryError(errorid, error[], callback[], query[], connectionHandle);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement