Page 1 of 1

Executing multiple statemnts

Posted: Tue 17 Oct 2006 15:51
by RH
Hi

I have two questions:

1- If you send multiple queries to the server using the TMyCommand.Execute method, the sql server only parses and executes the first query, while the second is desregarded.
If you do the same thing using the TMyQuery.Open, then all queries are parsed and executed by the Server. How come there is this difference ?
If you log the queries by the server and look at them, there is no difference in what ther server gets. So how can this occur ?

2- In the documentation it says that the TMyQuery. Execute method implicitly calls prepare, and calls open. I cannot see a prepare query in the MySQL query log. Does that mean that no prepare is called, or just that a call to prepare dos not show up there ?? And besides I do not want an implicit call to prepare to be made. How can I prevent this ?

I have also a couple of comments and suggestions:

A) In the documentation, if you go to the MyQuery and click on "Properties", you will find a derived property: Autocommit. This is actually not derived in implimentation, as one cannot refer to it in MyQuery object

B)The MyConnection has a preperty called "Embedded" and another preperty called "Options.Embedded" is this some form of redundency ? would you kindly correct this ?

C) In the MyConnection there are two properties: "Options.Direct" and "Options.Embedded" I wonder whether it is not better to declare this as an enumerated type instaed of booleans. for example:

TserverInterface = (siDirect, siEmbedded);
Options.ServerInterface: TServerInterface

This would make more sense, because the connection type can only be true for either Embedded or Direct at any given time. It cannot be both

Thanks in advance :mrgreen:

Posted: Wed 18 Oct 2006 09:27
by Antaeus
1) Your assertion is correct for current version of MySQL Server. Old versions of the server were unable to execute multiple SQL statements.

2) MyQuery implicitly prepares statement before execution only if AutoPrepare option is set to True.

A) This property is marked with yellow square in the MyDAC Help. It means that AutoCommit is protected property (see legend).

B) At first Embedded option was added as MyConnection.Embedded property then it was moved to MyConnection.Options. But to leave new version compatible with previous MyConnection.Embedded property was not removed.

C) This would be good solution but Direct option was added earlier than Embedded and we did not change neither type of the Direct option nor its name for compatibility reasons. So, we do not plan to perform such changes in the future.

Posted: Wed 18 Oct 2006 11:22
by RH
Thanks for yor answer

I just have a couple of clarifying questions:

regarding 1
But how come that multiple queries are executed by the server when you use MyQuery.Open; but only first query is executed when you use MyCommand.Execute ? I am wondering about this, because MySQL's query log does not show any difference between what is sent to the server in each case. I am by the way using the latest server version

Posted: Thu 19 Oct 2006 09:08
by Antaeus
In general there is no difference between MyQuery.Open and MyCommand.Execute methods except some details:
1) MyQuery.Open must return one or more result sets, otherwise it fails
2) if assigned SQL statements to MyQuery.SQL and MyCommand.SQL return more than one result set:
- MyQuery.Open executes all statements and returns the first result set. Other result sets are cached on the client and can be retrieved calling MyQuery.OpenNext.
- MyCommand.Execute executes all statements but all result sets are ignored.