DataModel.exportToFile

Exports data contained in model 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 gda.data_handler.DataHandler.getDefault) unless the "cnc" property has been set and points to a #GdaConnection to use that connection's date format.

Specifically, the parameters in the options list can be: <itemizedlist> <listitem><para>"SEPARATOR": a string value of which the first character is used as a separator in case of CSV export </para></listitem> <listitem><para>"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</para></listitem> <listitem><para>"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</para></listitem> <listitem><para>"NAMES_ON_FIRST_LINE": a boolean value which, if set to true and in case of a CSV or GDA_DATA_MODEL_IO_TEXT_TABLE export, will add a first line with the name each exported field (note that "FIELDS_NAME" is also accepted as a synonym)</para></listitem> <listitem><para>"NAME": a string value used to name the exported data if the export format is XML or GDA_DATA_MODEL_IO_TEXT_TABLE</para></listitem> <listitem><para>"OVERWRITE": a boolean value which tells if the file must be over-written if it already exists.</para></listitem> <listitem><para>"NULL_AS_EMPTY": a boolean value which, if set to true and in case of a CSV or GDA_DATA_MODEL_IO_TEXT_TABLE export, will render and NULL value as the empty string (instead of the 'NULL' string)</para></listitem> <listitem><para>"INVALID_AS_NULL": a boolean value which, if set to true, considers any invalid data (for example for the date related values) as NULL</para></listitem> <listitem><para>"COLUMN_SEPARATORS": a boolean value which, if set to true, adds a separators lines between each column, if the export format is GDA_DATA_MODEL_IO_TEXT_TABLE </para></listitem> <listitem><para>"SEPARATOR_LINE": a boolean value which, if set to true, adds an horizontal line between column titles and values, if the export format is GDA_DATA_MODEL_IO_TEXT_TABLE </para></listitem> <listitem><para>"ROW_NUMBERS": a boolean value which, if set to true, prepends a column with row numbers, if the export format is GDA_DATA_MODEL_IO_TEXT_TABLE </para></listitem> <listitem><para>"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 GDA_DATA_MODEL_IO_TEXT_TABLE </para></listitem> </itemizedlist>

Warning: this function uses a #GdaDataModelIter iterator, and if model does not offer a random access (check using gda.data_model.DataModel.getAccessFlags), the iterator will be the same as normally used to access data in model 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 #GError from the #GDA_DATA_MODEL_ERROR domain.

interface DataModel
bool
exportToFile

Parameters

format gda.types.DataModelIOFormat

the format in which to export data

file string

the filename to export to

cols int[]

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

rows int[]

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

options gda.set.Set

list of options for the export

Return Value

Type: bool

TRUE if no error occurred

Throws