Advertisement
Guest User

Untitled

a guest
Jan 3rd, 2023
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 7.70 KB | None | 0 0
  1. /**
  2.  * MySQL plugin R39-6
  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_MYSQL_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_MYSQL_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_MYSQL_OPTION
  52. {
  53.     DUPLICATE_CONNECTIONS,
  54.     LOG_TRUNCATE_DATA
  55. };
  56.  
  57. enum E_EXECTIME_UNIT
  58. {
  59.     UNIT_MILLISECONDS,
  60.     UNIT_MICROSECONDS
  61. };
  62.  
  63.  
  64. #define mysql_real_escape_string                    mysql_escape_string
  65. #define cache_num_fields                            cache_get_field_count
  66. #define cache_num_rows                              cache_get_row_count
  67. #define mysql_function_query(%0,%1,%2,%3,"%4"%5)    mysql_tquery(%0,%1,%3,#%4%5)
  68. #define mysql_reload(%0)                            mysql_tquery(%0,"FLUSH PRIVILEGES")
  69. #define mysql_debug(%0)                             (%0?mysql_log(LOG_ALL):mysql_log())
  70. #define ismysqlnull(%0)                             (strcmp(%0,"NULL",false)==0)
  71.  
  72.  
  73. // ORM functions
  74. native ORM:orm_create(const table[], connectionHandle = 1);
  75. native orm_destroy(ORM:id);
  76.  
  77. native ORM_Error:orm_errno(ORM:id);
  78.  
  79. native orm_apply_cache(ORM:id, row);
  80. native orm_select(ORM:id, callback[] = "", format[] = "", {Float, _}:...);
  81. /*
  82. native orm_select_inline(ORM:id, callback:Callback, format[], {Float,_}:...); //y_inline
  83. */
  84. native orm_update(ORM:id);
  85. native orm_insert(ORM:id, callback[] = "", format[] = "", {Float, _}:...);
  86. /*
  87. native orm_insert_inline(ORM:id, callback:Callback, format[], {Float,_}:...); //y_inline
  88. */
  89. native orm_delete(ORM:id, bool:clearvars=true);
  90.  
  91. native orm_load(ORM:id, callback[] = "", format[] = "", {Float, _}:...) = orm_select;
  92. native orm_save(ORM:id, callback[] = "", format[] = "", {Float, _}:...);
  93.  
  94. native orm_addvar_int(ORM:id, &var, varname[]);
  95. native orm_addvar_float(ORM:id, &Float:var, varname[]);
  96. native orm_addvar_string(ORM:id, var[], var_maxlen, varname[]);
  97.  
  98. native orm_delvar(ORM:id, varname[]);
  99. native orm_setkey(ORM:id, varname[]);
  100.  
  101.  
  102. // MySQL functions
  103. native mysql_log(E_MYSQL_LOGLEVEL:loglevel = LOG_ERROR | LOG_WARNING, E_MYSQL_LOGTYPE:logtype = LOG_TYPE_TEXT);
  104. native mysql_connect(const host[], const user[], const database[], const password[], port = 3306, bool:autoreconnect = true, pool_size = 2);
  105. native mysql_close(connectionHandle = 1);
  106. native mysql_reconnect(connectionHandle = 1);
  107.  
  108. native mysql_unprocessed_queries(connectionHandle = 1);
  109. native mysql_current_handle();
  110. native mysql_option(E_MYSQL_OPTION:type, value);
  111.  
  112. native mysql_errno(connectionHandle = 1);
  113. native mysql_escape_string(const source[], destination[], connectionHandle = 1, max_len = sizeof(destination));
  114. native mysql_format(connectionHandle, output[], len, format[], {Float,_}:...);
  115. native mysql_pquery(connectionHandle, query[], callback[] = "", format[] = "", {Float,_}:...);
  116. /*
  117. native mysql_pquery_inline(connHandle, query[], callback:Callback, format[], {Float,_}:...); //y_inline
  118. */
  119. native mysql_tquery(connectionHandle, query[], callback[] = "", format[] = "", {Float,_}:...);
  120. /*
  121. native mysql_tquery_inline(connHandle, query[], callback:Callback, format[], {Float,_}:...); //y_inline
  122. */
  123. native Cache:mysql_query(conhandle, query[], bool:use_cache = true);
  124.  
  125. native mysql_stat(destination[], connectionHandle = 1, max_len = sizeof(destination));
  126. native mysql_get_charset(destination[], connectionHandle = 1, max_len = sizeof(destination));
  127. native mysql_set_charset(charset[], connectionHandle = 1);
  128.  
  129.  
  130. // Cache functions
  131. native cache_get_data(&num_rows, &num_fields, connectionHandle = 1);
  132. native cache_get_row_count(connectionHandle = 1);
  133. native cache_get_field_count(connectionHandle = 1);
  134. native cache_get_field_name(field_index, destination[], connectionHandle = 1, max_len = sizeof(destination));
  135.  
  136. native cache_get_row(row, field_idx, destination[], connectionHandle = 1, max_len = sizeof(destination));
  137. native cache_get_row_int(row, field_idx, connectionHandle = 1);
  138. native Float:cache_get_row_float(row, field_idx, connectionHandle = 1);
  139.  
  140. native cache_get_field_content(row, const field_name[], destination[], connectionHandle = 1, max_len = sizeof(destination));
  141. native cache_get_field_content_int(row, const field_name[], connectionHandle = 1);
  142. native Float:cache_get_field_content_float(row, const field_name[], connectionHandle = 1);
  143.  
  144. native Cache:cache_save(connectionHandle = 1);
  145. native cache_delete(Cache:cache_id, connectionHandle = 1);
  146. native cache_set_active(Cache:cache_id, connectionHandle = 1);
  147. native cache_is_valid(Cache:cache_id, connectionHandle = 1);
  148.  
  149. native cache_affected_rows(connectionHandle = 1);
  150. native cache_insert_id(connectionHandle = 1);
  151. native cache_warning_count(connectionHandle = 1);
  152.  
  153. native cache_get_query_exec_time(E_EXECTIME_UNIT:unit = UNIT_MICROSECONDS);
  154. native cache_get_query_string(destination[], max_len = sizeof(destination));
  155.  
  156.  
  157. // Forward declarations
  158. forward OnQueryError(errorid, error[], callback[], query[], connectionHandle);
  159.  
  160.  
  161. #if defined MYSQL_USE_YINLINE || defined E_CALLBACK_DATA
  162.     #if !defined E_CALLBACK_DATA
  163.         #include <YSI\y_inline>
  164.     #endif
  165.    
  166.     static g_MySQL_InlineData[1000][E_CALLBACK_DATA];
  167.     static g_MySQL_VarArray[32][YSI_MAX_STRING];
  168.     static g_MySQL_AddressArray[32];
  169.  
  170.     stock MySQL_Internal_SaveInline(callback:CB)
  171.     {
  172.         static bool:g_MySQL_LazyInit = true;
  173.         if(g_MySQL_LazyInit == true)
  174.         {
  175.             //set g_MySQL_InlineData empty
  176.             for(new i=0; i < sizeof(g_MySQL_InlineData); ++i)
  177.                 for(new E_CALLBACK_DATA:e = E_CALLBACK_DATA:0; e < E_CALLBACK_DATA; ++e)
  178.                     g_MySQL_InlineData[i][e] = 0;
  179.             g_MySQL_LazyInit = false;
  180.         }
  181.        
  182.         for(new i=0; i < sizeof(g_MySQL_InlineData); ++i)
  183.             if(_:g_MySQL_InlineData[i][E_CALLBACK_DATA_POINTER] == 0)
  184.                 if (Callback_Get(CB, g_MySQL_InlineData[i]))
  185.                     return i;
  186.                    
  187.         return -1;
  188.     }
  189.    
  190.     #define mysql_pquery_inline(%0,%1,%2,"%3"%4) \
  191.         mysql_pquery(%0,%1,"FJ37DH3JG_MYSQL_INTERNAL","d"#%3,MySQL_Internal_SaveInline(%2)%4)
  192.        
  193.     #define mysql_tquery_inline(%0,%1,%2,"%3"%4) \
  194.         mysql_tquery(%0,%1,"FJ37DH3JG_MYSQL_INTERNAL","d"#%3,MySQL_Internal_SaveInline(%2)%4)
  195.    
  196.     #define orm_select_inline(%0,%1,"%2"%3) \
  197.         orm_select(%0,"FJ37DH3JG_MYSQL_INTERNAL","d"#%2,MySQL_Internal_SaveInline(%1)%3)
  198.    
  199.     #define orm_insert_inline(%0,%1,"%2"%3) \
  200.         orm_insert(%0,"FJ37DH3JG_MYSQL_INTERNAL","d"#%2,MySQL_Internal_SaveInline(%1)%3)
  201.  
  202.  
  203.     forward FJ37DH3JG_MYSQL_INTERNAL(...);
  204.     public FJ37DH3JG_MYSQL_INTERNAL(...)
  205.     {
  206.         new InlineDataIndex = getarg(0);
  207.         if(InlineDataIndex < 0)
  208.             return 0;
  209.        
  210.         for(new i=0; i < numargs()-1; ++i)
  211.         {
  212.             for(new l=0; l < YSI_MAX_STRING; ++l)
  213.             {
  214.                 new TmpVal = getarg(i+1, l);
  215.                 if(l == 0 || g_MySQL_VarArray[i][l-1] < 256)
  216.                     g_MySQL_VarArray[i][l] = TmpVal;
  217.                 else
  218.                     break;
  219.             }
  220.            
  221.             g_MySQL_AddressArray[i] = AMX_GetRelativeAddress(g_MySQL_VarArray[i][0]);
  222.         }
  223.        
  224.         Callback_Array(g_MySQL_InlineData[InlineDataIndex], g_MySQL_AddressArray);
  225.        
  226.         Callback_Release(g_MySQL_InlineData[InlineDataIndex]);
  227.         for(new E_CALLBACK_DATA:e = E_CALLBACK_DATA:0; e < E_CALLBACK_DATA; ++e)
  228.             g_MySQL_InlineData[InlineDataIndex][e] = 0;
  229.        
  230.         for(new i=0; i < numargs()-1; ++i)
  231.         {
  232.             g_MySQL_AddressArray[i] = 0;
  233.             for(new l=0, lmax=strlen(g_MySQL_VarArray[i]); l < lmax; ++l)
  234.                 g_MySQL_VarArray[i][l] = 0;
  235.         }
  236.         return 1;
  237.     }
  238. #endif
  239.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement