Greenbone Vulnerability Manager
22.4.0~dev1
|
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>
#include <execinfo.h>
Data Structures | |
struct | sql_stmt |
An SQL statement. More... | |
Macros | |
#define | G_LOG_DOMAIN "md manage" |
GLib log domain. | |
#define | BA_SIZE 100 |
Maximum number of frames in backtrace. More... | |
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_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 PGresult *result) |
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... | |
int | sql_open (const db_conn_info_t *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... | |
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 statement. 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... | |
void | iterator_rewind (iterator_t *iterator) |
Rewind an iterator to the beginning. More... | |
void | sql_finalize (sql_stmt_t *stmt) |
Free a statement. More... | |
double | sql_column_double (sql_stmt_t *stmt, int position) |
Return a column as a double from a statement. More... | |
const char * | sql_column_text (sql_stmt_t *stmt, int position) |
Return a column as text from a statement. More... | |
int | sql_column_int (sql_stmt_t *stmt, int position) |
Return a column as an integer from a statement. More... | |
long long int | sql_column_int64 (sql_stmt_t *stmt, int position) |
Return a column as an int64 from a statement. More... | |
gchar ** | sql_column_array (sql_stmt_t *stmt, int position) |
Return a column as text from a 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.
#define BA_SIZE 100 |
Maximum number of frames in backtrace.
For debugging backtrace in log_notice.
int iterator_null | ( | iterator_t * | iterator, |
int | col | ||
) |
Get whether a column is NULL.
[in] | iterator | Iterator. |
[in] | col | Column offset. |
void iterator_rewind | ( | iterator_t * | iterator | ) |
Rewind an iterator to the beginning.
This lets the caller iterate over the data again.
[in] | iterator | Iterator. |
|
static |
Log a NOTICE message.
[in] | arg | Dummy arg. |
[in] | result | Arg. |
int sql_begin_immediate_giveup | ( | ) |
Begin an immediate transaction.
int sql_cancel_internal | ( | ) |
Cancels the current SQL statement.
int sql_changes | ( | ) |
Return 0.
gchar** sql_column_array | ( | sql_stmt_t * | stmt, |
int | position | ||
) |
Return a column as text from a statement.
It's up to the caller to ensure that there is a row available.
[in] | stmt | Statement. |
[in] | position | Column position. |
double sql_column_double | ( | sql_stmt_t * | stmt, |
int | position | ||
) |
Return a column as a double from a 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 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 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 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 statement.
[in] | retry | Whether to keep retrying while database is busy or locked. |
[in] | stmt | Statement. |
void sql_finalize | ( | sql_stmt_t * | stmt | ) |
Free a 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 db_conn_info_t * | 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. |
const char* sql_regexp_op | ( | ) |
Get regular expression operator.
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. |
int sql_x | ( | char * | sql, |
va_list | args, | ||
sql_stmt_t ** | stmt_return | ||
) |
Get a particular cell from a SQL query.
[in] | sql | Format string for SQL query. |
[in] | args | Arguments for format string. |
[out] | stmt_return | Return from statement. |
|
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.