TUniQuery and TUniconnection
TUniQuery and TUniconnection
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;
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
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.
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.
-
DemetrionQ
- Devart Team
- Posts: 271
- Joined: Wed 23 Jan 2013 11:21
Re: TUniQuery and TUniconnection
If any other questions come up, please contact us.
Re: TUniQuery and TUniconnection
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
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
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.
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.
-
DemetrionQ
- Devart Team
- Posts: 271
- Joined: Wed 23 Jan 2013 11:21
Re: TUniQuery and TUniconnection
If any other questions come up, please contact us.