Page 1 of 1

Using the tzmysqlquery for updates?

Posted: 04.07.2007, 12:57
by Derek
Running Delphi 5.....

when I try and use the tzmysqlquery to do an update:
[font=Courier New]
with qryUpdate do
begin
Active:=false;
SQL.Clear;
SQL.Add(myQueryString);
Active:=true;
First;
Edit;
FieldByName('Name').AsString := 'TEST!';
ApplyUpdates;
end;[/font]

the program crashes on the ApplyUpdates with the message "Updatesql is empty".

Any suggestions, apart from the standard "upgrade to version X..."?

Posted: 04.07.2007, 13:39
by gto
Well, updagrading to version X is always good :mrgreen:
Anyway, I think your problem can be solved adding a .Post before ApplyUpdates, like this:

Code: Select all

with qryUpdate do
begin
   Active := false;
   SQL.Clear;
   SQL.Add(myQueryString);
   Active := true;
   First;
   Edit; 
   FieldByName('Name').AsString := 'TEST!';
   Post;
   ApplyUpdates;
end;

Posted: 04.07.2007, 14:43
by Derek
Unfortunately not - the code seems to accept the Post but still crashes on the ApplyUpdates - and if you leave the ApplyUpdates off, then the record is not updated.
gto wrote:Well, upgrading to version X is always good :mrgreen:
Anyway, I think your problem can be solved adding a .Post before ApplyUpdates, like this:

Code: Select all

with qryUpdate do
begin
   Active := false;
   SQL.Clear;
   SQL.Add(myQueryString);
   Active := true;
   First;
   Edit; 
   FieldByName('Name').AsString := 'TEST!';
   Post;
   ApplyUpdates;
end;

Posted: 04.07.2007, 16:57
by gto
This query is connected to a TZUpdateSQL ?
If it is, the Update SQL property of TZUpdateSQL compoent (uh!) may be empty, or malformed!

Posted: 05.07.2007, 07:15
by Derek
Well, I have connected the TzMySQLQuery to a TZUpdateSQL. Is there further code that I have to write; or how do I check the "Update SQL property" to see of the code is correct? Is there a major bug in the components; surely this is a fairly standard type of operation?
gto wrote:This query is connected to a TZUpdateSQL ?
If it is, the Update SQL property of TZUpdateSQL compoent (uh!) may be empty, or malformed!

Posted: 05.07.2007, 12:13
by gto
When you connect the query to a TZUpdateSQL, it means that your query is complex (eg: selecting from more than a table and/or doing joins), and if you try to use it without the TZUpdateSQL, it will pop an error when you try to edit/post/append.

Two steps now: If your query is simple, like "select xx from yy where zz" or any other query that uses only one table, remove the TZUpdateSQL and disconnect it from the query, as it's not needed.

But if your query is complex, you'll need to use the TZUpdateSQL. It will help you to choose what table the query should update when post/edit/append.

At newer versions, there's a little design editor that will help you to do this task. It can be accessed by double clicking in the component. Here is a screenshot:

Image

To use this form, setup the query, put a TZUpdateSQL and name it as you want, then link the query to it.
Double click in TZUpdateSQL, select the table name then click in Get Table Fields and Database Defaults. The two column at right should get filled. In the column Key Field, select the fields that will be used as Key, to update the table. (eg: code). In the update Fields, select the fields that will be updated when edit/post/append. Make sure all the fields you select are from the Table Name selected. Then click in Generate SQL.

Now, on the SQL tab of this window, you can see the SQL statements. They can be accessed by clicking in TZUpdateSQL and selecting DeleteSQL, UpdateSQL or InsertSQL at the Object Inspector.

[]'s!