Two queries in one -
MP2 - 23.05.2015
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
|
Re: Two queries in one -
Stev - 23.05.2015
Try using
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.
|
Re: Two queries in one -
Konstantinos - 23.05.2015
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.
Re: Two queries in one -
MP2 - 23.05.2015
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..
Re: Two queries in one -
Sithis - 23.05.2015
My question is: why do your queries like this? What kind of program flow could possibly warrant this method?
Re: Two queries in one -
MP2 - 23.05.2015
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.
Re: Two queries in one -
Konstantinos - 23.05.2015
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.
Re: Two queries in one -
Sithis - 24.05.2015
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.
Re: Two queries in one -
Yashas - 24.05.2015
You can execute multiple queries by separating each query by a ';'.
Код:
SELECT * FROM blablabla ; SELECT * FROM blablabla2
Re: Two queries in one -
Konstantinos - 24.05.2015
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