3.4. SQL and Database Infrastructure

3.4.1. dbi_conn_connect

int dbi_conn_connect(dbi_conn Conn)

Connects to the database using the options (host, username, password, port, (etc.) set with dbi_set_option() and dbi_set_option_numeric(). See the documentation for each specific database driver for the options it recognizes and requires.

Arguments

Conn: The target connection.

Returns

-1 on failure, zero on success.

3.4.2. dbi_conn_get_db_list

dbi_result dbi_conn_get_db_list(dbi_conn Conn, const char *pattern)

Queries the list of available databases on the server.

Arguments

Conn: The target connection.

pattern: A string pattern that each name must match.

Returns

A query result object, which will contain database names in the first (zeroth) field (for use with the by-index field functions).

3.4.3. dbi_conn_get_table_list

dbi_result dbi_conn_get_table_list(dbi_conn Conn, const char *db, const char *pattern)

Queries the list of available tables in a particular database.

Arguments

Conn: The target connection.

db: The target database name.

pattern: A string pattern that each name must match.

Returns

A query result object, which will contain table names in the first (zeroth) field (for use with the by-index field functions).

3.4.4. dbi_conn_query

dbi_result dbi_conn_query(dbi_conn Conn, const char *formatstr, ...)

Execute the specified SQL query statement.

Arguments

Conn: The target connection.

formatstr: The format string for the SQL statement. It uses the same format as printf().

ARG: (...) Any variables that correspond to the printf-like format string.

Returns

A query result object, or NULL if there was an error.

3.4.5. dbi_conn_query_null

dbi_result dbi_conn_query_null(dbi_conn Conn, const unsigned char *statement, unsigned long st_length)

Execute the specified SQL query statement, which may contain valid NULL characters.

Arguments

Conn: The target connection.

statement: The SQL statement, which may contain binary data.

st_length: The number of characters in the non-null-terminated statement string.

Returns

A query result object, or NULL if there was an error.

3.4.6. dbi_conn_select_db

int dbi_conn_select_db(dbi_conn Conn, const char *db)

Switches to a different database on the server.

Arguments

Conn: The target connection.

db: The target database name.

Returns

-1 on failure, zero on success.

3.4.7. dbi_result_get_conn

dbi_conn dbi_result_get_conn(dbi_result Result)

Returns the connection belonging to the specified result object.

Arguments

Result: The target query result.

Returns

The connection belonging to the target query result.

3.4.8. dbi_result_free

int dbi_result_free(dbi_result Result)

Frees the result's query, disables all stored field bindings, and releases internally stored variables.

Arguments

Result: The target query result.

Returns

-1 on failure, zero on success.

3.4.9. dbi_result_seek_row

int dbi_result_seek_row(dbi_result Result, unsigned int row)

Jump to a specific row in a result set.

Arguments

Result: The target query result.

row: The ordinal number of the row to seek to. The first row is at position 1, not zero.

Returns

The row number that was fetched, or 0 if there is an error.

3.4.10. dbi_result_first_row

int dbi_result_first_row(dbi_result Result)

Jump to the first row in a result set.

Arguments

Result: The target query result.

Returns

The row number that was fetched, or 0 if there is an error.

3.4.11. dbi_result_last_row

int dbi_result_last_row(dbi_result Result)

Jump to the last row in a result set.

Arguments

Result: The target query result.

Returns

The row number that was fetched, or 0 if there is an error.

3.4.12. dbi_result_prev_row

int dbi_result_prev_row(dbi_result Result)

Jump to the previous row in a result set.

Arguments

Result: The target query result.

Returns

The row number that was fetched, or 0 if there is an error.

3.4.13. dbi_result_next_row

int dbi_result_next_row(dbi_result Result)

Jump to the next row in a result set.

Arguments

Result: The target query result.

Returns

The row number that was fetched, or 0 if there is an error.

3.4.14. dbi_result_get_numrows

unsigned int dbi_result_get_numrows(dbi_result Result)

Returns the number of rows in the specified result set.

Arguments

Result: The target query result.

Returns

The number of rows in the result set.

3.4.15. dbi_result_get_numrows_affected

unsigned int dbi_result_get_numrows_affected(dbi_result Result)

Returns the number of rows in the specified result set that were actually modified. Note that not all database servers support this, in which case it will always be zero. See the documentation for each specific driver for details.

Arguments

Result: The target query result.

Returns

The number of modified rows in the result set.