SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 25/07/2013, 04:09 PM   #1
Ld Est Ld
Big Clucker
 
Ld Est Ld's Avatar
 
Join Date: Nov 2011
Posts: 99
Reputation: 2
Default Getting MySQL INSERT ID MySQL R7 plugin

Helllo, I have another problem I can't solve.

If I insert query then How I get the ID of the INSERTED query?

The Code:
PHP Code:
if(EDIT_OBJ_ID[playerid]) {
            
SetDynamicObjectPos(EDIT_OBJ_ID[playerid], xyz);
            
SetDynamicObjectRot(EDIT_OBJ_ID[playerid], rxryrz);
            
EDIT_OBJ_ID[playerid] = objectid;
                
            
furnitureVariables[EDIT_OBJ_ID[playerid]][fFurniturePos][0] = x;
            
furnitureVariables[EDIT_OBJ_ID[playerid]][fFurniturePos][1] = y;
            
furnitureVariables[EDIT_OBJ_ID[playerid]][fFurniturePos][2] = z;
            
            
furnitureVariables[EDIT_OBJ_ID[playerid]][fFurnitureRot][0] = rx;
            
furnitureVariables[EDIT_OBJ_ID[playerid]][fFurnitureRot][1] = ry;
            
furnitureVariables[EDIT_OBJ_ID[playerid]][fFurnitureRot][2] = rz;
            
            
furnitureVariables[EDIT_OBJ_ID[playerid]][fFurnitureHouseID] = getPlayerHouseID(playerid);
            
            
furnitureVariables[EDIT_OBJ_ID[playerid]][fFurnitureINT] = GetPlayerInterior(playerid);
            
furnitureVariables[EDIT_OBJ_ID[playerid]][fFurnitureVW] = GetPlayerVirtualWorld(playerid);
            
            if(
isnull(furnitureVariables[EDIT_OBJ_ID[playerid]][fFurniturePlanter])) {        
                
furnitureVariables[EDIT_OBJ_ID[playerid]][fFurniturePlanter] = playerVariables[playerid][pNormalName];
                
format(szQueryInputsizeof(szQueryInput), "INSERT INTO furniture (objectModelID, objectPosX, objectPosY, objectPosZ, objectHouseID, objectRotX, objectRotY, objectRotZ, objectPlanterName, objectVW, objectINT) VALUES ('%d', '%f', '%f', '%f', '%d', '%f', '%f', '%f', '%s', '%d', '%d')"furnitureVariables[EDIT_OBJ_ID[playerid]][fFurnitureOID],
                
furnitureVariables[EDIT_OBJ_ID[playerid]][fFurniturePos][0], furnitureVariables[EDIT_OBJ_ID[playerid]][fFurniturePos][1], furnitureVariables[EDIT_OBJ_ID[playerid]][fFurniturePos][2], furnitureVariables[EDIT_OBJ_ID[playerid]][fFurnitureHouseID],
                
furnitureVariables[EDIT_OBJ_ID[playerid]][fFurnitureRot][0], furnitureVariables[EDIT_OBJ_ID[playerid]][fFurnitureRot][1], furnitureVariables[EDIT_OBJ_ID[playerid]][fFurnitureRot][2], furnitureVariables[EDIT_OBJ_ID[playerid]][fFurniturePlanter],furnitureVariables[EDIT_OBJ_ID[playerid]][fFurnitureINT],furnitureVariables[EDIT_OBJ_ID[playerid]][fFurnitureVW]);
                
mysql_function_query(connectionszQueryInputtrue"insertFurniture""d"playerid);
                
#if defined DEBUG
                    
printf("%s"szQueryInput);
                
#endif
                
EDIT_OBJ_ID[playerid] = 0;
                
pEDIT_OBJ[playerid] = 0;
            } else if(!
isnull(furnitureVariables[EDIT_OBJ_ID[playerid]][fFurniturePlanter])) {            
                
saveFurniture(EDIT_OBJ_ID[playerid]);
                
EDIT_OBJ_ID[playerid] = 0;
                
pEDIT_OBJ[playerid] = 0;
            }
        } 
The public function
PHP Code:
public insertFurniture(playerid) {
    
furnitureVariables[EDIT_OBJ_ID[playerid]][fFurnitureID] = mysql_insert_id();
    return 
1;

And saveFunriture stck:
PHP Code:
public saveFurniture(furnitureID) {
    
format(szQueryInputsizeof(szQueryInput), "UPDATE furniture SET objectModelID = '%d', objectPosX = '%f', objectPosY = '%f', objectPosZ = '%f', objectHouseID = '%d', objectRotX = '%f', objectRotY = '%f', objectRotZ = '%f', objectPlanterName = '%s', objectVW = '%d', objectINT = '%d'",
    
furnitureVariables[furnitureID][fFurnitureOID], furnitureVariables[furnitureID][fFurniturePos][0], furnitureVariables[furnitureID][fFurniturePos][1], furnitureVariables[furnitureID][fFurniturePos][2], furnitureVariables[furnitureID][fFurnitureHouseID], furnitureVariables[furnitureID][fFurnitureRot][0], furnitureVariables[furnitureID][fFurnitureRot][1], furnitureVariables[furnitureID][fFurnitureRot][2], furnitureVariables[furnitureID][fFurniturePlanter],
    
furnitureVariables[furnitureID][fFurnitureVW], furnitureVariables[furnitureID][fFurnitureINT]);
    
    
format(szQueryInputsizeof(szQueryInput), "%s WHRE objectID = '%d'"szQueryInputfurnitureVariables[furnitureID][fFurnitureID]);
    
#if defined DEBUG
        
printf("%s"szQueryInput);
    
#endif
    
return 1;

Thanks.
Ld Est Ld is offline   Reply With Quote
Old 25/07/2013, 04:37 PM   #2
Xabi
Big Clucker
 
Xabi's Avatar
 
Join Date: Nov 2012
Posts: 145
Reputation: 6
Default Respuesta: Getting MySQL INSERT ID MySQL R7 plugin

Just change

pawn Code:
mysql_function_query(connection, szQueryInput, true, "insertFurniture", "d", playerid);

to

pawn Code:
mysql_function_query(connection, szQueryInput, false, "insertFurniture", "d", playerid);
Xabi is offline   Reply With Quote
Old 25/07/2013, 04:43 PM   #3
Konstantinos
Spam Machine
 
Konstantinos's Avatar
 
Join Date: Dec 2011
Posts: 11,828
Reputation: 1401
Default Re: Getting MySQL INSERT ID MySQL R7 plugin

Whenever you use INSERT INTO or UPDATE is not necessary to use cache parameter to true. If I remember correct, it ignores it and it set it to true (always) in the newest versions.

Anyways, what you're looking for is:
pawn Code:
mysql_insert_id( )

Like you have in a callback. That should work.

Quote:
pawn Code:
furnitureVariables[EDIT_OBJ_ID[playerid]][fFurnitureID] = mysql_insert_id();
__________________
Life is like riding a bicycle. To keep your balance, you must keep moving.

[Tutorial] How to use SQLite
[FilterScript] Tune System
Konstantinos is offline   Reply With Quote
Old 25/07/2013, 04:48 PM   #4
Ld Est Ld
Big Clucker
 
Ld Est Ld's Avatar
 
Join Date: Nov 2011
Posts: 99
Reputation: 2
Default Re : Re: Getting MySQL INSERT ID MySQL R7 plugin

Quote:
Originally Posted by _Zeus View Post
Whenever you use INSERT INTO or UPDATE is not necessary to use cache parameter to true. If I remember correct, it ignores it and it set it to true (always) in the newest versions.

Anyways, what you're looking for is:
pawn Code:
mysql_insert_id( )

Like you have in a callback. That should work.
Yes, but I give this value to the variable:

PHP Code:
public insertFurniture(playerid) {
    
furnitureVariables[EDIT_OBJ_ID[playerid]][fFurnitureID] = mysql_insert_id();
    return 
1;

But if I use it, it gives me 0.

EDIT::: Thank You both..
My stupid mistake. I made EDIT_OBJ_ID[playerid] = 0 before INSERT. That's Why it gave me 0.

Thanks. REP+.
Ld Est Ld is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
BlueG MySQL plugin - Failed (plugins/mysql.so: undefined symbol: _Z13stringvprintfPKcPc) linuxthefish Plugin Development 10 13/07/2013 10:56 AM
mysql insert id? .Mento Scripting Help 3 12/06/2013 05:04 PM
MYSQL INSERT INTO PaulDinam Scripting Help 2 22/01/2013 09:18 AM
[MySQL] INSERT INTO help Tigerkiller Scripting Help 3 30/01/2012 03:06 AM


All times are GMT. The time now is 10:16 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.