meta data for this page
  •  

ibec_ImportData

ibec_ImportData function implemented. This function returns the number of imported (inserted) records.

Syntax

function ibec_ImportData(TargetConnection : variant; TargetTable : string;

                        ImportType : integer; SourceFile : string; SourceTable : string; 
                        Options : string; Mappings : string; CallbackBlock : string) : variant;

ibec_ImportData imports records from the specified source (SourceFile, SourceTable) into the target database (TargetConnection, TargetTable).

Please note that when using the FixedWidths option for importing data from text files with fixed column widths, the Mappings parameter is mandatory if you import data from a text file with fixed column widths. The syntax of each item in the Mappings string is:

 <source_field_name>=<start_position>,<length>

IBExpert automatically produces an IBEBlock for data import directly in the Import Data window (Block page) so you can always get it there.

The ibec_ImportData function also supports import from XLSX files (Microsoft Excel). You can specify the sheet number (zero based) which you want to process, using the Sheet option for this, i.e.: Sheet=2. If the Sheet option is not specified the first sheet will be processed.

Parameters

Example #1

 execute ibeblock
 as
 begin
   MyDB = ibec_GetDefaultConnection();

    delete from test_import;
    commit;

   cbb = 'execute ibeblock (RecCount integer)
       as
       begin
         if (ibec_mod(RecCount, 100) = 0) then
         ibec_Progress(''Records inserted: '' || RecCount);
       end';

   res = ibec_ImportData(MyDB, 'TEST_IMPORT', __impText, 'D:\import\test_import.csv', '',
                      'RowLast=15000; RowFirst=1001;
                       CSVDelimiter=";"; DecimalSeparator=","; DateSeparator="-"; TimeSeparator=":";
                       DateOrder=DMY; CommitAfter=1000',
                       '',
                       cbb);
   if (res is not null) then
     ibec_ShowMessage(res || ' records imported successfully.');
 end; 

Example #2

 execute ibeblock
 as
 begin
   MyDB = ibec_GetDefaultConnection();

   res = ibec_ImportData(MyDB, 'TEST_IMPORT', __impAccess, 'D:\import\demo.mdb', 'CUSTOMER',
                       '',
                       'CUSTOMER_ID="Customer ID"; 2=3; 3=4',
                       '');
   if (res is not null) then
     ibec_ShowMessage(res || ' records imported successfully.');
 end; 

Example #3

  execute ibeblock
  as
  begin
    ...
    sMappings = 'Field1=1,26;' +
                'Field2=27,26;' +
                'Field3=53,45';

    Res = ibec_ImportData(DB, 'MYTABLE', __impText,
                          'D:\Import\country_fixed_colnames.txt', '',
                          'RowFirst=1; RowLast=255555;
                          TrimStrings;
                          FixedWidths;', :sMappings, cbb);
    ...
  end