Two queries in one
#1

It's possible to send two queries in one SQL statement, right?

pawn Код:
UPDATE `players` SET `Name` = '%e' WHERE `PlayerID` = '%i'; DELETE FROM `players` WHERE `PlayerID` = '%i'
Using mysql_format().

I'm getting this error:
Quote:

[18:44:45] [ERROR] CMySQLQuery::Execute[QR_OnChangeNameSuccess] - (error #1064) You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DELETE FROM `players` WHERE `PlayerID` = '47'' at line 1

Reply
#2

Try using
pawn Код:
UNION
In between the two queries. So it would be
pawn Код:
UPDATE `players` SET `Name` = '%e' WHERE `PlayerID` = %i UNION DELETE FROM `players` WHERE `PlayerID` = '%i'
Source: http://stackoverflow.com/questions/7...eries-into-one

@Konstantinos - Ooh yeah, My bad
Quote:

The column names from the first SELECT statement are used as the column names for the results returned.

Reply
#3

I had also tried something similar to insert data for racetop (top5) and then directly delete anything but keep 5 best time rows. The result was the same as yours. Even though in phpMyAdmin was executed without any problems so I just send 2 queries instead.

I'm not sure as I never tried, if something like this would work: https://dev.mysql.com/doc/refman/5.0/en/begin-end.html

@Stev: I think UNION is used only for SELECT queries, correct me if I'm wrong.
Reply
#4

Nope, still not working. Besides, I'm pretty certain you can end a statement with ; and put another one after it, because that's generally how SQL injection is done..
Reply
#5

My question is: why do your queries like this? What kind of program flow could possibly warrant this method?
Reply
#6

Quote:
Originally Posted by Sithis
Посмотреть сообщение
My question is: why do your queries like this? What kind of program flow could possibly warrant this method?
I want to take action when both queries have been processed. If I use two queries, I cannot assume they will be completed in the order I send them. I need both queries to be complete, and THEN take action. Yes, I could have two variables for each query being completed, but why do that when I can do this?

Also, it's got to be more efficient than sending two separate queries, as there is no result to process.
Reply
#7

Quote:
Originally Posted by MP2
Посмотреть сообщение
I want to take action when both queries have been processed. If I use two queries, I cannot assume they will be completed in the order I send them. I need both queries to be complete, and THEN take action. Yes, I could have two variables for each query being completed, but why do that when I can do this?

Also, it's got to be more efficient than sending two separate queries, as there is no result to process.
Doesn't mysql_tquery execute the queries with order but mysql_pquery doesn't? If it doesn't, transactions do:

pawn Код:
mysql_tquery(mysql, "START TRANSACTION;", "");
mysql_tquery(mysql, "UPDATE players ... ;", "");
mysql_tquery(mysql, "DELETE FROM players ... ;", "");
mysql_tquery(mysql, "COMMIT;", "CommitFinished", "");
Just an example. Of course you have them formatted and when CommitFinished will be called, take your action.
Reply
#8

Transactional queries would be my suggestion as well. I use it in C# development using the nHibernate library. Once you get the hang of it with committing and such, it's a breeze to quickly develop your data manipulation code.
Reply
#9

You can execute multiple queries by separating each query by a ';'.

Код:
SELECT * FROM blablabla ; SELECT * FROM blablabla2
Reply
#10

Quote:
Originally Posted by Yashas
Посмотреть сообщение
You can execute multiple queries by separating each query by a ';'.
Unfortunately, that doesn't work with BlueG's mysql plugin.

INSERT + DELETE -> error near DELETE
UPDATE + DELETE -> error near DELETE
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)