Greenbone Vulnerability Manager
8.0.1~git
|
Generic SQL interface: SQLite3 backend. More...
#include "sql.h"
#include "utils.h"
#include <assert.h>
#include <errno.h>
#include <sqlite3.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
Data Structures | |
struct | sql_stmt |
An SQL statement. More... | |
Macros | |
#define | DB_CHUNK_SIZE 1 * 1024 * 1024 |
Chunk size for SQLite memory allocation. | |
#define | G_LOG_DOMAIN "md manage" |
GLib log domain. | |
#define | BUSY_TIMEOUT 1000 |
Busy timeout, in milliseconds. | |
Functions | |
int | sqlv (int, char *, va_list) |
Perform an SQL statement. More... | |
int | sql_is_sqlite3 () |
Get whether backend is SQLite3. 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... | |
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... | |
const char * | sql_database () |
Return file name of current database. More... | |
const char * | sql_default_database () |
Return name of default database file. 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 () |
Get the number of rows changed or inserted in last statement. 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_exclusive () |
Begin an exclusive transaction. | |
int | sql_begin_exclusive_giveup () |
Begin an exclusive transaction, giving up on failure. More... | |
void | sql_begin_immediate () |
Begin an exclusive transaction. More... | |
int | sql_begin_immediate_giveup () |
Begin an exclusive 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... | |
const char * | iterator_column_name (iterator_t *iterator, int col) |
Get a column name from an iterator. More... | |
int | iterator_column_count (iterator_t *iterator) |
Get number of columns from an iterator. 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 | |
sqlite3 * | gvmd_db = NULL |
Handle on the database. | |
Generic SQL interface: SQLite3 backend.
SQLite3 backend of the SQL interface.
int iterator_column_count | ( | iterator_t * | iterator | ) |
Get number of columns from an iterator.
[in] | iterator | Iterator. |
const char* iterator_column_name | ( | iterator_t * | iterator, |
int | col | ||
) |
Get a column name from an iterator.
[in] | iterator | Iterator. |
[in] | col | Column offset. |
int iterator_null | ( | iterator_t * | iterator, |
int | col | ||
) |
Get whether a column is NULL.
[in] | iterator | Iterator. |
[in] | col | Column offset. |
int sql_begin_exclusive_giveup | ( | ) |
Begin an exclusive transaction, giving up on failure.
void sql_begin_immediate | ( | ) |
Begin an exclusive transaction.
Begin an immediate transaction.
int sql_begin_immediate_giveup | ( | ) |
Begin an exclusive transaction.
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 | ( | ) |
Get the number of rows changed or inserted in last statement.
Return 0.
double sql_column_double | ( | sql_stmt_t * | stmt, |
int | position | ||
) |
Return a column as a double from a prepared statement.
[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.
[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.
[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.
[in] | stmt | Statement. |
[in] | position | Column position. |
const char* sql_database | ( | ) |
Return file name of current database.
Return name of current database.
const char* sql_default_database | ( | ) |
Return name of default database file.
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.
int sql_is_sqlite3 | ( | ) |
Get whether backend is SQLite3.
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. |
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. |
int sqlv | ( | int | retry, |
char * | sql, | ||
va_list | args | ||
) |
Perform an SQL statement.
[in] | retry | Whether to keep retrying while database is busy or locked. |
[in] | sql | Format string for SQL statement. |
[in] | args | Arguments for format string. |