| gameplayonline |
07-01-2017 22:01 |
Re: SQLX How to get coluumn with highest number?
If it will help somebody i fixed it with this:
Code:
public register_client(FailState,Handle:Query,Error[],Errcode,Data[],DataSize)
{
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("Load Query failed. [%d] %s", Errcode, Error)
}
new id
id = Data[0]
if(SQL_NumResults(Query) < 1)
{
//.if there are no results found
new szSteamId[32]
get_user_authid(id, szSteamId, charsmax(szSteamId)) // get user's steamid
// if its still pending we can't do anything with it
if (equal(szSteamId,"ID_PENDING"))
return PLUGIN_HANDLED
new szTemp[512]
// now we will insturt the values into our table.
format(szTemp,charsmax(szTemp),"INSERT INTO `player` ( `SteamID` , `UID`, `Referrals`, `isReferral`)VALUES ('%s','%d','%d','%d');",szSteamId, uid, referrals, isReferral)
SQL_ThreadQuery(g_SqlTuple,"IgnoreHandle",szTemp)
addId(id)
}
else
{
client_print(id, print_chat, "Uz si bol zaregistrovany, napis /uid pre zistenie UID")
}
return PLUGIN_CONTINUE
}
public addId(id)
{
// READ MAIN DATA
new Data[1]
Data[0] = id
// ok, we're ready to connect
new ErrorCode,Handle:SqlConnection = SQL_Connect(g_SqlTuple,ErrorCode,g_Error,charsmax(g_Error))
if(SqlConnection == Empty_Handle)
// stop the plugin with an error message
set_fail_state(g_Error)
new Handle:Query2
Query2 = SQL_PrepareQuery(SqlConnection, "SELECT MAX(UID) FROM player")
SQL_Execute(Query2)
if(SQL_NumResults(Query2) == 1)
{
//.if there are no results found
new szTemp[512]
new szSteamId[32]
get_user_authid(id, szSteamId, charsmax(szSteamId)) // get user's steamid
// if its still pending we can't do anything with it
if (equal(szSteamId,"ID_PENDING"))
return PLUGIN_HANDLED
new num = SQL_ReadResult(Query2, 0)
client_print(id, print_chat, "num %d", num)
new addUid = num + 1
client_print(id, print_chat, "addid +1 = %d", addUid)
format(szTemp,charsmax(szTemp),"UPDATE `player` SET `UID` = '%d' WHERE `player`.`SteamID` = '%s';", addUid, szSteamId);
SQL_ThreadQuery(g_SqlTuple,"IgnoreHandle",szTemp)
client_print(id, print_chat, "Uspesne si sa zaregistroval do referral systemu. Napis /uid aby si zistil svoje UID")
}
else
{
client_print(id, print_chat, "Chyba")
}
SQL_FreeHandle(Query2)
// you free everything with SQL_FreeHandle
SQL_FreeHandle(SqlConnection)
return PLUGIN_CONTINUE
}
|