SQL::ConnectionToCSVFile Method
Syntax
dim result as C = ToCSVFile(TargetFile as C, SQLStatement as C [, Arguments as SQL::Arguments] [, IncludeHeaderRow as L = .f. [, RowsToCopy as N = -1[, StartRow as N = -1 [, UpperCaseNames as L = .f. [, DateTimeFormat as C = "" [, DateFormat as C = "" [, TextToSubstituteForBinary as C = "<Binary Data>"]]]]]]]])
Arguments
- TargetFileCharacter
The name of the file to store the data, including the file path.
- SQLStatementCharacter
A SQL SELECT statement.
- ArgumentsSQL::Arguments
Default = null_value(). A SQL::Arguments object. One or more arguments to be resolved when the SELECT statement is executed.
- IncludeHeaderRowLogical
Default = .f.. If true, the first row in the result will be the column names.
- RowsToCopyNumeric
Default = -1 (copy all rows). The number of rows to copy.
- StartRowNumeric
Default = -1 (start with next row in the result set). The starting row.
- UpperCaseNamesLogical
Default = .f.. If true and the header row is included, the header row column names will be converted to uppercase.
- DateTimeFormatCharacter
Default = "". The date time format used to format date time fields in the CSV file. See Date and Time Format Elements for more information about date time formats.
- DateFormatCharacter
Default = "". The date format used to format date fields in the CSV file. See Date and Time Format Elements for more information about date formats.
- TextToSubstituteForBinaryCharacter
Default = "<Binary Data>". A text string used in place of binary data in the CSV file.
Returns
- resultLogical
Returns .T. if the data was successfully saved to a CSV file. If result is .F., the file was not created. Check the result of SQL::ResultSet's callResult object for more info about the error.
Description
Fetch data using a SQL query and save the data to file as a CSV formatted string.
Example
dim cn as SQL::Connection cn.open("::Name::AADemo-Northwind") dim filename as c = "C:\Users\someuser\Documents\orders.csv" dim sql as c = "select FIRST 5 * from orders" ? cn.toCSVFile(filename,sql) = .T.