Greenbone Vulnerability Manager 22.5.2
sql.h
1/* Copyright (C) 2012-2022 Greenbone AG
2 *
3 * SPDX-License-Identifier: AGPL-3.0-or-later
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Affero General Public License as
7 * published by the Free Software Foundation, either version 3 of the
8 * License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Affero General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19/*
20 * @file sql.h
21 * @brief Headers for Greenbone Vulnerability Manager: the SQL library.
22 */
23
24#ifndef _GVMD_SQL_H
25#define _GVMD_SQL_H
26
27#include "iterator.h"
28#include "manage.h"
29
30#include <glib.h>
31
32/* Helpers. */
33
34const char *
35sql_schema ();
36
37const char *
38sql_greatest ();
39
40const char *
41sql_select_limit (int);
42
43const char *
44sql_regexp_op ();
45
46const char *
47sql_ilike_op ();
48
49const char *
50sql_database ();
51
52const char *
53sql_default_database ();
54
55void
56sql_recursive_triggers_off ();
57
58int
59sql_is_open ();
60
61int
62sql_open (const db_conn_info_t *);
63
64void
65sql_close ();
66
67void
68sql_close_fork ();
69
70int
71sql_changes ();
72
74sql_last_insert_id ();
75
76gchar *
77sql_nquote (const char *, size_t);
78
79gchar *
80sql_quote (const char *);
81
82gchar *
83sql_ascii_escape_and_quote (const char *);
84
85gchar *
86sql_insert (const char *);
87
88void
89sql (char *sql, ...);
90
91int
92sql_error (char *sql, ...);
93
94int
95sql_giveup (char *sql, ...);
96
97double
98sql_double (char *sql, ...);
99
100int
101sql_int (char *, ...);
102
103char *
104sql_string (char *, ...);
105
106int
107sql_int64 (long long int *ret, char *, ...);
108
109long long int
110sql_int64_0 (char *sql, ...);
111
112void
113sql_rename_column (const char *, const char *, const char *, const char *);
114
115int
116sql_cancel_internal ();
117
118/* Transactions. */
119
120void
121sql_begin_immediate ();
122
123int
124sql_begin_immediate_giveup ();
125
126void
127sql_commit ();
128
129void
130sql_rollback ();
131
132/* Iterators. */
133
134/* These functions are for "internal" use. They may only be accessed by code
135 * that is allowed to run SQL statements directly. */
136
137void
138init_iterator (iterator_t *, const char *, ...);
139
140void
141iterator_rewind (iterator_t *iterator);
142
143double
145
146int
147iterator_int (iterator_t *, int);
148
149long long int
151
152int
153iterator_null (iterator_t *, int);
154
155const char *
157
158gchar **
160
161const char *
162iterator_column_name (iterator_t *, int);
163
164int
165iterator_column_count (iterator_t *);
166
167#endif /* not _GVMD_SQL_H */
Headers for Iterators.
long long int resource_t
A resource, like a task or target.
Definition: iterator.h:39
void sql_rename_column(const char *old_table, const char *new_table, const char *old_name, const char *new_name)
Move data from a table to a new table, heeding column rename.
Definition: manage_pg.c:140
double iterator_double(iterator_t *iterator, int col)
Get a double column from an iterator.
Definition: sql.c:621
gchar * sql_insert(const char *string)
Get the SQL insert expression for a string.
Definition: sql.c:198
int sql_giveup(char *sql,...)
Perform an SQL statement, giving up if database is busy or locked.
Definition: sql.c:342
long long int sql_int64_0(char *sql,...)
Get a first column of first row from a SQL query, as an int64.
Definition: sql.c:562
int iterator_int(iterator_t *iterator, int col)
Get a int column from an iterator.
Definition: sql.c:636
void init_iterator(iterator_t *iterator, const char *sql,...)
Initialise an iterator.
Definition: sql.c:592
gchar * sql_quote(const char *string)
Quotes a string to be passed to sql statements.
Definition: sql.c:146
int sql_error(char *sql,...)
Perform an SQL statement, retrying if database is busy or locked.
Definition: sql.c:310
const char * iterator_string(iterator_t *iterator, int col)
Get a string column from an iterator.
Definition: sql.c:666
int sql_int64(long long int *ret, char *sql,...)
Get a particular cell from a SQL query, as an int64.
Definition: sql.c:521
gchar ** iterator_array(iterator_t *iterator, int col)
Get a string column from an iterator.
Definition: sql.c:685
gchar * sql_nquote(const char *string, size_t length)
Quotes a string of a known length to be passed to sql statements.
Definition: sql.c:101
char * sql_string(char *sql,...)
Get a particular cell from a SQL query, as an string.
Definition: sql.c:489
void sql(char *sql,...)
Perform an SQL statement, retrying if database is busy or locked.
Definition: sql.c:269
int sql_int(char *sql,...)
Get a particular cell from a SQL query, as an int.
Definition: sql.c:458
long long int iterator_int64(iterator_t *iterator, int col)
Get an integer column from an iterator.
Definition: sql.c:651
double sql_double(char *sql,...)
Get the first value from a SQL query, as a double.
Definition: sql.c:424
gchar * sql_ascii_escape_and_quote(const char *string)
Quotes a string for use in SQL statements, also ASCII escaping it if it is not valid UTF-8.
Definition: sql.c:161
Data structure for info used to connect to the database.
Definition: manage.h:47
A generic SQL iterator structure.
Definition: iterator.h:50