Using the tzmysqlquery for updates?

Forum related to all 5.x versions of ZeosLib's DBOs

Moderators: gto, cipto_kh, EgonHugeist

Derek
Fresh Boarder
Fresh Boarder
Posts: 3
Joined: 04.07.2007, 10:16

Using the tzmysqlquery for updates?

Postby Derek » 04.07.2007, 12:57

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..."?

gto
Zeos Dev Team
Zeos Dev Team
Posts: 278
Joined: 11.11.2005, 18:35
Location: Porto Alegre / Brasil
Contact:

Postby gto » 04.07.2007, 13:39

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;
Use the FU!!!!!IN Google !

gto's Zeos Quick Start Guide

Te Amo Taís!

Derek
Fresh Boarder
Fresh Boarder
Posts: 3
Joined: 04.07.2007, 10:16

Postby Derek » 04.07.2007, 14:43

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;

gto
Zeos Dev Team
Zeos Dev Team
Posts: 278
Joined: 11.11.2005, 18:35
Location: Porto Alegre / Brasil
Contact:

Postby gto » 04.07.2007, 16:57

This query is connected to a TZUpdateSQL ?
If it is, the Update SQL property of TZUpdateSQL compoent (uh!) may be empty, or malformed!
Use the FU!!!!!IN Google !

gto's Zeos Quick Start Guide

Te Amo Taís!

Derek
Fresh Boarder
Fresh Boarder
Posts: 3
Joined: 04.07.2007, 10:16

Postby Derek » 05.07.2007, 07:15

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!

gto
Zeos Dev Team
Zeos Dev Team
Posts: 278
Joined: 11.11.2005, 18:35
Location: Porto Alegre / Brasil
Contact:

Postby gto » 05.07.2007, 12:13

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!
Use the FU!!!!!IN Google !

gto's Zeos Quick Start Guide

Te Amo Taís!


Return to “5.x Versions”

Who is online

Users browsing this forum: No registered users and 1 guest