The SQL statement strings passed to functions
mcosql_execute_query()
andmcosql_execute_statement()
allow application variable values to be substituted into the string according to rules similar to the standardprintf()
format string substitution with some slight differences. Where a per cent "%"
appears in the SQL statement string followed by a single character or an asterisk"*"
, the value of the associated variable in the argument list will be substituted according to the following type specifications:
%b
a onebyte
value of 0 or 1
%f
adouble
value
%i
a signed integer value (4 bytes)
%l
a signed integer value (8 bytes)
%p
the address of an 8 byte integer (for example anautoid
)
%r
astruct
mapped to the record (fields with type string must bechar* type
)
%R
astruct
mapped to the record (fields with typechar<N>
must bechar[N]
type)
%s
achar * value
(associated with astring
orchar<n>
field)
%t
atime_t
value
%u
an unsigned integer value (4 bytes)
%v
aValue*
(address of a variable of typeValue
)
%w
awchar_t*
value (associated with anstring
ornchar<n>
field)When pre-compiling a statement with function
mcosql_prepare_statement()
the variable-length argument list is often intended to bind program variables to columns in the result set of a select statement. In this case what is needed is the address of the variable to receive the result set value. So, formcosql_prepare_statement()
, the following additional substitution types are provided:
%*b
- address of abool
variable
%*f
address of adouble
variable
%*i
address of anint
variable
%*l
address of anint64_t
variable%*p address of an
int64_t
variable (for example anautoid
)%*s address of a
string
variable (i.e.char**
)
%*S
achar *
value (indirect reference to astring
orchar<n>
field)
%*t
address of atime_t
variable
%*w
address of awchar_t*
variable (i.e.wchar_t**
)
%*W
awchar_t *
value (indirect reference to anstring
ornchar<n>
field)Mapping SQL Date and Time fields
In order to map C-language date or time data to the SQL data types, a C application should use an 8-byte
mco_datetime
data type (instead of themco_time
ormco_date
). The date and time types are represented via the 8-bytetpDatetime
type in SQL. (Use the%l
or%*l
substitution specifier as this is an 8-byte
orint64_t
value.)A note on using scientific notation for numeric values
When scientific notation is used for numeric types (eg.
7.5013e+006
instead of7501301
), the number must always begin with a digit. This means that such a number can’t be defined as ”.e1
”, which is allowed by the standard.