Recover a value[mysql]
#1

Hi,

I tried to recover 2 values posX and posY from my mysql database, but it always return me "0". Could you please tell me what's wrong in my code ?
Thank you !

Код:
 mysql_format(mysql, query, sizeof(query), "INSERT INTO `joueurs` (`Username`, `Password`, `IP`, `Admin`, `VIP`, `Argent`, `posX` ,`posY`, `posZ`, `Interieur`, `World`, `Skin`, `Niveau`) VALUES ('%e', '%s', '%s', 0, 0, 1000, 1527.5634, -1738.9218, 13.5469, 0, 0, 26, 1)", Name[playerid], pInfo[playerid][Password], IP[playerid]);
mysql_tquery(mysql, query, "", "");

mysql_format(mysql, query, sizeof(query), "SELECT `posX`, `posY` FROM `joueurs` WHERE `posX` = '%f', `posY` = '%f'", pInfo[playerid][posX], pInfo[playerid][posY]);
printf("%f %f ", pInfo[playerid][posX], pInfo[playerid][posY]);
Mysql log:

Код:
[19:34:59] [DEBUG] mysql_format - connection: 1, len: 1024, format: "INSERT INTO `joueurs` (`Username`, `Password`, `IP`, `Admin`, `VIP`, `Argent`, `posX` ,`posY`, `posZ`, `Interieur`, `World`, `Sk..."
[19:34:59] [DEBUG] mysql_tquery - connection: 1, query: "INSERT INTO `joueurs` (`Username`, `Password`, `IP`, `Admin`, `V", callback: "(null)", format: "(null)"
[19:34:59] [DEBUG] mysql_format - connection: 1, len: 1024, format: "SELECT `posX`, `posY` FROM `joueurs` WHERE `posX` = '%f', `posY` = '%f'"
[19:34:59] [DEBUG] CMySQLQuery::Execute[] - starting query execution
[19:34:59] [DEBUG] CMySQLQuery::Execute[] - query was successful
[19:34:59] [DEBUG] CMySQLQuery::Execute[] - no callback specified, skipping result saving
I don't understand what's wrong :S


Thank you !
Reply
#2

You don't even seem to send the SELECT query. Please post the complete code where it sends the query and fetches the result with the cache_* functions.
Reply
#3

Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
	new query[1024];
    switch(dialogid)
    {
        case 1: //login dialog
        {
            if(!response) Kick(playerid); //if they clicked Quit, we will kick them
            new hpass[129]; //for password hashing
            WP_Hash(hpass, 129, inputtext); //hashing inputtext
            if(!strcmp(hpass, pInfo[playerid][Password])) //remember we have loaded player's password into this variable, pInfo[playerid][Password] earlier. Now let's use it to compare the hashed password with password that we load
            { //if the hashed password matches with the loaded password from database
                mysql_format(mysql, query, sizeof(query), "SELECT * FROM `joueurs` WHERE `Username` = '%e' LIMIT 1", Name[playerid]);
                //let's format our query
                //once again, we select all rows in the table that has your name and limit the result
                mysql_tquery(mysql, query, "OnAccountLoad", "i", playerid);
                //lets execute the formatted query and when the execution is done, a callback OnAccountLoad will be called
                //You can name the callback however you like
            }
            else //if the hashed password didn't match with the loaded password(pInfo[playerid][Password])
            {	
                //we tell them that they have inserted a wrong password
                ShowPlayerDialog(playerid, 1, DIALOG_STYLE_INPUT, "Connexion", "Mot de passe ?\nMauvais Mot de passe !", "Connexion", "Quitter");
            }
        }
        case 2: //register dialog
        {
            if(!response) return Kick(playerid); //if they clicked Quit, we will kick them
            if(strlen(inputtext) < 6) return ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "S'enregistrer", "Ton mot de passe doit faire plus de 6 caractиres !", "S'enregistrer", "Quitter");
			if(strlen(inputtext) > 24) return ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "S'enregistrer", "Ton mot de passe doit faire moins de 24 caractиres !", "S'enregistrer", "Quitter");
            //strlen checks a lenght of a string. so if player types their password that is lower than 6, we tell them; Your password must be at least 6 characters long!
            WP_Hash(pInfo[playerid][Password], 129, inputtext); //hashing inputtext
            mysql_format(mysql, query, sizeof(query), "INSERT INTO `joueurs` (`Username`, `Password`, `IP`, `Admin`, `VIP`, `Argent`, `posX` ,`posY`, `posZ`, `Interieur`, `World`, `Skin`, `Niveau`) VALUES ('%e', '%s', '%s', 0, 0, 1000, 1527.5634, -1738.9218, 13.5469, 0, 0, 26, 1)", Name[playerid], pInfo[playerid][Password], IP[playerid]);
            //Now let's create a new row and insert player's information in it
            mysql_tquery(mysql, query, "", "");
            //let's execute the query^^^^^^
			mysql_format(mysql, query, sizeof(query), "SELECT `posX`, `posY` FROM `joueurs` WHERE `posX` = '%f', `posY` = '%f'", pInfo[playerid][posX], pInfo[playerid][posY]);
			mysql_tquery(mysql, query, "", "");
			printf("%f %f %d %d", pInfo[playerid][posX], pInfo[playerid][posY]);
			SetSpawnInfo( playerid, 0, 26, 1527.5634,-1738.9218,13.5469, 0.0, 0, 0, 0, 0, 0, 0 );
			SetPlayerScore(playerid,pInfo[playerid][Niveau]);
			TogglePlayerSpectating(playerid, 0);
			SpawnPlayer(playerid);
        }
    }


	return 1;
}
If you need the entire code: http://pastebin.com/Rquj7JSf

But with the printf in my console I have "0.00000 0.00000"


It's all I have.


Could you please explain me what's "Please post the complete code where it sends the query and fetches the result with the cache_* functions. "




Thank you !
Reply
#4

Quote:
Код:
mysql_format(mysql, query, sizeof(query), "SELECT `posX`, `posY` FROM `joueurs` WHERE `posX` = '%f', `posY` = '%f'", pInfo[playerid][posX], pInfo[playerid][posY]);
mysql_tquery(mysql, query, "", "");
printf("%f %f %d %d", pInfo[playerid][posX], pInfo[playerid][posY]);
  1. your query doesn't really makes any sense
  2. that query will also likely never return any result, because you are comparing float values (very bad)
  3. even if this query would return some valid values, do you expect these values are auto-magically assigned to their correct variables? Only the ORM system can do this.
tl;dr: You should try to understand how threaded queries work and how to use the cache_* (cache_get_row, cache_get_field_content, ...) natives.
If you don't really care about understanding how to use it and how it works, you can alternatively take a look at the ORM system. Once set up, it should make your life easier.
Reply
#5

Thank you guy !
If I follow the tutorial in your signature, might I be able to understand how to recover a value from a database ?


What's the difference between threated query and non threated ?

Could you please give me an exemple of a usage of ORM system to recover a value ?

For exemple: recover the value of 'money' in the table 'players'.

Thank you !



EDIT: Can't I use this ?


Код:
pInfo[playerid][Admin] = cache_get_row_int(0, 4);
pInfo[playerid][VIP] = cache_get_row_int(0, 5); 
pInfo[playerid][Argent] = cache_get_row_int(0, 6);
pInfo[playerid][posX] = cache_get_row_float(0, 7);
pInfo[playerid][posY] = cache_get_row_float(0, 8);
pInfo[playerid][posZ] = cache_get_row_float(0, 9);
pInfo[playerid][Interieur] = cache_get_row_int(0, 10);
pInfo[playerid][World] = cache_get_row_int(0, 11);
pInfo[playerid][Skin] = cache_get_row_int(0, 12);
pInfo[playerid][Niveau] = cache_get_row_int(0, 13);
Reply
#6

ORM is so much easier. Use it.
Reply
#7

Could you please give me an exemple of the utilization of ORM for my problem please ?

Do I have to include a special file in pawno includes or it's already in the R35 ?



Last question for tonight:
Why cache_get_row_flow work for a user who's already register but not for my register system ? o_O


Thank you guys !

(( sorry for my bad English ))
Reply
#8

UP please
Reply
#9

Well if you want to save his position under OnPlayerConnect, you can do this:

orm_addvar_float(ormid, pInfo[playerid][LastX], "LastX"); - Make sure ormid is defined correctly.

Alternatively you can use mysql_tquery, I'll let you see a snippet of my /savepos command (same concept):

pawn Код:
new query[256];
GetPlayerPos(playerid, Player[playerid][PosX], Player[playerid][PosY], Player[playerid][PosZ]);
        GetPlayerFacingAngle(playerid, Player[playerid][PosA]);
        format(query, sizeof(query), "UPDATE `players` SET `PosX` = '%f', `PosY` = '%f', `PosZ` = '%f', `PosA` = '%f' WHERE `username` = '%s' LIMIT 1", Player[playerid][PosX], Player[playerid][PosY], Player[playerid][PosZ], Player[playerid][PosA], getName(playerid));
        printf("\n %s", query); // printing to make sure the co-ords are being sent.
        mysql_tquery(SQL, query, "", "");
There's a tutorial somewhere on how to use MySQL r34, look up "MySQL R34 ORM Usage".


If you want to -load- the co-ordinates, do this:

SELECT * FROM `accounts` WHERE `PosX` = '%f', `PosY` = '%f' AND `PosZ` = '%f' WHERE `Name` = '%s'
Reply
#10

Thank you for this, Im gonna try this

Is it possible to save something then load it just after or it needs something between to save ?

Thank you !



EDIT:

I did this:

Код:
mysql_format(mysql, query, sizeof(query), "SELECT * FROM `joueurs` WHERE `posX` = '%f', `posY` = '%f' AND `posZ` = '%f' WHERE `Name` = '%s'  ", pInfo[playerid][posX], pInfo[playerid][posY], pInfo[playerid][posZ],  Name[playerid]);
mysql_tquery(mysql, query, "", "");
printf("\n %s", query); // printing to make sure the co-ords are being sent. );
But it still doesn't work...

This is what I want:
I save in the database informations, then I load them to use them after.

Код:
mysql_format(mysql, query, sizeof(query), "INSERT INTO `joueurs` (`Username`, `Password`, `IP`, `Admin`, `VIP`, `Argent`, `posX` ,`posY`, `posZ`, `Interieur`, `World`, `Skin`, `Niveau`) VALUES ('%e', '%s', '%s', 0, 0, 1000, 1527.5634, -1738.9218, 13.5469, 0, 0, 26, 1)", Name[playerid], pInfo[playerid][Password], IP[playerid]);
mysql_tquery(mysql, query, "", "");

mysql_format(mysql, query, sizeof(query), "SELECT * FROM `joueurs` WHERE `posX` = '%f', `posY` = '%f' AND `posZ` = '%f' WHERE `Name` = '%s'  ", pInfo[playerid][posX], pInfo[playerid][posY], pInfo[playerid][posZ],  Name[playerid]);
mysql_tquery(mysql, query, "", "");
printf("\n %s", query); // printing to make sure the co-ords are being sent. );



I can see that there's an error but I don't know how to solve it.

You got an idea please ?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)