Verbose mode for TMyScript or TMyCommand

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
GuzunNicolae
Posts: 78
Joined: Wed 17 Jan 2007 14:16

Verbose mode for TMyScript or TMyCommand

Post by GuzunNicolae » Thu 21 Jun 2007 09:24

Hello

I have a question.

How can I get the results of MyScript or MyCommand queries as in MySQL console?
For example:

Code: Select all

Query ok: xx rows affected, (yy seconds)
or

Code: Select all

Error xxx: cannot do yyy
Is this possible? Also I would like to get from a MyScript the result of each statement.

Thanks

Antaeus
Posts: 2098
Joined: Tue 14 Feb 2006 10:14

Post by Antaeus » Thu 21 Jun 2007 12:10

Just attach a TMyQuery object to TMyScript and use it to display data and read affected rows count. This may look like this:

Code: Select all

  MyScript1.SQL.Clear;
  MyScript1.SQL.Add('UPDATE emp SET empno=empno;');
  MyScript1.SQL.Add('SELECT * FROM emp;');
  MyScript1.SQL.Add('SELECT * FROM dept;');
  MyScript1.DataSet := MyQuery1;

  MyScript1.ExecuteNext;
  ShowMessage('Affected rows count: ' + IntToStr(MyQuery1.RowsAffected));

  DataSource1.DataSet := MyQuery1;

  MyScript1.ExecuteNext; // display the `emp` table
  ShowMessage('The `emp` table is displayed');

  MyScript1.ExecuteNext; // display the `dept` table
  ShowMessage('The `dept` table is displayed');
In order to catch errors when executing the script, you should add a handler to the OnError event of TMyScript.

GuzunNicolae
Posts: 78
Joined: Wed 17 Jan 2007 14:16

Post by GuzunNicolae » Fri 22 Jun 2007 08:17

Won't this decrease visibly the performance?

Antaeus
Posts: 2098
Joined: Tue 14 Feb 2006 10:14

Post by Antaeus » Sat 23 Jun 2007 09:23

No, the performance loss should be insignificant.

GuzunNicolae
Posts: 78
Joined: Wed 17 Jan 2007 14:16

Post by GuzunNicolae » Wed 18 Jul 2007 11:09

What about the time in which the query executes? Should I calculate it by myself?

Also in MySQL when I issue an UPDATE/DELETE statement I get the following result:
'Rows matched: xx Changed: yy Warnings: zz
How I can get matched rows and warnings?

And how can I get the last error message of a script or command?

Thank you.

Antaeus
Posts: 2098
Joined: Tue 14 Feb 2006 10:14

Post by Antaeus » Wed 18 Jul 2007 13:55

GuzunNicolae wrote:What about the time in which the query executes? Should I calculate it by myself?
Yes, you should.
GuzunNicolae wrote:How I can get matched rows and warnings?
You can get the matched rows count from the TMyQuery.RowsAffected property. MyDAC does not support functionality with returning information about changed recodrs count, and warnings count.
GuzunNicolae wrote:And how can I get the last error message of a script or command?
You can handle errors in the TMyScript.OnError event, and cache their messages.

Post Reply