|
Greenbone Vulnerability Manager
9.0.1
|
Generic SQL interface: PostgreSQL backend. More...
#include "sql.h"#include <assert.h>#include <endian.h>#include <errno.h>#include <arpa/inet.h>#include <glib.h>#include <inttypes.h>#include <netinet/in.h>#include <libpq-fe.h>#include <stdlib.h>#include <string.h>#include <gvm/base/array.h>Data Structures | |
| struct | sql_stmt |
| An SQL statement. More... | |
Macros | |
| #define | G_LOG_DOMAIN "md manage" |
| GLib log domain. | |
Functions | |
| int | sql_x (char *, va_list args, sql_stmt_t **) |
| Get a particular cell from a SQL query. More... | |
| const char * | sql_schema () |
| Get main schema name. More... | |
| const char * | sql_greatest () |
| Get keyword for "greatest" SQL function. More... | |
| const char * | sql_select_limit (int max) |
| Setup a LIMIT argument. More... | |
| static void | sql_stmt_param_add (sql_stmt_t *stmt, const char *param_value, int param_size, int param_format) |
| Add param to statement. More... | |
| static void | sql_stmt_init (sql_stmt_t *stmt) |
| Init statement, preserving SQL. More... | |
| const char * | sql_ilike_op () |
| Get case insensitive LIKE operator. More... | |
| const char * | sql_regexp_op () |
| Get regular expression operator. More... | |
| int | sql_is_open () |
| Check whether the database is open. More... | |
| static void | log_notice (void *arg, const char *message) |
| Log a NOTICE message. More... | |
| const char * | sql_database () |
| Return name of current database. More... | |
| const char * | sql_default_database () |
| Return name of default database. More... | |
| void | sql_recursive_triggers_off () |
| Turn off recursive triggers. More... | |
| int | sql_open (const char *database) |
| Open the database. More... | |
| void | sql_close () |
| Close the database. | |
| void | sql_close_fork () |
| Close the database in a forked process. | |
| int | sql_changes () |
| Return 0. More... | |
| resource_t | sql_last_insert_id () |
| Get the ID of the last inserted row. More... | |
| void | sqli (resource_t *resource, char *sql,...) |
| Perform an SQL statement, retrying if database is busy or locked. More... | |
| int | sql_prepare_internal (int retry, int log, const char *sql, va_list args, sql_stmt_t **stmt) |
| Prepare a statement. More... | |
| int | sql_exec_internal (int retry, sql_stmt_t *stmt) |
| Execute a prepared statement. More... | |
| int | sql_explain_internal (const char *sql, va_list args) |
| Write debug messages with the query plan for an SQL query to the log. More... | |
| void | sql_begin_immediate () |
| Begin an immediate transaction. | |
| int | sql_begin_immediate_giveup () |
| Begin an immediate transaction. More... | |
| void | sql_commit () |
| Commit a transaction. | |
| void | sql_rollback () |
| Roll a transaction back. | |
| int | iterator_null (iterator_t *iterator, int col) |
| Get whether a column is NULL. More... | |
| static void | bind_param (sql_stmt_t *stmt, int position, const void *param_value, int param_size, int param_format) |
| Bind a param to a statement. More... | |
| int | sql_bind_blob (sql_stmt_t *stmt, int position, const void *value, int value_size) |
| Bind a blob to a statement. More... | |
| int | sql_bind_text (sql_stmt_t *stmt, int position, const gchar *value, gsize value_size) |
| Bind a text value to a statement. More... | |
| void | sql_finalize (sql_stmt_t *stmt) |
| Free a prepared statement. More... | |
| int | sql_reset (sql_stmt_t *stmt) |
| Reset a prepared statement. More... | |
| double | sql_column_double (sql_stmt_t *stmt, int position) |
| Return a column as a double from a prepared statement. More... | |
| const char * | sql_column_text (sql_stmt_t *stmt, int position) |
| Return a column as text from a prepared statement. More... | |
| int | sql_column_int (sql_stmt_t *stmt, int position) |
| Return a column as an integer from a prepared statement. More... | |
| long long int | sql_column_int64 (sql_stmt_t *stmt, int position) |
| Return a column as an int64 from a prepared statement. More... | |
| int | sql_cancel_internal () |
| Cancels the current SQL statement. More... | |
Variables | |
| int | log_errors |
| Whether to log errors. More... | |
| static PGconn * | conn = NULL |
| Handle on the database. | |
Generic SQL interface: PostgreSQL backend.
PostreSQL backend of the SQL interface.
|
static |
Bind a param to a statement.
| [in] | stmt | Statement. |
| [in] | position | Position in statement. |
| [in] | param_value | Param value. |
| [in] | param_size | Param size. |
| [in] | param_format | 0 text, 1 binary. |
| int iterator_null | ( | iterator_t * | iterator, |
| int | col | ||
| ) |
Get whether a column is NULL.
| [in] | iterator | Iterator. |
| [in] | col | Column offset. |
|
static |
Log a NOTICE message.
| [in] | arg | Dummy arg. |
| [in] | message | Arg. |
| int sql_begin_immediate_giveup | ( | ) |
Begin an immediate transaction.
| int sql_bind_blob | ( | sql_stmt_t * | stmt, |
| int | position, | ||
| const void * | value, | ||
| int | value_size | ||
| ) |
Bind a blob to a statement.
| [in] | stmt | Statement. |
| [in] | position | Position in statement. |
| [in] | value | Blob. |
| [in] | value_size | Blob size. |
| int sql_bind_text | ( | sql_stmt_t * | stmt, |
| int | position, | ||
| const gchar * | value, | ||
| gsize | value_size | ||
| ) |
Bind a text value to a statement.
| [in] | stmt | Statement. |
| [in] | position | Position in statement. |
| [in] | value | Value. |
| [in] | value_size | Value size, or -1 to use strlen of value. |
| int sql_cancel_internal | ( | ) |
Cancels the current SQL statement.
| int sql_changes | ( | ) |
Return 0.
| double sql_column_double | ( | sql_stmt_t * | stmt, |
| int | position | ||
| ) |
Return a column as a double from a prepared statement.
It's up to the caller to ensure that there is a row available.
| [in] | stmt | Statement. |
| [in] | position | Column position. |
| int sql_column_int | ( | sql_stmt_t * | stmt, |
| int | position | ||
| ) |
Return a column as an integer from a prepared statement.
It's up to the caller to ensure that there is a row available.
| [in] | stmt | Statement. |
| [in] | position | Column position. |
| long long int sql_column_int64 | ( | sql_stmt_t * | stmt, |
| int | position | ||
| ) |
Return a column as an int64 from a prepared statement.
It's up to the caller to ensure that there is a row available.
| [in] | stmt | Statement. |
| [in] | position | Column position. |
| const char* sql_column_text | ( | sql_stmt_t * | stmt, |
| int | position | ||
| ) |
Return a column as text from a prepared statement.
It's up to the caller to ensure that there is a row available.
| [in] | stmt | Statement. |
| [in] | position | Column position. |
| const char* sql_database | ( | ) |
Return name of current database.
| const char* sql_default_database | ( | ) |
Return name of default database.
| int sql_exec_internal | ( | int | retry, |
| sql_stmt_t * | stmt | ||
| ) |
Execute a prepared statement.
| [in] | retry | Whether to keep retrying while database is busy or locked. |
| [in] | stmt | Statement. |
| int sql_explain_internal | ( | const char * | sql, |
| va_list | args | ||
| ) |
Write debug messages with the query plan for an SQL query to the log.
| [in] | sql | Format string for the SQL query. |
| [in] | args | Format string arguments in a va_list. |
| void sql_finalize | ( | sql_stmt_t * | stmt | ) |
Free a prepared statement.
| [in] | stmt | Statement. |
| const char* sql_greatest | ( | ) |
Get keyword for "greatest" SQL function.
| const char* sql_ilike_op | ( | ) |
Get case insensitive LIKE operator.
| int sql_is_open | ( | ) |
Check whether the database is open.
| resource_t sql_last_insert_id | ( | ) |
Get the ID of the last inserted row.
| int sql_open | ( | const char * | database | ) |
Open the database.
| [in] | database | Database, or NULL for default. |
| int sql_prepare_internal | ( | int | retry, |
| int | log, | ||
| const char * | sql, | ||
| va_list | args, | ||
| sql_stmt_t ** | stmt | ||
| ) |
Prepare a statement.
| [in] | retry | Whether to keep retrying while database is busy or locked. |
| [in] | log | Whether to keep retrying while database is busy or locked. |
| [in] | sql | Format string for SQL statement. |
| [in] | args | Arguments for format string. |
| [out] | stmt | Statement return. |
| void sql_recursive_triggers_off | ( | ) |
Turn off recursive triggers.
Ignored when DB is Postgres.
| const char* sql_regexp_op | ( | ) |
Get regular expression operator.
| int sql_reset | ( | sql_stmt_t * | stmt | ) |
Reset a prepared statement.
| [in] | stmt | Statement. |
| const char* sql_schema | ( | ) |
Get main schema name.
| const char* sql_select_limit | ( | int | max | ) |
Setup a LIMIT argument.
| [in] | max | Max. |
|
static |
Init statement, preserving SQL.
| [in] | stmt | Statement. |
|
static |
Add param to statement.
| [in] | stmt | Statement. |
| [in] | param_value | Value. |
| [in] | param_size | Size. |
| [in] | param_format | 0 text, 1 binary. |
| int sql_x | ( | char * | sql, |
| va_list | args, | ||
| sql_stmt_t ** | stmt_return | ||
| ) |
Get a particular cell from a SQL query.
Do logging as usual.
| [in] | sql | Format string for SQL query. |
| [in] | args | Arguments for format string. |
| [out] | stmt_return | Return from statement. |
| void sqli | ( | resource_t * | resource, |
| char * | sql, | ||
| ... | |||
| ) |
Perform an SQL statement, retrying if database is busy or locked.
| [out] | resource | Last inserted resource. |
| [in] | sql | Format string for SQL statement. |
| [in] | ... | Arguments for format string. |
|
extern |
Whether to log errors.
Used to turn off logging when cancelling statements on exit. Defined in sql.c.
Used to turn off logging when cancelling statements on exit.