Subject Re: [firebird-support] INSERT TABLE INTO DIFFERENT DATABASE GDB
Author Helen Borrie
At 06:36 AM 19/02/2008, Allies wrote:
>im sorry... im still confuse....
> give me a detail argument...
> thanks...
> best regard

1. Create your TIBQuery in runtime (for better performance use TIBSQL, see IBX help)
2. Use a prepared statement with parameters
3. Use a 2-phase transaction
4. Don't call Delete on the clientdataset unless you really want
to delete those records.
^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
5. Don't use upper case for postings to lists
6. Use a Delphi newsgroup for Delphi questions in future
^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
var
IBQuery: TIBQuery;
...
begin
...
if IBClientDataset.Active then
IBClientDataset.Close;
if IBClientDataset.DBTransaction.InTransaction then
try
IBClientDataset.DBTransaction.Commit
except
IBClientDataset.DBTransaction.Rollback;
// add any other needed exception handling here
end;
// assuming the transaction is quiet and happy

IBQuery := TIBQuery.Create(nil);
with IBQuery do
try
Database := MyTarget; // existing DB object for MYOFF.GDB
Transaction := IBClientDataset.DBTransaction;
SQL.Add( 'insert into MYSS values (' );
SQL.Add( 'P_TGL, P_ORD,......' );
SQL.Add(' ) values (' );
SQL.Add(' :P_TGL, :P_ORD,......');
SQL.Add(' ) ');
IBClientDataset.DBTransaction.StartTransaction;
IBClientDataset.Open; // IBClientDataset should prepare itself

Prepare;
// Now we are ready to begin looping through IBClientDataset

WHILE NOT IBCLIENTDATASET.EOF DO
begin
ParamByName('P_TGL').Value := IBClientDataset.FieldByName('P_TGL').Value;
ParamByName('P_ORD').Value := IBClientDataset.FieldByName('P_ORD').Value;
ParamByName(...................

// When all parameters are filled, execute one insert
ExecSQL;

// If you intended to delete the source record then uncomment
// the following:
{ IBClientDataset.Delete;}

// If you didn't intend to delete the source record then
// uncomment the following instead, to move to the
// next source record
{ IBClientDataset.Next; }

end; // End of loop

// Now try to commit the transaction
try
Transaction.Commit
except
Transaction.Rollback; // or whatever exception handling you want
end;
IBClientDataset.Close;
finally
if Active then Close; // not sure if this is needed - see IBX help
FreeAndNil;
end;
END;

No guarantees that this code will run exactly as written, since I never use IBX.

This list is is about Firebird issues. It is NOT a Teach-yourself forum for Delphi users. If you intend to use IBX then study the IBX help that comes with Delphi.

For questions about how the components work, find the appropriate Codegear Delphi newsgroup and ask there.

^ heLen ^