export_to_file


Description:

public bool export_to_file (DataModelIOFormat format, string file, int[]? cols, int[]? rows, Set options) throws Error

Exports data contained in this to the file file; the format is specified using the format argument.

Note that the date format used is the one used by the connection from which the data model has been made (as the result of a SELECT statement), or, for other kinds of data models, the default format (refer to get_default) unless the "cnc" property has been set and points to a Connection to use that connection's date format.

Specifically, the parameters in the options list can be:

  • "SEPARATOR": a string value of which the first character is used as a separator in case of CSV export
  • "QUOTE": a string value of which the first character is used as a quote character in case of CSV export. The default if not specified is the double quote character
  • "FIELD_QUOTE": a boolean value which can be set to FALSE if no quote around the individual fields is requeted, in case of CSV export
  • "NAMES_ON_FIRST_LINE": a boolean value which, if set to true and in case of a CSV or TEXT_TABLE export, will add a first line with the name each exported field (note that "FIELDS_NAME" is also accepted as a synonym)
  • "NAME": a string value used to name the exported data if the export format is XML or TEXT_TABLE
  • "OVERWRITE": a boolean value which tells if the file must be over-written if it already exists.
  • "NULL_AS_EMPTY": a boolean value which, if set to true and in case of a CSV or TEXT_TABLE export, will render and NULL value as the empty string (instead of the 'NULL' string)
  • "INVALID_AS_NULL": a boolean value which, if set to true, considers any invalid data (for example for the date related values) as NULL
  • "COLUMN_SEPARATORS": a boolean value which, if set to true, adds a separators lines between each column, if the export format is TEXT_TABLE
  • "SEPARATOR_LINE": a boolean value which, if set to true, adds an horizontal line between column titles and values, if the export format is TEXT_TABLE
  • "ROW_NUMBERS": a boolean value which, if set to true, prepends a column with row numbers, if the export format is TEXT_TABLE
  • "MAX_WIDTH": an integer value which, if greater than 0, makes all the lines truncated to have at most that number of characters, if the export format is TEXT_TABLE

Warning: this function uses a DataModelIter iterator, and if this does not offer a random access (check using get_access_flags), the iterator will be the same as normally used to access data in this previously to calling this method, and this iterator will be moved (point to another row).

Upon errors false will be returned and error will be assigned a Error from the DataModelError domain.

Parameters:

this

a DataModel

format

the format in which to export data

file

the filename to export to

cols

an array containing which columns of this will be exported, or null for all columns

rows

an array containing which rows of this will be exported, or null for all rows

options

list of options for the export

nb_cols

the number of columns in cols

nb_rows

the number of rows in rows

Returns:

TRUE if no error occurred