7.8. Retrieving Field Data by Name

7.8.1. dbi_result_get_fields

unsigned int dbi_result_get_fields(dbi_result Result, const char *format, ...);

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:

Example usage: dbi_result_get_fields(result, "idnum.%ul lastname.%s", &id_number, &name)

Arguments

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.

Returns

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.

7.8.2. dbi_result_bind_fields

unsigned int dbi_result_bind_fields(dbi_result Result, const char *format, ...);

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.

Arguments

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.

Returns

The number of field binding set up, or DBI_FIELD_ERROR if there was an error.

7.8.3. dbi_result_get_char

signed char dbi_result_get_char(dbi_result Result, const char *fieldname);

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.

Arguments

Result: The target query result.

fieldname: The name of the field to fetch.

Returns

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.

7.8.4. dbi_result_get_uchar

unsigned char dbi_result_get_uchar(dbi_result Result, const char *fieldname);

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.

Arguments

Result: The target query result.

fieldname: The name of the field to fetch.

Returns

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.

7.8.5. dbi_result_get_short

short dbi_result_get_short(dbi_result Result, const char *const char *fieldname);

Fetch the data stored in the speficied field, which contains a short integer (2-byte signed integer).

Arguments

Result: The target query result.

fieldname: The name of the field to fetch.

Returns

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..

7.8.6. dbi_result_get_ushort

unsigned short dbi_result_get_ushort(dbi_result Result, const char *fieldname);

Fetch the data stored in the speficied field, which contains an unsigned short integer (2-byte unsigned integer).

Arguments

Result: The target query result.

fieldname: The name of the field to fetch.

Returns

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..

7.8.7. dbi_result_get_int

int dbi_result_get_int(dbi_result Result, const char *fieldname);

Fetch the data stored in the speficied field, which contains an integer (4-byte signed integer).

Arguments

Result: The target query result.

fieldname: The name of the field to fetch.

Returns

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..

Availability

0.8.0

7.8.8. dbi_result_get_uint

unsigned int dbi_result_get_uint(dbi_result Result, const char *fieldname);

Fetch the data stored in the speficied field, which contains an unsigned integer (4-byte unsigned integer).

Arguments

Result: The target query result.

fieldname: The name of the field to fetch.

Returns

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..

Availability

0.8.0

7.8.9. dbi_result_get_long

int dbi_result_get_long(dbi_result Result, const char *fieldname);

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.

7.8.10. dbi_result_get_ulong

unsigned int dbi_result_get_ulong(dbi_result Result, const char *fieldname);

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.

7.8.11. dbi_result_get_longlong

long long dbi_result_get_longlong(dbi_result Result, const char *fieldname);

Fetch the data stored in the speficied field, which contains a long long integer (8-byte signed integer).

Arguments

Result: The target query result.

fieldname: The name of the field to fetch.

Returns

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..

7.8.12. dbi_result_get_ulonglong

unsigned long long dbi_result_get_ulonglong(dbi_result Result, const char *fieldname);

Fetch the data stored in the speficied field, which contains an unsigned long long integer (8-byte unsigned integer).

Arguments

Result: The target query result.

fieldname: The name of the field to fetch.

Returns

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..

7.8.13. dbi_result_get_float

float dbi_result_get_float(dbi_result Result, const char *fieldname);

Fetch the data stored in the speficied field, which contains a floating-point number.

Arguments

Result: The target query result.

fieldname: The name of the field to fetch.

Returns

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..

7.8.14. dbi_result_get_double

double dbi_result_get_double(dbi_result Result, const char *fieldname);

Fetch the data stored in the speficied field, which contains a double-precision fractional number.

Arguments

Result: The target query result.

fieldname: The name of the field to fetch.

Returns

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..

7.8.15. dbi_result_get_string

const char *dbi_result_get_string(dbi_result Result, const char *fieldname);

Fetch the data stored in the speficied field, which contains a zero-terminated string.

Arguments

Result: The target query result.

fieldname: The name of the field to fetch.

Returns

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.

7.8.16. dbi_result_get_string_copy

char *dbi_result_get_string_copy(dbi_result Result, const char *fieldname);

Fetch the data stored in the speficied field, which contains a zero-terminated string, and return it in an allocated buffer.

Arguments

Result: The target query result.

fieldname: The name of the field to fetch.

Returns

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.

7.8.17. dbi_result_get_binary

const unsigned char *dbi_result_get_binary(dbi_result Result, const char *fieldname);

Fetch the data stored in the speficied field, which contains binary data.

Arguments

Result: The target query result.

fieldname: The name of the field to fetch.

Returns

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.

7.8.18. dbi_result_get_binary_copy

unsigned char *dbi_result_get_binary_copy(dbi_result Result, const char *fieldname);

Fetch the data stored in the speficied field, which contains binary data, and return it in an allocated buffer.

Arguments

Result: The target query result.

fieldname: The name of the field to fetch.

Returns

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.

7.8.19. dbi_result_get_datetime

time_t dbi_result_get_datetime(dbi_result Result, const char *fieldname);

Fetch the data stored in the specified field, which contains a DATE and/or TIME value.

Arguments

Result: The target query result.

fieldname: The name of the field to fetch.

Returns

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.

7.8.20. dbi_result_get_as_longlong

long long dbi_result_get_as_longlong(dbi_result Result, const char *fieldname);

Fetch the data stored in the specified field. Return the contents as a long long integer value, using appropriate casts or conversions if applicable.

Arguments

Result: The target query result.

fieldname: The name of the field to fetch.

Returns

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.

Availability

0.9.0

7.8.21. dbi_result_get_as_string_copy

char *dbi_result_get_as_string_copy(dbi_result Result, const char *fieldname);

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.

Arguments

Result: The target query result.

fieldname: The name of the field to fetch.

Returns

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.

Availability

0.9.0

7.8.22. dbi_result_bind_char

int dbi_result_bind_char(dbi_result Result, const char *fieldname, char *bindto);

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.

Arguments

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.

Returns

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.

7.8.23. dbi_result_bind_uchar

int dbi_result_bind_uchar(dbi_result Result, const char *fieldname, unsigned char *bindto);

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.

Arguments

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.

Returns

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.

7.8.24. dbi_result_bind_short

int dbi_result_bind_short(dbi_result Result, const char *fieldname, short *bindto);

Bind the specified variable to the specified field, which holds a short integer (2-byte signed integer).

Arguments

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.

Returns

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.

7.8.25. dbi_result_bind_ushort

int dbi_result_bind_ushort(dbi_result Result, const char *fieldname, unsigned short *bindto);

Bind the specified variable to the specified field, which holds an unsigned short integer (2-byte unsigned integer).

Arguments

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.

Returns

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.

7.8.26. dbi_result_bind_int

int dbi_result_bind_int(dbi_result Result, const char *fieldname, long *bindto);

Bind the specified variable to the specified field, which holds an integer (4-byte signed integer).

Arguments

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.

Returns

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.

Availability

0.8.0

7.8.27. dbi_result_bind_uint

int dbi_result_bind_uint(dbi_result Result, const char *fieldname, unsigned long *bindto);

Bind the specified variable to the specified field, which holds an unsigned long integer (4-byte unsigned integer).

Arguments

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.

Returns

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.

Availability

0.8.0

7.8.28. dbi_result_bind_long

int dbi_result_bind_long(dbi_result Result, const char *fieldname, long *bindto);

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.

7.8.29. dbi_result_bind_ulong

int dbi_result_bind_ulong(dbi_result Result, const char *fieldname, unsigned long *bindto);

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.

7.8.30. dbi_result_bind_longlong

int dbi_result_bind_longlong(dbi_result Result, const char *fieldname, long long *bindto);

Bind the specified variable to the specified field, which holds a long long integer (8-byte signed integer).

Arguments

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.

Returns

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.

7.8.31. dbi_result_bind_ulonglong

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).

Arguments

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.

Returns

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.

7.8.32. dbi_result_bind_float

int dbi_result_bind_float(dbi_result Result, const char *fieldname, float *bindto);

Bind the specified variable to the specified field, which holds a floating-point number.

Arguments

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.

Returns

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.

7.8.33. dbi_result_bind_double

int dbi_result_bind_double(dbi_result Result, const char *fieldname, double *bindto);

Bind the specified variable to the specified field, which holds a double-precision fractional number.

Arguments

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.

Returns

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.

7.8.34. dbi_result_bind_string

int dbi_result_bind_string(dbi_result Result, const char *fieldname, const char **bindto);

Bind the specified variable to the specified field, which holds a string. The string must not be modified.

Arguments

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.

Returns

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.

7.8.35. dbi_result_bind_binary

int dbi_result_bind_binary(dbi_result Result, const char *fieldname, const unsigned char **bindto);

Bind the specified variable to the specified field, which holds binary BLOB data. The data must not be modified.

Arguments

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.

Returns

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.

7.8.36. dbi_result_bind_string_copy

int dbi_result_bind_string_copy(dbi_result Result, const char *fieldname, char **bindto);

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.

Arguments

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.

Returns

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.

7.8.37. dbi_result_bind_binary_copy

int dbi_result_bind_binary_copy(dbi_result Result, const char *fieldname, unsigned char **bindto);

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.

Arguments

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.

Returns

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.

7.8.38. dbi_result_bind_datetime

int dbi_result_bind_datetime(dbi_result Result, const char *fieldname, time_t *bindto);

Bind the specified variable to the specified field, which holds a DATE and/or TIME value.

Arguments

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.

Returns

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.