REPLACE INTO not working
#1

I can't figure out what the problem is.
It says I have an error in my sql syntax.

PHP код:
new queryy[500];
mysql_format(mysqlqueryysizeof(queryy), "REPLACE INTO `offsets` (`DisplayID`,`PosX0`,`PosY0`,`PosZ0`,`RotX0`,`RotY0`,`RotZ0`,`ScaleX0`,`ScaleY0`,`ScaleZ0`) VALUES ('%i',%f','%f','%f','%f','%f','%f','%f','%f','%f')"GetModelID(GetPVarInt(playerid"edit")), fOffsetXfOffsetYfOffsetZfRotXfRotYfRotZfScaleXfScaleYfScaleZ);
mysql_query(mysqlqueryy);
SendClientMessage(playerid, -1"Editing object");
RemovePlayerAttachedObject(playerid0); 
Is there an other way to do this?
I need to update the row and insert if the DisplayID does not exist

Here is my mysql table:
Reply
#2

If DisplayID exists, it will delete the old data and replace with the new instead of returning an error.
You may also use INSERT INTO .. ON DUPLICATE KEY UPDATE.

Perhaps posting the error message?
Reply
#3

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
If DisplayID exists, it will delete the old data and replace with the new instead of returning an error.
What you need is INSERT INTO .. ON DUPLICATE KEY UPDATE.

Perhaps posting the error message?


PHP код:
            new queryy[500];
            
mysql_format(mysqlqueryysizeof(queryy), "INSERT INTO `offsets` (`DisplayID`,`PosX0`,`PosY0`,`PosZ0`,`RotX0`,`RotY0`,`RotZ0`,`ScaleX0`,`ScaleY0`,`ScaleZ0`) VALUES ('%i',%f','%f','%f','%f','%f','%f','%f','%f','%f') ON DUPLICATE KEY UPDATE `PosX0` = '%f',`PosY0` = '%f',`PosZ0` = '%f',`RotX0` = '%f',`RotY0` = '%f',`RotZ0` = '%f',`ScaleX0` = '%f',`ScaleY0` = '%f',`ScaleZ0` = '%f'"GetModelID(GetPVarInt(playerid"edit")), fOffsetXfOffsetYfOffsetZfRotXfRotYfRotZfScaleXfScaleYfScaleZfOffsetXfOffsetYfOffsetZfRotXfRotYfRotZfScaleXfScaleYfScaleZ);
            
mysql_query(mysqlqueryy);
            
SendClientMessage(playerid, -1"Editing object");
            
RemovePlayerAttachedObject(playerid0); 
I tried to change it but now I'm getting all these errors:


Quote:

C:\...\prp-gamemode.pwn(1767) : error 075: input line too long (after substitutions)
C:\...\prp-gamemode.pwn(176 : error 017: undefined symbol "fOf"
C:\...\prp-gamemode.pwn(1769) : error 017: undefined symbol "fsetX"
C:\...\prp-gamemode.pwn(1769) : warning 215: expression has no effect
C:\...\prp-gamemode.pwn(1769) : warning 215: expression has no effect
C:\...\prp-gamemode.pwn(1769) : warning 215: expression has no effect
C:\...\prp-gamemode.pwn(1769) : warning 215: expression has no effect
C:\...\prp-gamemode.pwn(1769) : warning 215: expression has no effect
C:\...\prp-gamemode.pwn(1769) : warning 215: expression has no effect
C:\...\prp-gamemode.pwn(1769) : warning 215: expression has no effect
C:\...\prp-gamemode.pwn(1769) : warning 215: expression has no effect
C:\...\prp-gamemode.pwn(1769) : error 001: expected token: ";", but found ")"
C:\...\prp-gamemode.pwn(1769) : error 029: invalid expression, assumed zero
C:\..\prp-gamemode.pwn(1769) : fatal error 107: too many error messages on one line

Reply
#4

After reading again what you were trying to do, I noticed that REPLACE was correct but INSERT INTO .. ON DUPLICATE is somewhat better. I did modify my post a couple of times, sorry about that.

So if you want to keep your old syntax, post the error in syntax you got even though the query seems ok.

About the above errors, the line is too long - split the arguments at the next line:
pawn Код:
mysql_format(..., "...",
GetModelID(GetPVarInt(playerid, "edit")), ...);
Reply
#5

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
After reading again what you were trying to do, I noticed that REPLACE was correct but INSERT INTO .. ON DUPLICATE is somewhat better. I did modify my post a couple of times, sorry about that.

So if you want to keep your old syntax, post the error in syntax you got even though the query seems ok.
I couldn't fix the errors so I went back to my old code.
This is the error in the mysql log:

Quote:

mysql_format - connection: 1, len: 500, format: "REPLACE INTO `offsets` (`DisplayID`,`PosX0`,`PosY0`,`PosZ0`,`RotX0`,`RotY 0`,`RotZ0`,`ScaleX0`,`ScaleY0`,`ScaleZ0`) VALUES ('%i',..."
mysql_query - connection: 1, query: "REPLACE INTO `offsets` (`DisplayID`,`PosX0`,`PosY0`,`PosZ0`,`Rot", use_cache: true
CMySQLQuery::Execute - starting query execution
CMySQLQuery::Execute - (error #1064) You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '','-0.019','0.0','0.0','88.5','0.0','1.0','1.0','1.0') ' at line 1

Reply
#6

The problem is clear now:
Код:
VALUES ('%i','%f','%f','%f','%f','%f','%f','%f','%f','%f')
You forgot an apostrophe.
Reply
#7

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
The problem is clear now:
Код:
VALUES ('%i','%f','%f','%f','%f','%f','%f','%f','%f','%f')
You forgot an apostrophe.
It works now
Thanks for the help man
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)