TUniQuery and TUniconnection

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Suhaimin
Posts: 79
Joined: Mon 06 May 2013 12:19

TUniQuery and TUniconnection

Post by Suhaimin » Thu 23 May 2013 12:03

hello,

I have used Uniconnection and a Uniquery to insert data,if all data be inserted successful then I run uniquery.applyupdates but error occur "Cannot perform this operation on closed dataset" ... whats wrong with this code? thanks a lot..


try
UniConnection.StartTransaction;
UNiquery.Close;
UNiquery.sql.Clear;
UNiquery.SQL.Add('INSERT INTO "TEST" ("VALUE1","VALUE2") ');
UNIQUERY.SQL.Add('VALUES (:p0 ,:p1) ');
FOR I := 1 TO 10
begin
UNIQUERY.Prepare;
UNIQUERY.ParamByName('p0').value := I;
UNIQUERY.ParamByName('p1').VALUE := I;
UNIQUERY.ExecSQL;

end;

UNIQUERY.APPLYUPDATES;
UniConNECT.Commit; // if there were no errors, commit transaction


except
// calling ApplyUpdates
UNIQUERY.RestoreUpdates;
UniConNECTION.Rollback; // roll back transaction
end;

DemetrionQ
Devart Team
Posts: 271
Joined: Wed 23 Jan 2013 11:21

Re: TUniQuery and TUniconnection

Post by DemetrionQ » Thu 23 May 2013 13:13

Hello.


The ApplyUpdates and RestoreUpdates methods are designed for situations when TUniQuery.CachedUpdates is set to True, a dataset is open (using the TUniQuery.Open method) and you are modifying data in a table using the TUniQuery.Edit, TUniQuery.Post, etc. methods.

In your code sample, there is no need to use ApplyUpdates and RestoreUpdates. To solve the problem, remove calling of the ApplyUpdates and RestoreUpdates methods from your sample.

The detailed information about the CachedUpdates property and the ApplyUpdates and RestoreUpdates methods can be read in the UniDAC documentation.

Suhaimin
Posts: 79
Joined: Mon 06 May 2013 12:19

Re: TUniQuery and TUniconnection

Post by Suhaimin » Thu 23 May 2013 14:39

Thank a lot..

DemetrionQ
Devart Team
Posts: 271
Joined: Wed 23 Jan 2013 11:21

Re: TUniQuery and TUniconnection

Post by DemetrionQ » Thu 23 May 2013 14:46

If any other questions come up, please contact us.

Suhaimin
Posts: 79
Joined: Mon 06 May 2013 12:19

Re: TUniQuery and TUniconnection

Post by Suhaimin » Fri 24 May 2013 09:02

Hello,

try
UniConnection.StartTransaction;
UNiquery.Close;
UNiquery.sql.Clear;
UNiquery.SQL.Add('INSERT INTO "TEST" ("VALUE1","VALUE2") ');
UNIQUERY.SQL.Add('VALUES (:p0 ,:p1) ');
FOR I := 1 TO 10
begin
UNIQUERY.Prepare;
UNIQUERY.ParamByName('p0').value := I;
UNIQUERY.ParamByName('p1').VALUE := I;
UNIQUERY.ExecSQL;
end;

UniConNECT.Commit; // if there were no errors, commit transaction

except
UniConNECTION.Rollback; // roll back transaction
end;

in this code while uniquery.exec, is it process work in cache memory even if uniquery.cacheupdates = false ?i dont understand uniquery.exec process . thanks a lot

DemetrionQ
Devart Team
Posts: 271
Joined: Wed 23 Jan 2013 11:21

Re: TUniQuery and TUniconnection

Post by DemetrionQ » Mon 27 May 2013 12:56

Hello.

TUniQuery.CachedUpdates is responsible for caching updates on a client, i.e. all updates are stored in memory of a PC, on which the application was launched. Since you don't work with a dataset on the client in your sample, the CachedUpdates option doesn't affect it.
The TUniQuery.ExecSQL method executes operations on the server. Since you use a transaction, all changes made in it are stored on the server.

Suhaimin
Posts: 79
Joined: Mon 06 May 2013 12:19

Re: TUniQuery and TUniconnection

Post by Suhaimin » Sun 02 Jun 2013 11:53

thanks a lot

DemetrionQ
Devart Team
Posts: 271
Joined: Wed 23 Jan 2013 11:21

Re: TUniQuery and TUniconnection

Post by DemetrionQ » Mon 03 Jun 2013 12:06

If any other questions come up, please contact us.

Post Reply