DatabaseImport

Imports data from a file into a table.

long  DatabaseImport(
   int           database,          // database handle received in DatabaseOpen
   const string  table,             // name of a table to insert data
   const string  filename,          // name of a file to import data
   uint          flags,             // combination of flags
   const string  separator,         // data separator 
   ulong         skip_rows,         // how many initial strings to skip 
   const string  skip_comments      // string of characters defining comments
   );

Parameters

database

[in]  Database handle received in DatabaseOpen().

table

[in]  Name of a table the data from a file is to be added to.

filename

[in]  CSV file or ZIP archive for reading data. The name may contain subdirectories and is set relative to the MQL5\Files folder.

flags

[in]  Combination of flags.

separator

[in]  Data separator in CSV file.

skip_rows

[in]  Number of initial strings to be skipped when reading data from the file.

skip_comments

[in]  String of characters for designating strings as comments. If any character from skip_comments is detected at the beginning of a string, such a string is considered a comment and is not imported.

Return Value

Return the number of imported strings or -1 in case of an error. To get the error code, use GetLastError(), the possible responses are:

  • ERR_INVALID_PARAMETER (4003)              –  no table name specified (empty string or NULL);
  • ERR_DATABASE_INTERNAL (5120)              – internal database error;
  • ERR_DATABASE_INVALID_HANDLE (5121)   - invalid database handle.

 

Note

If there is no table named table, it is generated automatically. Names and field types in the created table are defined automatically based on the file data.  

 

See also

DatabaseOpen, DatabasePrint