The SQL Statement

Top  Previous  Next

For exports, an SQL SELECTstatement specifies the data you want to extract from the database and pass to the file.  For imports, you can use an INSERT, UPDATE, UPDATE OR INSERT statement to specify the write to the database, or you can call a parameterised executable procedure with EXECUTE PROCEDURE in order to perform the desired DML completely at the server side.

For an export, your SELECT can be a call to a selectable procedure that returns the desired data to dbFile.  It must be a stored procedure that has been written with a SUSPEND command designed to return one set, being the set that is specified for the output file. 

Do not try to call an executable procedure using SELECT.

Statements for Input

For input statements, the standard SQL syntax for specifying unnamed replaceable parameters with a comma-separated list of questionmarks is used.  The dbFile parser treats the set of parameters as a group of variables that, by default, are in the same order in the input file. For example, the following statement might be used to load data from a three-field input record in a delimited file into a table called STATES with columns COUNTRY_CD, STATE_CD and STATE_NAME:

insert into states (

  country_cd, 

  state_cd, 

  state_name

  ) 

values (?,?,?)

NOTE that statement terminators-such as ISQL's default semicolon-and the ISQL SET TERM statement are not valid in the dbFile environment.

dbFile Embedded Field Descriptors

dbFile implements some additional syntactic elements that are enclosed in curly braces and embedded into the SQL statement, following the identifier of the column to which the descriptor applies.  Multiple attributes for a field are comma-separated.  The following example is an element describing some attributes of one incoming field:

{position=10, size=2}

Such elements, which are required for processing fixed format record input and optional for delimited record input, are stripped out before the DSQL request is submitted to the Firebird engine.  The following simple example illustrates the usage of a qualifier element for the same import specified by the previous example:

insert into states (

  country_cd {position=10, size=2},

  state_cd {position=8, size=2},

  state_name {position=71, size=35}

                    ) 

values (?,?,?)

NOTE
Semantics of the attribute qualifiers may vary according to the type of input record.  The position attribute, for example, refers to the position of the field within the record for delimited records while, for fixed-length records, it refers to starting position of the field relative to the beginning of the record.

Supported Qualifiers

The following table lists the qualifiers that are available when constructing embedded field descriptors in your SQL statements.

Qualifier Keyword

Argument

Description

Input/Output

external=XXX

(in association with size attribute)

XXX may be INT or FLOAT

For INT, size must be 1, 2, 4, or 8 for tiny, short, int or long integers

For FLOAT, size must be 4 or 8 for short float or long float respectively

Use when the data item is (or is to be delivered) in an external numeric format.  It is valid only for numeric data.

External formats may not be portable across all platforms.

 

Both, but only for fixed-length record formats

dateform=N

(may be associated with external and/or size attributes:  if so, N must be consistent with both)

N is the number constant to which the dateform is mapped. 
The number constants and the applicable dateforms are described in the topic Date/Time Data

The format of the input date or date/time, for parsing purposes;  or the literal form in which the output date or date/time is to be written.

Fields that are to be read from or written to an external (binary) date/time format are applicable only to fixed-length records.

Both

size=N

N is an integer

Size of the field, in bytes

Both, but not valid for delimited data

position=N

N is a number

1-base starting position applicable to the field in the input  or output record:

for fixed-length records, it is the offset of the start of the field from the beginning of the record
for delimited records, it is number of the field in the field order

Both


Generated Fields

enum

No argument

Generates a value of smallint, integer or BigInt type that is a row count.

For input it must be the only attribute in the embedded element, i.e. {ENUM}.

Both

sysdate

No argument

Generates a value that reads the system date and time. 

For output it is a literal string whose format determined by an accompanying dateform specification.
For input it is a TIMESTAMP and it must be the only attribute in the embedded element, i.e. {SYSDATE}.  It must be mapped to an SQL column of the appropriate date/time type.  It can be cast if necessary.

Both


BLOB-related Attributes

Three attributes-ascii_blob, blob_size amd blob_stream-apply only to input that is destined for writing to BLOB columns.  For details, refer to the topic BLOB Inputs.