Guest User

Untitled

a guest
May 17th, 2015
360
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.76 KB | None | 0 0
  1. /**
  2. * MySQL plugin R39-3
  3. */
  4.  
  5.  
  6. #if defined mysql_included
  7. #endinput
  8. #endif
  9. #define mysql_included
  10.  
  11.  
  12. /**
  13. * Common error codes
  14. *
  15. * Client: http://dev.mysql.com/doc/refman/5.1/en/error-messages-client.html
  16. * Server: http://dev.mysql.com/doc/refman/5.1/en/error-messages-server.html
  17. */
  18.  
  19. #define ER_DBACCESS_DENIED_ERROR 1044
  20. #define ER_ACCESS_DENIED_ERROR 1045
  21. #define ER_UNKNOWN_TABLE 1109
  22. #define ER_SYNTAX_ERROR 1149
  23. #define CR_SERVER_GONE_ERROR 2006
  24. #define CR_SERVER_LOST 2013
  25. #define CR_COMMAND_OUT_OF_SYNC 2014
  26. #define CR_SERVER_LOST_EXTENDED 2055
  27.  
  28.  
  29. enum E_LOGLEVEL
  30. {
  31. LOG_NONE = 0,
  32. LOG_ERROR = 1,
  33. LOG_WARNING = 2,
  34. LOG_DEBUG = 4,
  35.  
  36. LOG_ALL = LOG_ERROR | LOG_WARNING | LOG_DEBUG
  37. };
  38.  
  39. enum E_LOGTYPE
  40. {
  41. LOG_TYPE_TEXT = 1,
  42. LOG_TYPE_HTML = 2
  43. };
  44.  
  45. enum ORM_Error
  46. {
  47. ERROR_OK,
  48. ERROR_NO_DATA
  49. };
  50.  
  51. enum E_VAR_DATATYPE
  52. {
  53. DATATYPE_INT,
  54. DATATYPE_FLOAT,
  55. DATATYPE_STRING
  56. };
  57.  
  58. enum E_MYSQL_OPTION
  59. {
  60. DUPLICATE_CONNECTIONS,
  61. LOG_TRUNCATE_DATA
  62. };
  63.  
  64. enum E_EXECTIME_UNIT
  65. {
  66. UNIT_MILLISECONDS,
  67. UNIT_MICROSECONDS
  68. };
  69.  
  70.  
  71. #define mysql_real_escape_string mysql_escape_string
  72. #define cache_num_fields cache_get_field_count
  73. #define cache_num_rows cache_get_row_count
  74. #define mysql_function_query(%0,%1,%2,%3,"%4"%5) mysql_tquery(%0,%1,%3,#%4%5)
  75. #define mysql_reload(%0) mysql_tquery(%0,"FLUSH PRIVILEGES")
  76. #define mysql_debug(%0) (%0?mysql_log(LOG_ALL):mysql_log())
  77. #define ismysqlnull(%0) (strcmp(%0,"NULL",false)==0)
  78.  
  79.  
  80. // ORM functions
  81. native ORM:orm_create(const table[], connectionHandle = 1);
  82. native orm_destroy(ORM:id);
  83.  
  84. native ORM_Error:orm_errno(ORM:id);
  85.  
  86. native orm_apply_cache(ORM:id, row);
  87. native orm_select(ORM:id, callback[] = "", format[] = "", {Float, _}:...);
  88. /*
  89. native orm_select_inline(ORM:id, callback:Callback, format[], {Float,_}:...); //y_inline
  90. */
  91. native orm_update(ORM:id);
  92. native orm_insert(ORM:id, callback[] = "", format[] = "", {Float, _}:...);
  93. /*
  94. native orm_insert_inline(ORM:id, callback:Callback, format[], {Float,_}:...); //y_inline
  95. */
  96. native orm_delete(ORM:id, bool:clearvars=true);
  97.  
  98. native orm_load(ORM:id, callback[] = "", format[] = "", {Float, _}:...) = orm_select;
  99. native orm_save(ORM:id, callback[] = "", format[] = "", {Float, _}:...);
  100.  
  101. native orm_addvar_int(ORM:id, &var, varname[]);
  102. native orm_addvar_float(ORM:id, &Float:var, varname[]);
  103. native orm_addvar_string(ORM:id, var[], var_maxlen, varname[]);
  104.  
  105. native orm_delvar(ORM:id, varname[]);
  106. native orm_setkey(ORM:id, varname[]);
  107.  
  108.  
  109. // MySQL functions
  110. native mysql_log(E_LOGLEVEL:loglevel = LOG_ERROR | LOG_WARNING, E_LOGTYPE:logtype = LOG_TYPE_TEXT);
  111. native mysql_connect(const host[], const user[], const database[], const password[], port = 3306, bool:autoreconnect = true, pool_size = 2);
  112. native mysql_close(connectionHandle = 1);
  113. native mysql_reconnect(connectionHandle = 1);
  114.  
  115. native mysql_unprocessed_queries(connectionHandle = 1);
  116. native mysql_current_handle();
  117. native mysql_option(E_MYSQL_OPTION:type, value);
  118.  
  119. native mysql_errno(connectionHandle = 1);
  120. native mysql_escape_string(const source[], destination[], connectionHandle = 1, max_len = sizeof(destination));
  121. native mysql_format(connectionHandle, output[], len, format[], {Float,_}:...);
  122. native mysql_pquery(connectionHandle, query[], callback[] = "", format[] = "", {Float,_}:...);
  123. /*
  124. native mysql_pquery_inline(connHandle, query[], callback:Callback, format[], {Float,_}:...); //y_inline
  125. */
  126. native mysql_tquery(connectionHandle, query[], callback[] = "", format[] = "", {Float,_}:...);
  127. /*
  128. native mysql_tquery_inline(connHandle, query[], callback:Callback, format[], {Float,_}:...); //y_inline
  129. */
  130. native Cache:mysql_query(conhandle, query[], bool:use_cache = true);
  131.  
  132. native mysql_stat(destination[], connectionHandle = 1, max_len = sizeof(destination));
  133. native mysql_get_charset(destination[], connectionHandle = 1, max_len = sizeof(destination));
  134. native mysql_set_charset(charset[], connectionHandle = 1);
  135.  
  136.  
  137. // Cache functions
  138. native cache_get_data(&num_rows, &num_fields, connectionHandle = 1);
  139. native cache_get_row_count(connectionHandle = 1);
  140. native cache_get_field_count(connectionHandle = 1);
  141. native cache_get_field_name(field_index, destination[], connectionHandle = 1, max_len = sizeof(destination));
  142.  
  143. native cache_get_row(row, field_idx, destination[], connectionHandle = 1, max_len = sizeof(destination));
  144. native cache_get_row_int(row, field_idx, connectionHandle = 1);
  145. native Float:cache_get_row_float(row, field_idx, connectionHandle = 1);
  146.  
  147. native cache_get_field_content(row, const field_name[], destination[], connectionHandle = 1, max_len = sizeof(destination));
  148. native cache_get_field_content_int(row, const field_name[], connectionHandle = 1);
  149. native Float:cache_get_field_content_float(row, const field_name[], connectionHandle = 1);
  150.  
  151. native Cache:cache_save(connectionHandle = 1);
  152. native cache_delete(Cache:cache_id, connectionHandle = 1);
  153. native cache_set_active(Cache:cache_id, connectionHandle = 1);
  154. native cache_is_valid(Cache:cache_id, connectionHandle = 1);
  155.  
  156. native cache_affected_rows(connectionHandle = 1);
  157. native cache_insert_id(connectionHandle = 1);
  158. native cache_warning_count(connectionHandle = 1);
  159.  
  160. native cache_get_query_exec_time(E_EXECTIME_UNIT:unit = UNIT_MICROSECONDS);
  161. native cache_get_query_string(destination[], max_len = sizeof(destination));
  162.  
  163.  
  164. // Forward declarations
  165. forward OnQueryError(errorid, error[], callback[], query[], connectionHandle);
  166.  
  167.  
  168. #if defined MYSQL_USE_YINLINE || defined E_CALLBACK_DATA
  169. #if !defined E_CALLBACK_DATA
  170. #include <YSI\y_inline>
  171. #endif
  172.  
  173. static g_MySQL_InlineData[1000][E_CALLBACK_DATA];
  174. static g_MySQL_VarArray[32][YSI_MAX_STRING];
  175. static g_MySQL_AddressArray[32];
  176.  
  177. stock MySQL_Internal_SaveInline(callback:CB)
  178. {
  179. static bool:g_MySQL_LazyInit = true;
  180. if(g_MySQL_LazyInit == true)
  181. {
  182. //set g_MySQL_InlineData empty
  183. for(new i=0; i < sizeof(g_MySQL_InlineData); ++i)
  184. for(new E_CALLBACK_DATA:e = E_CALLBACK_DATA:0; e < E_CALLBACK_DATA; ++e)
  185. g_MySQL_InlineData[i][e] = 0;
  186. g_MySQL_LazyInit = false;
  187. }
  188.  
  189. for(new i=0; i < sizeof(g_MySQL_InlineData); ++i)
  190. if(_:g_MySQL_InlineData[i][E_CALLBACK_DATA_POINTER] == 0)
  191. if (Callback_Get(CB, g_MySQL_InlineData[i]))
  192. return i;
  193.  
  194. return -1;
  195. }
  196.  
  197. #define mysql_pquery_inline(%0,%1,%2,"%3"%4) \
  198. mysql_pquery(%0,%1,"FJ37DH3JG_MYSQL_INTERNAL","d"#%3,MySQL_Internal_SaveInline(%2)%4)
  199.  
  200. #define mysql_tquery_inline(%0,%1,%2,"%3"%4) \
  201. mysql_tquery(%0,%1,"FJ37DH3JG_MYSQL_INTERNAL","d"#%3,MySQL_Internal_SaveInline(%2)%4)
  202.  
  203. #define orm_select_inline(%0,%1,"%2"%3) \
  204. orm_select(%0,"FJ37DH3JG_MYSQL_INTERNAL","d"#%2,MySQL_Internal_SaveInline(%1)%3)
  205.  
  206. #define orm_insert_inline(%0,%1,"%2"%3) \
  207. orm_insert(%0,"FJ37DH3JG_MYSQL_INTERNAL","d"#%2,MySQL_Internal_SaveInline(%1)%3)
  208.  
  209.  
  210. forward FJ37DH3JG_MYSQL_INTERNAL(...);
  211. public FJ37DH3JG_MYSQL_INTERNAL(...)
  212. {
  213. new InlineDataIndex = getarg(0);
  214. if(InlineDataIndex < 0)
  215. return 0;
  216.  
  217. for(new i=0; i < numargs()-1; ++i)
  218. {
  219. for(new l=0; l < YSI_MAX_STRING; ++l)
  220. {
  221. new TmpVal = getarg(i+1, l);
  222. if(l == 0 || g_MySQL_VarArray[i][l-1] < 256)
  223. g_MySQL_VarArray[i][l] = TmpVal;
  224. else
  225. break;
  226. }
  227.  
  228. g_MySQL_AddressArray[i] = AMX_GetRelativeAddress(g_MySQL_VarArray[i][0]);
  229. }
  230.  
  231. Callback_Array(g_MySQL_InlineData[InlineDataIndex], g_MySQL_AddressArray);
  232.  
  233. Callback_Release(g_MySQL_InlineData[InlineDataIndex]);
  234. for(new E_CALLBACK_DATA:e = E_CALLBACK_DATA:0; e < E_CALLBACK_DATA; ++e)
  235. g_MySQL_InlineData[InlineDataIndex][e] = 0;
  236.  
  237. for(new i=0; i < numargs()-1; ++i)
  238. {
  239. g_MySQL_AddressArray[i] = 0;
  240. for(new l=0, lmax=strlen(g_MySQL_VarArray[i]); l < lmax; ++l)
  241. g_MySQL_VarArray[i][l] = 0;
  242. }
  243. return 1;
  244. }
  245. #endif
Advertisement
Add Comment
Please, Sign In to add comment