Exports a table or an SQL request execution result to a CSV file. The file is created in the UTF-8 encoding.
long DatabaseExport(
|
Parameters
database
[in] Database handle received in DatabaseOpen().
table_or_sql
[in] A name of a table or a text of an SQL request whose results are to be exported to a specified file.
filename
[in] A file name for data export. The path is set relative to the MQL5\Files folder.
flags
[in] Combination of flags defining the output to a file. The flags are defined as follows:
DATABASE_EXPORT_HEADER – display a string with field names
DATABASE_EXPORT_INDEX – display string indices
DATABASE_EXPORT_NO_BOM – do not insert BOM mark at the beginning of the file (BOM is inserted by default)
DATABASE_EXPORT_CRLF – use CRLF for line break (the default is LF)
DATABASE_EXPORT_APPEND – add data to the end of an existing file (by default, the file is overwritten). If the file does not exist, it will be created.
DATABASE_EXPORT_QUOTED_STRINGS – display string values in double quotes.
DATABASE_EXPORT_COMMON_FOLDER - a CSV file is created in the common folder of all client terminals \Terminal\Common\File.
separator
[in] Data separator. If NULL is specified, the '\t' tabulation character is used as a separator. An empty string "" is considered a valid separator but the obtained CSV file cannot be read as a table – it is considered as a set of strings.
Return Value
Return the number of exported entries or a negative value in case of an error. To get the error code, use GetLastError(), the possible responses are:
Note
If request results are exported, the SQL request should begin with "SELECT" or "select". In other words, the SQL request cannot alter the database status, otherwise DatabaseExport() fails with an error.
Database string values may contain the conversion character ('\r' or '\r\n' ), as well as the value separator character set in the separator parameter. In this case, be sure to use the DATABASE_EXPORT_QUOTED_STRINGS flag in the 'flags' parameter. If this flag is present, all displayed strings are enclosed in double quotes. If a string contains a double quote, it is replaced by two double quotes.
See also