PDA

View Full Version : SQL_TQuery Problems :X


graczu
08-24-2007, 19:47
Hi i got this code in my plugin to get rank:

if somone say /rank starting this:

public GetMyRank(client){

if(userInit[client] == 1){

new String:steamId[64];
GetClientAuthString(client, steamId, sizeof(steamId));

decl String:buffer[512];
Format(buffer, sizeof(buffer), "SELECT * FROM css_rank WHERE steamId = '%s'", steamIdSave[client]);
if(DEBUG == 1){
PrintToServer("DEBUG: GetMyRank (%s)", buffer);
}
SQL_TQuery(db, SQLGetMyRank, buffer, client);

} else {

PrintToChat(client,"[RANK] Poczekaj na zaladowanie danych z Bazy");

}
}


This SQL_TQuery to SQLGetMyRank:

public SQLGetMyRank(Handle:owner, Handle:hndl, const String:error[], any:client){

decl RAkills;
decl RAdeaths;
decl RAheadshots;
decl RAsucsides;

if(SQL_FetchRow(hndl))
{
RAkills=SQL_FetchInt(hndl,0);
RAdeaths=SQL_FetchInt(hndl,1);
RAheadshots=SQL_FetchInt(hndl,2);
RAsucsides=SQL_FetchInt(hndl,3);

}

decl String:buffer[512];
Format(buffer, sizeof(buffer), "SELECT rank_id FROM css_rank WHERE kills >= '%i' AND deaths <= '%i'", RAkills, RAdeaths);
if(DEBUG == 1){
PrintToServer("DEBUG: SQLGetMyRank (%s)", buffer);
}
SQL_TQuery(db, SQLShowRank, buffer, client);
PrintToChat(client,"[STATS] Fragow: %i | Smierci: %i | Trafien w Glowe: %i | Samobojstw: %i", RAkills, RAdeaths, RAheadshots, RAsucsides);
}


and fin shows the rank:

public SQLShowRank(Handle:owner, Handle:hndl, const String:error[], any:client){

if (SQL_HasResultSet(hndl))
{
printRank(hndl, client)
} else {
PrintToChat(client,"[RANK] H@H@ nie ma cie w ranku n00b13.");
}
}


and problem is with that, when client say /rank

he gets some strange numbers in kills,deaths (34346346346, -234535),.... and strange rank like 3453464567457457 or -43534643576

what is wrong in here?

i attach whole plugin

Nican
08-24-2007, 19:56
Change the query to:

SELECT kills, deaths, headshots, sucsides FROM css_rank WHERE steamId = '%s'

graczu
08-24-2007, 20:06
i was got that query to, and there was the same problem.

Nican
08-24-2007, 20:14
ok.. I think you meant:
--I tried that query too, but it did not solve the problem.

I am sure the query is there is wrong but I am not sure about this:
try changing

decl RAkills;
decl RAdeaths;
decl RAheadshots;
decl RAsucsides;

to

new RAkills;
new RAdeaths;
new RAheadshots;
new RAsucsides;

dalto
08-24-2007, 21:25
You need to put more of your code in that function into this if:

if(SQL_FetchRow(hndl))

If your query has no results, then you are displaying the contents of uninitialized variables.

graczu
08-24-2007, 22:01
You need to put more of your code in that function into this if:

if(SQL_FetchRow(hndl))

If your query has no results, then you are displaying the contents of uninitialized variables.


Hmm i dont understand.

if (SQL_HasResultSet(hndl))
{



this i need to add?

dalto
08-24-2007, 22:13
public SQLGetMyRank(Handle:owner, Handle:hndl, const String:error[], any:client){
if(hndl == INVALID_HANDLE)
{
LogError(error);
return;
}

decl RAkills;
decl RAdeaths;
decl RAheadshots;
decl RAsucsides;

if(SQL_FetchRow(hndl))
{
RAkills=SQL_FetchInt(hndl,0);
RAdeaths=SQL_FetchInt(hndl,1);
RAheadshots=SQL_FetchInt(hndl,2);
RAsucsides=SQL_FetchInt(hndl,3);

decl String:buffer[512];
Format(buffer, sizeof(buffer), "SELECT rank_id FROM css_rank WHERE kills >= '%i' AND deaths <= '%i'", RAkills, RAdeaths);
if(DEBUG == 1){
PrintToServer("DEBUG: SQLGetMyRank (%s)", buffer);
}
SQL_TQuery(db, SQLShowRank, buffer, client);
PrintToChat(client,"[STATS] Fragow: %i | Smierci: %i | Trafien w Glowe: %i | Samobojstw: %i", RAkills, RAdeaths, RAheadshots, RAsucsides);
} else {
PrintToChat(client, "No results found");
}
}

graczu
08-26-2007, 06:56
Thx man you the best :)

new:

public SQLGetMyRank(Handle:owner, Handle:hndl, const String:error[], any:client){
if(hndl == INVALID_HANDLE)
{
LogError(error);
PrintToServer("Last Connect SQL Error: %s", error);
return;
}

decl RAkills;
decl RAdeaths;
decl RAheadshots;
decl RAsucsides;

if(SQL_FetchRow(hndl))
{
RAkills=SQL_FetchInt(hndl,0);
RAdeaths=SQL_FetchInt(hndl,1);
RAheadshots=SQL_FetchInt(hndl,2);
RAsucsides=SQL_FetchInt(hndl,3);

decl String:buffer[512];
Format(buffer, sizeof(buffer), "SELECT rank_id FROM css_rank WHERE kills >= '%i'", RAkills);
if(DEBUG == 1){
PrintToServer("DEBUG: SQLGetMyRank (%s)", buffer);
}
SQL_TQuery(db, SQLShowRank, buffer, client);
PrintToChat(client,"[STATS] Fragow: %i | Smierci: %i | Trafien w Glowe: %i | Samobojstw: %i", RAkills, RAdeaths, RAheadshots, RAsucsides);
} else {
PrintToChat(client, "[STATS] Brak Wynikow");
}
}


hehe its working, and a php site is working too:

http://cssrank.cs.wrocek.com/index.php

:]