Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to send several insert statements using TSQLConnection.Execute

I’m using TSQLConnection to connect to a remote MySql DB.

What i want is, to send several insert statements by once, instead of send one by one (this would be painfully slow).

But when i try to do it, i get an error from the server.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

If i send only one statement, like :

mySQLConnection.execute('insert into table values (1,100)',nil);

It works. But if i send like this :

mySQLConnection.execute('insert into table values (1,100);insert into table values (2,200);insert into table values (3,300)',nil);

Server will raise an exception :

Project xxx.exe raised exception class TDBXError with message '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 ...

Any way to make it work ? On MySQL Workbench the same SQL statement with several inserts will work, but not on Delphi.

>Solution :

Each call to .execute() can only execute one query. If you want to insert multiple rows, put more than one list of values after VALUES.

mySQLConnection.execute('insert into table values (1,100), (2,200), (3,300)',nil);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading