meta data for this page
  •  

ibec_CopyData

This function is intended for the quick copying of data from one connection (ODBC or Firebird/InterBase®) to another (Firebird/InterBase® only)

Description

The ibec_CopyData function returns the number of records copied from SrcConnection to DestConnection.

Syntax

   function ibec_CopyData(SrcConnection : variant;
                          DestConnection : variant;
                          DestTableName : string;
                          SelectStatement : string;
                          Options : string;
                          CallbackBlock : variant) : integer;

Possible options are:

  • CommitAfter=<number_of_records> - after the specified number of records a COMMIT will be performed. Default value is 500.
  • CreateTable - if the table doesn't exist in the target database it will be created using the structure of the source query. If the target table doesn't exist and the CreateTable option is not specified an exception will be raised.
  • EmptyTable - the target table will be emptied before copying data.
  • DontQuoteIdents - all identifiers in CREATE TABLE and INSERT statements will be converted to uppercase even if they are case-sensitive in the source database.

Example of an Options string:

 'CommitAfter=1000; CreateTable'
 

Example

   execute ibeblock
   as
   begin
     cbb = 'execute ibeblock (RecNo integer)
            as
            begin
              if (ibec_mod(RecNo, 100) = 0) then
                ibec_Progress(RecNo || 'records copied...');
            end';
 
     OdbcCon = ibec_CreateConnection(__ctODBC, 'DBQ=C:\IBE Demo\demo.mdb; DRIVER=Microsoft Access Driver 
 
 (*.mdb)');
 
     DB = ibec_CreateConnection(__ctInterBase,
                                'DBName="localhost:D:\FB2_DATA\IBEHELP.FBA";
                                 ClientLib=C:\Program Files\Firebird\bin\fbclient.dll;
                                 user=SYSDBA; password=masterkey; names=WIN1251; sqldialect=3');
     try
       use DB;
       if (exists(select * from rdb$relations where rdb$relation_name = 'IBEC_COPYDATA')) 
 
 then
       begin
         execute statement 'drop table IBEC_COPYDATA';
         commit;
       end;
 
       Country = 'US';
 
       RecCount = ibec_CopyData(OdbcCon, DB, 'IBEC_COPYDATA', 
                                'SELECT * FROM CUSTOMER WHERE COUNTRY < :Country', 
                                'CommitAfter=100; EmptyTable; CreateTable; DontQuoteIdents', 
                                cbb);
 
       if (RecCount is not null) then
         ibec_ShowMessage(RecCount || 'records copied successfully.');
 
 
     finally
       ibec_CloseConnection(DB);
       ibec_CloseConnection(OdbcCon);
     end;
   end