eXtremeSQL Statement Argument Substitution in C

The SQL statement strings passed to functions mcosql_execute_query() and mcosql_execute_statement() allow application variable values to be substituted into the string according to rules similar to the standard printf() 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 one byte value of 0 or 1

%f a double 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 an autoid)

%r a struct mapped to the record (fields with type string must be char* type)

%R a struct mapped to the record (fields with type char<N> must be char[N] type)

%s a char * value (associated with a string or char<n> field)

%t a time_t value

%u an unsigned integer value (4 bytes)

%v a Value* (address of a variable of type Value)

%w a wchar_t* value (associated with a nstring or nchar<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, for mcosql_prepare_statement(), the following additional substitution types are provided:

%*b - address of a bool variable

%*f address of a double variable

%*i address of an int variable

%*l address of an int64_t variable

%*p address of an int64_t variable (for example an autoid)

%*s address of a string variable (i.e. char**)

%*S a char * value (indirect reference to a string or char<n> field)

%*t address of a time_t variable

%*w address of a wchar_t* variable (i.e. wchar_t**)

%*W a wchar_t * value (indirect reference to a nstring or nchar<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 the mco_time or mco_date). The date and time types are represented via the 8-byte tpDatetime type in SQL. (Use the %l or %*l substitution specifier as this is an 8-byte or int64_t value.)

A note on using scientific notation for numeric values

When scientific notation is used for numeric types (eg. 7.5013e+006 instead of 7501301), 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.