buffer
The buffer
command is used to create and/or populate one of these named buffers with data.
Syntax
buffer
name
=
protocol protocol_parameter(s)
Details
The first argument to the buffer
statement is the name of the buffer to create. If a buffer with this name already exists then any data it contains will be overwritten.
There must be a whitespace on both sides of the 'equals' symbol following the buffer name.
The following protocols are supported:
file
buffer
buffername
= file
filename
The file
protocol imports a file directly into a buffer. This can be very useful when developing USE scripts, as the USE script for processing for a JSON file (for example) can be implemented without requiring access to a server.
If the specified buffer name already exists, then a warning will be logged and any data in it will be cleared before importing the file.
data
buffer
buffername
= data
string
The data
protocol populates the buffer with the literal text specified in string. This is useful when extracting embedded JSON. For example, the JSON snippet below contains embedded JSON in the instanceData field:
In this case, the instanceData field can be extracted using a parslet, placed into a new buffer and re-parsed to extract the values within it. Assuming the snippet is in a file called my_data.json
this would be done as follows:
http
buffer
buffername
= http
method url
For full details on the HTTP protocol and its parameters please refer to the http article.
Once the HTTP request has been executed, any data it returned will be contained in the named buffer, even if the data is binary in format (eg: images, audio files or anything else non-human readable).
If the HTTP request returned no data, one of the following will apply:
If the buffer does not already exist then the buffer will not be created
If the buffer already exists then it will be deleted altogether
For details of how to access the data in a named buffer, please refer to the USE script basics article.
odbc
buffer
buffername
= odbc
dsn [username password] query
username and password are optional, but neither or both must be specified
where:
dsn is the ODBC Data Source Name (this should be configured at the OS level)
username and password are the credentials required by the DSN
query is an SQL query
Once the query has been executed, the resulting data is located in the named buffer. It can subsequently be saved as a CSV file to disk using:
save {buffername} as filename.csv
The resulting CSV uses a comma (,
) as the separator and double quotes ("
) as the quoting character. Any fields in the data which contain a comma will be quoted.
odbc_direct
buffer
buffername
= odbc_direct
query
where query is an SQL query.
Executes SQL query against ODBC datasource that is described in set's odbc_connect parameter.
Once the query has been executed, the resulting data is located in the named buffer. It can subsequently be saved as a CSV file to disk using:
save {buffername} as filename.csv
The resulting CSV uses a comma (,
) as the separator and double quotes ("
) as the quoting character. Any fields in the data which contain a comma will be quoted.
Examples
The following examples retrieve data from ODBC and HTTP sources:
Last updated