Components | All | New | MacOS | Windows | Linux | iOS | ||||
Examples | Mac & Win | Server | Client | Guides | Statistic | FMM | Blog | Deprecated | Old |
FM.SQL.CSV
Queries text of SQL result for CSV export.
Component | Version | macOS | Windows | Linux | Server | iOS SDK |
FM FMSQL | 7.0 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |
Parameters
Parameter | Description | Example | Flags |
---|---|---|---|
SQLref | The reference number returned by FM.SQL.Execute function. | $SQLRef | |
firstRow | The index of first row. Default is 0. |
0 | Optional |
lastRow | The index of last row. Default is FM.SQL.RowCount-1 if no value is given. |
5 | Optional |
firstCol | The index of first column. Default is 0. |
0 | Optional |
lastCol | The index of last column. Default is FM.SQL.FieldCount-1 if no value is given. |
6 | Optional |
rowSeparator | The row separator. Default is CR. Can be more than one character. |
Char(13) | Optional |
colSeparator | The column separator. Default is semicolon. Can be more than one character. |
";" | Optional |
flags | Available in MBS FileMaker Plugin 13.0 or newer. Various flags. 1: Pass 1 to put all text values in quotes. |
0 | Optional |
Result
Returns text or error.
Description
Queries text of SQL result for CSV export.You can use this method to quickly get all fields in a given area as text.
If needed, we put values in quotes and escape quotes and newlines.
For numeric values we ask FileMaker to provide text representation, so FileMaker may use dot or comma as decimal divider depending on your locale.
Please use Text.WriteTextFile to write to text file if you need CSV export.
Examples
Query fields and export as text and CSV:
Set Variable [$sql; Value:MBS( "FM.SQL.Execute"; ""; "select * from Clients")]
If [MBS("IsError")]
Show Custom Dialog ["SQL error"; $sql]
Else
Show Custom Dialog ["SQL result"; "got " & MBS( "FM.SQL.RowCount"; $sql ) &" rows with each " & MBS( "FM.SQL.FieldCount"; $sql ) & " …"]
# Write to text file
Set Variable [$text; Value:MBS( "FM.SQL.Text"; $sql )]
Set Variable [$desktopFolder; Value:MBS( "Folders.UserDesktop" )]
Set Variable [$path; Value:MBS( "Path.AddPathComponent"; $desktopFolder; "fields.txt" )]
Set Variable [$r; Value:MBS( "Text.WriteTextFile"; $text; $path; "UTF8")]
# Write to text file
Set Variable [$text; Value:MBS( "FM.SQL.CSV"; $sql )]
Set Variable [$path; Value:MBS( "Path.AddPathComponent"; $desktopFolder; "fields.csv" )]
Set Variable [$r; Value:MBS( "Text.WriteTextFile"; $text; $path; "UTF8")]
# Cleanup
Set Variable [$r; Value:MBS( "FM.SQL.Release"; $sql )]
End If
See also
- FM.SQL.Execute
- FM.SQL.Release
- FM.SQL.RowCount
- FM.SQL.Text
- Folders.UserDesktop
- IsError
- Path.AddPathComponent
- SQL.Execute
- SQL.FieldCount
- Text.WriteTextFile
Release notes
- Version 13.0
- Added new flags parameter to FM.SQL.CSV and Matrix.CSV.
- Changed FM.SQL.Text and FM.SQL.CSV functions to return empty text if there are no rows and no row parameter.
- Version 8.2
- Improved FM.SQL.CSV function to no longer quote numbers.
- Version 7.0
- Added FM.SQL.Text and FM.SQL.CSV.
Blog Entries
- New in MBS FileMaker Plugin 13.0
- MBS FileMaker Plugin, version 13.0pr5
- MBS FileMaker Plugin, version 12.6pr2
- FileMaker records to XML or JSON
- Query FileMaker records as JSON
- MBS FileMaker Plugin, version 8.2pr3
- MBS FileMaker Plugin, version 7.0pr2
FileMaker Magazin
This function checks for a license.
Created 8th January 2017, last changed 31st March 2023