Advertisement
Sugisaki

[AMXX] Mysql Core

Feb 11th, 2019
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 1.98 KB | None | 0 0
  1. /*
  2. * native MysqlEscapeString(string[])
  3. * native MysqlQuery(query[], forward[])
  4. */
  5. #include <amxmodx>
  6. #include <sqlx>
  7.  
  8. #define PLUGIN  "Mysql CORE"
  9. #define VERSION "1.0"
  10. #define AUTHOR  "Author"
  11.  
  12. #define DB_HOST "localhost"
  13. #define DB_USER "root"
  14. #define DB_PASS ""
  15. #define DB_DATA "apps"
  16.  
  17. new Handle:SQL_Con = Empty_Handle
  18. new Handle:SQL_Tuple = Empty_Handle
  19. native MysqlQuery(query[], fwd[])
  20. enum _:DATAS
  21. {
  22.     FUNC,
  23.     PLID
  24. }
  25. public plugin_init()
  26. {
  27.     register_plugin(PLUGIN, VERSION, AUTHOR)
  28. }
  29. public plugin_precache()
  30. {
  31.     StartMysql()
  32. }
  33. StartMysql()
  34. {
  35.     SQL_Tuple = SQL_MakeDbTuple(DB_HOST, DB_USER, DB_PASS, DB_DATA)
  36.     new errno, error[128]
  37.     SQL_Con = SQL_Connect(SQL_Tuple, errno, error, charsmax(error))
  38.     if(SQL_Con == Empty_Handle)
  39.     {
  40.         set_fail_state("[MYSQL] %s", error);
  41.     }
  42.     //mysql_performance(30, 30, 6)
  43. }
  44. public plugin_end()
  45. {
  46.     SQL_FreeHandle(SQL_Con)
  47. }
  48. public plugin_natives()
  49. {
  50.     register_native("MysqlQuery", "OnSetQuery")
  51.     register_native("MysqlEscapeString", "OnEscapeString")
  52. }
  53. public OnSetQuery(pl,pr)
  54. {
  55.     new sz[256], fwd[32]
  56.     get_string(1,sz,charsmax(sz))
  57.     get_string(2, fwd, charsmax(fwd))
  58.     new data[DATAS]
  59.     if((data[FUNC] = get_func_id(fwd, pl)) == -1)
  60.     {
  61.         new plname[32]
  62.         get_plugin(pl, plname, charsmax(plname))
  63.         server_print("[AMXX] [%s] Funcion %s no esta presente", plname, fwd)
  64.         return
  65.     }
  66.     data[PLID] = pl
  67.     SQL_ThreadQuery(SQL_Tuple, "QueryExcecuted", sz, data, DATAS)
  68. }
  69. public QueryExcecuted(failstate, Handle:query, error[], errnum, data[], size, Float:queuetime)
  70. {
  71.     if(failstate != TQUERY_SUCCESS)
  72.     {
  73.         log_amx("[AMXX] %s", error)
  74.         return;
  75.     }
  76.     callfunc_begin_i(data[FUNC], data[PLID])
  77.     callfunc_push_int(any:query)
  78.     callfunc_end()
  79. }
  80. public OnEscapeString()
  81. {
  82.     new string[64]
  83.     get_string(1, string, charsmax(string))
  84.     replace_all(string, charsmax(string), "\", "\\")
  85.     replace_all(string, charsmax(string), "^"", "\^"")
  86.     replace_all(string, charsmax(string), "'", "\'")
  87.     set_string(1, string, strlen(string)-1)
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement