Database Independent Abstraction Layer for C: libdbi Programmer's Guide | ||
---|---|---|
Prev | Chapter 7. libdbi API Reference | Next |
Fetch multiple fields from the current result set, using a printf-like syntax. The formatter string specified field names and types, and each field's associated destination variable is passed as an argument following the format string. Fields in the formatter string are separated by spaces, and follow the format "a.%b", where "a" is the name of the field, and "b" is the field type specifier. Make sure you pass the destination variables' memory addresses by prepending the & operator to each variable's name.
Field type specifiers:
%c / %uc: A signed/unsigned character (1-byte)
%h / %uh: A signed/unsigned short integer (2-byte)
%l / %ul: A signed/unsigned integer (4-byte)
%i / %ui: A signed/unsigned integer (4-byte)
%L / %uL: A signed/unsigned long long integer (8-byte)
%f: A floating point number
%d: A double-precision number
%s: A read-only string
%S: A local copy of a string (must be freed by program)
%b: A read-only pointer to binary data
%B: A local copy of binary data (must be freed by program)
%m: A time_t value representing a DATE and/or TIME
Example usage: dbi_result_get_fields(result, "idnum.%ul lastname.%s", &id_number, &name)
Result: The target query result.
format: The field format string as described above.
ARG: (...) Pointers to the destination variables corresponding with each field in the format string.
The number of fields fetched, or DBI_FIELD_ERROR if there was an error. If an invalid field name was specified it will not raise an error, and the other fetched fields will work as usual.
Bind multiple fields in the current result set, using a printf-like syntax. See dbi_result_get_fields for a detailed explanation of the syntax.
Result: The target query result.
format: The field format string as described above.
ARG: (...) Pointers to the destination variables corresponding with each field in the format string.
The number of field binding set up, or DBI_FIELD_ERROR if there was an error.
Fetch the data stored in the speficied field, which contains a character (a 1-byte signed integer). This is the default for the "char" type on the x86 platform, as well as on Mac OS X.
Result: The target query result.
fieldname: The name of the field to fetch.
The data stored in the specified field, or 0 (zero) if an error occurs. In the latter case the error number is DBI_ERROR_BADTYPE, DBI_ERROR_BADIDX, or DBI_ERROR_BADNAME.
Fetch the data stored in the speficied field, which contains an unsigned character (1-byte unsigned integer). This is the default for the "char" type on Linux for PowerPC.
Result: The target query result.
fieldname: The name of the field to fetch.
The data stored in the specified field, or 0 (zero) if an error occurs. In the latter case the error number is DBI_ERROR_BADTYPE, DBI_ERROR_BADIDX, or DBI_ERROR_BADNAME.
Fetch the data stored in the speficied field, which contains a short integer (2-byte signed integer).
Result: The target query result.
fieldname: The name of the field to fetch.
The data stored in the specified field, or 0 (zero) if an error occurs. In the latter case the error number is DBI_ERROR_BADTYPE, DBI_ERROR_BADIDX, or DBI_ERROR_BADNAME..
Fetch the data stored in the speficied field, which contains an unsigned short integer (2-byte unsigned integer).
Result: The target query result.
fieldname: The name of the field to fetch.
The data stored in the specified field, or 0 (zero) if an error occurs. In the latter case the error number is DBI_ERROR_BADTYPE, DBI_ERROR_BADIDX, or DBI_ERROR_BADNAME..
Fetch the data stored in the speficied field, which contains an integer (4-byte signed integer).
Result: The target query result.
fieldname: The name of the field to fetch.
The data stored in the specified field, or 0 (zero) if an error occurs. In the latter case the error number is DBI_ERROR_BADTYPE, DBI_ERROR_BADIDX, or DBI_ERROR_BADNAME..
0.8.0
Fetch the data stored in the speficied field, which contains an unsigned integer (4-byte unsigned integer).
Result: The target query result.
fieldname: The name of the field to fetch.
The data stored in the specified field, or 0 (zero) if an error occurs. In the latter case the error number is DBI_ERROR_BADTYPE, DBI_ERROR_BADIDX, or DBI_ERROR_BADNAME..
0.8.0
This is the same as dbi_result_get_int. The use of this function is deprecated as the name implies the wrong return type on 64-bit platforms.
This is the same as dbi_result_get_uint. The use of this function is deprecated as the name implies the wrong return type on 64-bit platforms.
Fetch the data stored in the speficied field, which contains a long long integer (8-byte signed integer).
Result: The target query result.
fieldname: The name of the field to fetch.
The data stored in the specified field, or 0 (zero) if an error occurs. In the latter case the error number is DBI_ERROR_BADTYPE, DBI_ERROR_BADIDX, or DBI_ERROR_BADNAME..
Fetch the data stored in the speficied field, which contains an unsigned long long integer (8-byte unsigned integer).
Result: The target query result.
fieldname: The name of the field to fetch.
The data stored in the specified field, or 0 (zero) if an error occurs. In the latter case the error number is DBI_ERROR_BADTYPE, DBI_ERROR_BADIDX, or DBI_ERROR_BADNAME..
Fetch the data stored in the speficied field, which contains a floating-point number.
Result: The target query result.
fieldname: The name of the field to fetch.
The data stored in the specified field, which contains a fractional number, or 0 (zero) if an error occurs. In the latter case the error number is DBI_ERROR_BADTYPE, DBI_ERROR_BADIDX, or DBI_ERROR_BADNAME..
Fetch the data stored in the speficied field, which contains a double-precision fractional number.
Result: The target query result.
fieldname: The name of the field to fetch.
The data stored in the specified field, or 0 (zero) if an error occurs. In the latter case the error number is DBI_ERROR_BADTYPE, DBI_ERROR_BADIDX, or DBI_ERROR_BADNAME..
Fetch the data stored in the speficied field, which contains a zero-terminated string.
Result: The target query result.
fieldname: The name of the field to fetch.
The data stored in the specified field, which is a zero-terminated string. If the field contains a NULL value, the function returns a NULL pointer. The string may not be modified, and may not necessarily persist between row fetches. In case of an error, this function returns the string "ERROR". In the latter case the error number is DBI_ERROR_BADTYPE, DBI_ERROR_BADIDX, or DBI_ERROR_BADNAME.
Fetch the data stored in the speficied field, which contains a zero-terminated string, and return it in an allocated buffer.
Result: The target query result.
fieldname: The name of the field to fetch.
The data stored in the specified field as a zero-terminated allocated string. If the field contains a NULL value, the function returns a NULL pointer, and no memory is allocated. The newly allocated string may be modified by the host program, but the program is responsible for freeing the string. In case of an error, this function returns an allocated string reading "ERROR". In that case the error number is DBI_ERROR_BADTYPE, DBI_ERROR_BADIDX, or DBI_ERROR_BADNAME.
Fetch the data stored in the speficied field, which contains binary data.
Result: The target query result.
fieldname: The name of the field to fetch.
The data stored in the specified field. The binary data may contain zero bytes and non-printable characters. Use dbi_result_get_field_length or dbi_result_get_field_length_idx to determine the number of bytes contained in the resulting binary string. The data may not be modified, and may not necessarily persist between row fetches. If the field contains a NULL value, the function returns a NULL pointer. In case of an error, this function returns the string "ERROR". In that case the error number is DBI_ERROR_BADTYPE, DBI_ERROR_BADIDX, or DBI_ERROR_BADNAME.
Fetch the data stored in the speficied field, which contains binary data, and return it in an allocated buffer.
Result: The target query result.
fieldname: The name of the field to fetch.
The data stored in the specified field. The binary data may contain zero bytes and non-printable characters. Use dbi_result_get_field_length or dbi_result_get_field_length_idx to determine the number of bytes contained in the resulting binary string. The newly allocated memory may be modified by the host program, but the program is responsible for freeing the data. If the field contains a NULL value, the function returns a NULL pointer. In case of an error, this function returns the string "ERROR". In that case the error number is DBI_ERROR_BADTYPE, DBI_ERROR_BADIDX, or DBI_ERROR_BADNAME.
Fetch the data stored in the specified field, which contains a DATE and/or TIME value.
Result: The target query result.
fieldname: The name of the field to fetch.
The data stored in the specified field as a time_t value. To convert this into human-readable dates or times, use the C library functions gmtime (3) and localtime (3). In case of an error this function returns 0 (zero) which resolves to the Unix epoch when converted. In case of an error the error number is DBI_ERROR_BADTYPE, DBI_ERROR_BADIDX, or DBI_ERROR_BADNAME.
Fetch the data stored in the specified field. Return the contents as a long long integer value, using appropriate casts or conversions if applicable.
Result: The target query result.
fieldname: The name of the field to fetch.
The data stored in the specified field as a long long integer. Integer and floating point data as well as datetime data are cast to long long. Strings are converted using strtoll(). Empty strings, strings that do not translate into an integer, and binary strings are returned as 0 (zero) without raising an error. In case of an error this function returns 0 (zero) and the error number is DBI_ERROR_BADTYPE, DBI_ERROR_BADIDX, or DBI_ERROR_BADNAME.
0.9.0
Fetch the data stored in the specified field. Return the contents as an allocated string, using appropriate conversions if applicable. The caller is responsible for freeing the returned buffer when done.
Result: The target query result.
fieldname: The name of the field to fetch.
A string representation of the data stored in the specified field. Integer, floating point and datetime data are pretty-printed using snprintf(). Strings are returned as such. Empty strings and binary strings are returned as empty strings without raising an error. In case of an error this function returns the string "ERROR" and the error number is DBI_ERROR_NOMEM, DBI_ERROR_BADTYPE, DBI_ERROR_BADIDX, or DBI_ERROR_BADNAME.
0.9.0
Bind the specified variable to the specified field, which holds a character (a 1-byte signed integer). This is the default for the "char" type on the x86 platform, as well as on Mac OS X.
Result: The target query result.
fieldname: The name of the field to bind to.
bindto: A pointer to the variable that will be updated with the specified field's value.
0 upon success, DBI_BIND_ERROR if there was an error. Possible error numbers are DBI_ERROR_BADPTR, DBI_ERROR_NOMEM, and DBI_ERROR_BADNAME.
Bind the specified variable to the specified field, which holds an unsigned character (1-byte unsigned integer). This is the default for the "char" type on Linux for PowerPC.
Result: The target query result.
fieldname: The name of the field to bind to.
bindto: A pointer to the variable that will be updated with the specified field's value.
0 upon success, DBI_BIND_ERROR if there was an error. Possible error numbers are DBI_ERROR_BADPTR, DBI_ERROR_NOMEM, and DBI_ERROR_BADNAME.
Bind the specified variable to the specified field, which holds a short integer (2-byte signed integer).
Result: The target query result.
fieldname: The name of the field to bind to.
bindto: A pointer to the variable that will be updated with the specified field's value.
0 upon success, DBI_BIND_ERROR if there was an error. Possible error numbers are DBI_ERROR_BADPTR, DBI_ERROR_NOMEM, and DBI_ERROR_BADNAME.
Bind the specified variable to the specified field, which holds an unsigned short integer (2-byte unsigned integer).
Result: The target query result.
fieldname: The name of the field to bind to.
bindto: A pointer to the variable that will be updated with the specified field's value.
0 upon success, DBI_BIND_ERROR if there was an error. Possible error numbers are DBI_ERROR_BADPTR, DBI_ERROR_NOMEM, and DBI_ERROR_BADNAME.
Bind the specified variable to the specified field, which holds an integer (4-byte signed integer).
Result: The target query result.
fieldname: The name of the field to bind to.
bindto: A pointer to the variable that will be updated with the specified field's value.
0 upon success, DBI_BIND_ERROR if there was an error. Possible error numbers are DBI_ERROR_BADPTR, DBI_ERROR_NOMEM, and DBI_ERROR_BADNAME.
0.8.0
Bind the specified variable to the specified field, which holds an unsigned long integer (4-byte unsigned integer).
Result: The target query result.
fieldname: The name of the field to bind to.
bindto: A pointer to the variable that will be updated with the specified field's value.
0 upon success, DBI_BIND_ERROR if there was an error. Possible error numbers are DBI_ERROR_BADPTR, DBI_ERROR_NOMEM, and DBI_ERROR_BADNAME.
0.8.0
The same as dbi_result_bind_int. The use of this function is deprecated as the name implies the wrong return type on 64-bit platforms.
The same as dbi_result_bind_uint. The use of this function is deprecated as the name implies the wrong return type on 64-bit platforms.
Bind the specified variable to the specified field, which holds a long long integer (8-byte signed integer).
Result: The target query result.
fieldname: The name of the field to bind to.
bindto: A pointer to the variable that will be updated with the specified field's value.
0 upon success, DBI_BIND_ERROR if there was an error. Possible error numbers are DBI_ERROR_BADPTR, DBI_ERROR_NOMEM, and DBI_ERROR_BADNAME.
int dbi_result_bind_ulonglong
(dbi_result Result, const char *fieldname, unsigned long long *bindto);
Bind the specified variable to the specified field, which holds an unsigned long long integer (8-byte unsigned integer).
Result: The target query result.
fieldname: The name of the field to bind to.
bindto: A pointer to the variable that will be updated with the specified field's value.
0 upon success, DBI_BIND_ERROR if there was an error. Possible error numbers are DBI_ERROR_BADPTR, DBI_ERROR_NOMEM, and DBI_ERROR_BADNAME.
Bind the specified variable to the specified field, which holds a floating-point number.
Result: The target query result.
fieldname: The name of the field to bind to.
bindto: A pointer to the variable that will be updated with the specified field's value.
0 upon success, DBI_BIND_ERROR if there was an error. Possible error numbers are DBI_ERROR_BADPTR, DBI_ERROR_NOMEM, and DBI_ERROR_BADNAME.
Bind the specified variable to the specified field, which holds a double-precision fractional number.
Result: The target query result.
fieldname: The name of the field to bind to.
bindto: A pointer to the variable that will be updated with the specified field's value.
0 upon success, DBI_BIND_ERROR if there was an error. Possible error numbers are DBI_ERROR_BADPTR, DBI_ERROR_NOMEM, and DBI_ERROR_BADNAME.
Bind the specified variable to the specified field, which holds a string. The string must not be modified.
Result: The target query result.
fieldname: The name of the field to bind to.
bindto: A pointer to the variable that will be updated with the specified field's value.
0 upon success, DBI_BIND_ERROR if there was an error. Possible error numbers are DBI_ERROR_BADPTR, DBI_ERROR_NOMEM, and DBI_ERROR_BADNAME.
Bind the specified variable to the specified field, which holds binary BLOB data. The data must not be modified.
Result: The target query result.
fieldname: The name of the field to bind to.
bindto: A pointer to the variable that will be updated with the specified field's value.
0 upon success, DBI_BIND_ERROR if there was an error. Possible error numbers are DBI_ERROR_BADPTR, DBI_ERROR_NOMEM, and DBI_ERROR_BADNAME.
Bind the specified variable to the specified field, which holds a string. The newly allocated string may be modified by the host program, but the program is responsible for freeing the string.
Result: The target query result.
fieldname: The name of the field to bind to.
bindto: A pointer to the variable that will be updated with the specified field's value.
0 upon success, DBI_BIND_ERROR if there was an error. Possible error numbers are DBI_ERROR_BADPTR, DBI_ERROR_NOMEM, and DBI_ERROR_BADNAME.
Bind the specified variable to the specified field, which holds binary BLOB data. The newly allocated data may be modified by the host program, but the program is responsible for freeing the data.
Result: The target query result.
fieldname: The name of the field to bind to.
bindto: A pointer to the variable that will be updated with the specified field's value.
0 upon success, DBI_BIND_ERROR if there was an error. Possible error numbers are DBI_ERROR_BADPTR, DBI_ERROR_NOMEM, and DBI_ERROR_BADNAME.
Bind the specified variable to the specified field, which holds a DATE and/or TIME value.
Result: The target query result.
fieldname: The name of the field to bind to.
bindto: A pointer to the variable that will be updated with the specified field's value.
0 upon success, DBI_BIND_ERROR if there was an error. Possible error numbers are DBI_ERROR_BADPTR, DBI_ERROR_NOMEM, and DBI_ERROR_BADNAME.