PHP Code:
#include <amxmodx>
#include <sqlx>
#pragma defclasslib sqlite sqlite
#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "Author"
#define CREATE "CREATE TABLE IF NOT EXISTS example (steamid varchar(32), name varchar(32));"
#define CREATE2 "CREATE TABLE IF NOT EXISTS example (steamid TEXT, name TEXT);"
#define CREATE3 "CREATE TABLE IF NOT EXISTS stats (steamid TEXT, name TEXT);"
#define SQLITEFILE "SQLITE"
#define SQLITEFILESTATS "SQLITESTATS"
#define HOST "localhost"
#define USER "user"
#define PASS "PASSWORD"
#define DB_INFO "DB INFO"
new Handle:g_iTuple = Empty_Handle, QueryNum;
new QueryError[512]
enum(+=1)
{
SQLITE_TYPE = 0,
MYSQL_TYPE
}
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
set_task(2.0, "InitMYSQLQueries")
}
public InitMYSQLQueries()
{
PrepareTuple();
DoBasicInfo("mysql");
szData[0] = MYSQL_TYPE;
new szQuery[128]
new szData[3];
formatex(szQuery, charsmax(szQuery), CREATE);
server_print("Adding to %i queue at: %f", ++QueryNum, get_gametime());
szData[1] = QueryNum;
SQL_ThreadQuery(g_MySQL,"InitialMySQL_Handler",szQuery, szData, sizeof(szData))
DoBasicInfo("sqlite");
szData[0] = SQLITE_TYPE;
formatex( szQuery, charsmax(szQuery), CREATE2)
server_print("Adding to %i queue at: %f", ++QueryNum, get_gametime())
szData[1] = QueryNum;
SQL_ThreadQuery(g_MySQLITE,"InitialMySQL_Handler", szQuery, szData, sizeof(szData))
formatex(szQuery, charsmax(szQuery), CREATE3)
server_print("Adding to %i queue at: %f", ++QueryNum, get_gametime())
szData[1] = QueryNum;
SQL_ThreadQuery(g_MySQLITESTATS,"InitialMySQL_Handler", szQuery, szData, sizeof(szData))
}
GetAffinityType(const type, szType[], len)
{
switch( type )
{
MYSQL_TYPE: copy(szType, len, "mysql");
SQLITE_TYPE: copy(szType, len, "sqlite");
}
}
DoBasicInfo(const wanted_type[]="mysql")
{
new affinity[12];
SQL_GetAffinity(affinity, charsmax(affinity))
server_print("SQLX Affinity: %s", affinity)
server_print("SQLX Wanted: %s", wanted_type)
if (!equal(wanted_type, affinity))
{
if(g_iTuple != Empty_Handle)
{
SQL_FreeHandle(g_iTupe)
g_iTupe = Empty_Handle
}
new res = SQL_SetAffinity(wanted_type)
server_print("Setting affinity from %s to %s: %s",
affinity,
wanted_type,
res ? "Success" : "Failed")
SQL_GetAffinity(affinity, 11)
PrepareTuple();
server_print("Verification: %s", affinity)
}
}
PrepareTuple()
{
g_iTuple = SQL_MakeDbTuple(HOST,USER,PASS,DB_INFO);
}
public InitialMySQL_Handler(FailState, Handle:Query, Error[], Errcode, Data[], DataSize, Float:queuetime)
{
new wanted_type[12];
GetAffinityType(Data[0], wanted_type, charsmax(wanted_type));
DoBasicInfo(wanted_type);
server_print(" --> Resolved query %d, took %f seconds", Data[1], queuetime)
if(FailState == TQUERY_CONNECT_FAILED)
log_amx("Load - Could not connect to SQL database. [%d] %s", Errcode, Error)
else if(FailState == TQUERY_QUERY_FAILED)
{
log_amx("Could not execute query ^"%s^"",QueryError)
}
if(!SQL_NumRows(Query))
{
server_print("No Results.")
}
else
server_print("Found some rows in the table!.")
}