Export Sql query result to csv

Activity

exportToCsv

Description

Extract data from a DbStore into a CSV file

Input :

PropertyName

Rule of use (if revelant)

Type

Required

Default Value

Description

connectionName


STRING

YES


name of the source connection (see DbStore)

QueryFileToken

If QueryFileToken is filled in, the content of the file specified will be used instead of Query

STRING

YES


Filetoken containing the query to execute

Query

STRING


SQL Query to execute

Params


PARAMETERS ARRAY

NO


Query parameters

CommandTimeout


INT

NO


Execution timeout of the SQL query in the database

Separator


CHAR

NO

';'

CSV output separator

OutputFileStoreName


STRING

YES


Output fileStore name

OutputFileName


STRING

YES


Name of the output file (.csv extension will be added automatically)

OutputFileEncoding


STRING

NO


Default is UTF-8 (See here https://learn.microsoft.com/en-us/dotnet/api/system.text.encoding?view=net-9.0 for possible values)

OutputFileCulture


STRING

NO


Default is Invariant Culture (See https://learn.microsoft.com/en-us/dotnet/api/system.globalization.cultureinfo.name?view=net-9.0#system-globalization-cultureinfo-name for possible values)

OutputFileDateTimeCulture

WORKERS 1.12.1+


STRING

NO


All .NET date and time objects are serialized to their text representation in the CSV using their ToString(string? format, IFormatProvider? provider) method. This property is used to determine which culture is used for the provider argument. For “format” strings, see parameters below.

Defaults to null, which usually means https://learn.microsoft.com/en-us/dotnet/fundamentals/runtime-libraries/system-globalization-cultureinfo-invariantculture

OutputFileDateTimeFormats

WORKERS 2.0.0+


OBJECT (DICT)

NO


All .NET date and time objects are serialized to their text representation in the CSV using their ToString(string? format, IFormatProvider? provider) method. This dictionary can be used to tweak the format of most C# date and time object types. The actual type of your date/time object depends on which store/database you read from with this worker and the specific implementation of their C#/.Net driver.

For defaults, see below.

OutputFileDateTimeFormats.DateTimeFormat


STRING

NO

'o'

For https://learn.microsoft.com/en-us/dotnet/api/system.datetime?view=net-8.0 objects, this string is used as the format parameter of their ToString(string? format, IFormatProvider? provider) serialization method. Defaults to “o".

OutputFileDateTimeFormats.DateTimeOffsetFormat


STRING

NO

'o'

For https://learn.microsoft.com/en-us/dotnet/api/system.datetimeoffset?view=net-8.0 objects, this string is used as the format parameter of their ToString(string? format, IFormatProvider? provider) serialization method. Defaults to “o".

OutputFileDateTimeFormats.DateOnlyFormat


STRING

NO


For https://learn.microsoft.com/en-us/dotnet/api/system.dateonly?view=net-8.0 objects, this string is used as the format parameter of their ToString(string? format, IFormatProvider? provider) serialization method. Defaults to null, which uses the format provider defaults.

OutputFileDateTimeFormats.TimeOnlyFormat


STRING

NO


For https://learn.microsoft.com/en-us/dotnet/api/system.timeonly?view=net-8.0 objects, this string is used as the format parameter of their ToString(string? format, IFormatProvider? provider) serialization method. Defaults to null, which uses the format provider defaults.

OutputFileDateTimeFormats.TimeSpanFormat


STRING

NO


For https://learn.microsoft.com/en-us/dotnet/api/system.timespan?view=net-8.0 objects, this string is used as the format parameter of their ToString(string? format, IFormatProvider? provider) serialization method. Defaults to null, which uses the format provider defaults.

Parameters

PropertyName

Type

Required

Default Value

Description

Name

STRING

YES


name of the parameter

Value

STRING

NO


value of the parameter

Output

CSV file token

Example1: Export Simple query in CSV

Input

JSON
{
  "connectionName": "dbStore1",
  "query":"SELECT name, role FROM employees"
  "outputFileStoreName": "ftp1",
  "outputFileName": "employees",
  "outputFileDateTimeCulture": "fr-BE",
  "outputFileDateTimeFormats": {
    "DateTimeFormat": null,
    "DateTimeOffsetFormat": "dddd, MMM dd yyyy HH:mm:ss zzz"
  }
}

Output

JSON
ftp://ftp1/employees.csv

File content

"name";"role"
"bob";"sales"
"frank";"operations"
"billie";"board"