Greenbone Vulnerability Manager 22.4.1
sql.h
1/* Copyright (C) 2012-2022 Greenbone Networks GmbH
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
97void
98sql_quiet (char *sql, ...);
99
100double
101sql_double (char *sql, ...);
102
103int
104sql_int (char *, ...);
105
106char *
107sql_string (char *, ...);
108
109int
110sql_int64 (long long int *ret, char *, ...);
111
112long long int
113sql_int64_0 (char *sql, ...);
114
115void
116sql_rename_column (const char *, const char *, const char *, const char *);
117
118int
119sql_cancel_internal ();
120
121/* Transactions. */
122
123void
124sql_begin_immediate ();
125
126int
127sql_begin_immediate_giveup ();
128
129void
130sql_commit ();
131
132void
133sql_rollback ();
134
135/* Iterators. */
136
137/* These functions are for "internal" use. They may only be accessed by code
138 * that is allowed to run SQL statements directly. */
139
140void
141init_iterator (iterator_t *, const char *, ...);
142
143void
144iterator_rewind (iterator_t *iterator);
145
146double
148
149int
150iterator_int (iterator_t *, int);
151
152long long int
154
155int
156iterator_null (iterator_t *, int);
157
158const char *
160
161gchar **
163
164const char *
165iterator_column_name (iterator_t *, int);
166
167int
168iterator_column_count (iterator_t *);
169
170#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