Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * native MysqlEscapeString(string[])
- * native MysqlQuery(query[], forward[])
- */
- #include <amxmodx>
- #include <sqlx>
- #define PLUGIN "Mysql CORE"
- #define VERSION "1.0"
- #define AUTHOR "Author"
- #define DB_HOST "localhost"
- #define DB_USER "root"
- #define DB_PASS ""
- #define DB_DATA "apps"
- new Handle:SQL_Con = Empty_Handle
- new Handle:SQL_Tuple = Empty_Handle
- native MysqlQuery(query[], fwd[])
- enum _:DATAS
- {
- FUNC,
- PLID
- }
- public plugin_init()
- {
- register_plugin(PLUGIN, VERSION, AUTHOR)
- }
- public plugin_precache()
- {
- StartMysql()
- }
- StartMysql()
- {
- SQL_Tuple = SQL_MakeDbTuple(DB_HOST, DB_USER, DB_PASS, DB_DATA)
- new errno, error[128]
- SQL_Con = SQL_Connect(SQL_Tuple, errno, error, charsmax(error))
- if(SQL_Con == Empty_Handle)
- {
- set_fail_state("[MYSQL] %s", error);
- }
- //mysql_performance(30, 30, 6)
- }
- public plugin_end()
- {
- SQL_FreeHandle(SQL_Con)
- }
- public plugin_natives()
- {
- register_native("MysqlQuery", "OnSetQuery")
- register_native("MysqlEscapeString", "OnEscapeString")
- }
- public OnSetQuery(pl,pr)
- {
- new sz[256], fwd[32]
- get_string(1,sz,charsmax(sz))
- get_string(2, fwd, charsmax(fwd))
- new data[DATAS]
- if((data[FUNC] = get_func_id(fwd, pl)) == -1)
- {
- new plname[32]
- get_plugin(pl, plname, charsmax(plname))
- server_print("[AMXX] [%s] Funcion %s no esta presente", plname, fwd)
- return
- }
- data[PLID] = pl
- SQL_ThreadQuery(SQL_Tuple, "QueryExcecuted", sz, data, DATAS)
- }
- public QueryExcecuted(failstate, Handle:query, error[], errnum, data[], size, Float:queuetime)
- {
- if(failstate != TQUERY_SUCCESS)
- {
- log_amx("[AMXX] %s", error)
- return;
- }
- callfunc_begin_i(data[FUNC], data[PLID])
- callfunc_push_int(any:query)
- callfunc_end()
- }
- public OnEscapeString()
- {
- new string[64]
- get_string(1, string, charsmax(string))
- replace_all(string, charsmax(string), "\", "\\")
- replace_all(string, charsmax(string), "^"", "\^"")
- replace_all(string, charsmax(string), "'", "\'")
- set_string(1, string, strlen(string)-1)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement