Page 1 of 1

Multiple SQL statements possible ?

Posted: Sat 04 Aug 2007 18:14
by Nukster
Hi there :)

I have a question. Maybe it's a dumb one but I'm just not sure if it's possible without causing trouble...

Is is possible to use multiple statements for the SQLUpdate property in TMyQuery ?

Somethin like this:

MyQuery.SQLUpdate.Clear;
MyQuery.SQLUpdate.Add('UPDATE terminals SET terminal_machineid = :terminal_machineid, terminal_requiresnewregistration = 0 WHERE terminal_id = :OLD_terminal_id;');
MyQuery.SQLUpdate.Add('UPDATE terminals SET terminal_requiresnewregistration = 1 WHERE (terminal_machineid = :terminal_machineid) AND (terminal_id :OLD_terminal_id);');

It seems to work flawlessly on a MySQL server 5.0.41. I'm just not sure if there are any side effects which I should be aware of...

Thx in advance

Bernd

Posted: Mon 06 Aug 2007 09:58
by Ikar
Yes it is possible. But you should set TMyQuery.Options.StrictUpdate to
False.

Posted: Sat 11 Aug 2007 09:22
by ben
i used to execute multiple UPDATE or INSERT queries without StrictUpdate and have no problems. why?

Posted: Sat 11 Aug 2007 22:04
by Nukster
ben wrote:i used to execute multiple UPDATE or INSERT queries without StrictUpdate and have no problems. why?
If StrictUpdate is on and the last insert/update statement affects more than ONE row (RowsAffected > 1) you will get an exception.

Setting StrictUpdate=False disables this "more-than-one-row-affected" check.

Posted: Mon 13 Aug 2007 07:03
by Antaeus
You are right, but I should add that StrictUpdate mode checks whether the affected rows count equals to one. You have missed the case when the affected rows count is less than one.