Greenbone Vulnerability Manager  22.4.0~dev1
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 
34 const char *
35 sql_schema ();
36 
37 const char *
38 sql_greatest ();
39 
40 const char *
41 sql_select_limit (int);
42 
43 const char *
44 sql_regexp_op ();
45 
46 const char *
47 sql_ilike_op ();
48 
49 const char *
50 sql_database ();
51 
52 const char *
54 
55 void
56 sql_recursive_triggers_off ();
57 
58 int
59 sql_is_open ();
60 
61 int
62 sql_open (const db_conn_info_t *);
63 
64 void
65 sql_close ();
66 
67 void
69 
70 int
71 sql_changes ();
72 
75 
76 gchar *
77 sql_nquote (const char *, size_t);
78 
79 gchar *
80 sql_quote (const char *);
81 
82 gchar *
83 sql_ascii_escape_and_quote (const char *);
84 
85 gchar *
86 sql_insert (const char *);
87 
88 void
89 sql (char *sql, ...);
90 
91 int
92 sql_error (char *sql, ...);
93 
94 int
95 sql_giveup (char *sql, ...);
96 
97 void
98 sql_quiet (char *sql, ...);
99 
100 double
101 sql_double (char *sql, ...);
102 
103 int
104 sql_int (char *, ...);
105 
106 char *
107 sql_string (char *, ...);
108 
109 int
110 sql_int64 (long long int *ret, char *, ...);
111 
112 long long int
113 sql_int64_0 (char *sql, ...);
114 
115 void
116 sql_rename_column (const char *, const char *, const char *, const char *);
117 
118 int
120 
121 /* Transactions. */
122 
123 void
125 
126 int
128 
129 void
130 sql_commit ();
131 
132 void
133 sql_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 
140 void
141 init_iterator (iterator_t *, const char *, ...);
142 
143 void
145 
146 double
147 iterator_double (iterator_t *, int);
148 
149 int
150 iterator_int (iterator_t *, int);
151 
152 long long int
153 iterator_int64 (iterator_t *, int);
154 
155 int
156 iterator_null (iterator_t *, int);
157 
158 const char *
159 iterator_string (iterator_t *, int);
160 
161 gchar **
162 iterator_array (iterator_t *, int);
163 
164 const char *
165 iterator_column_name (iterator_t *, int);
166 
167 int
168 iterator_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 ** iterator_array(iterator_t *iterator, int col)
Get a string column from an iterator.
Definition: sql.c:685
int sql_giveup(char *sql,...)
Perform an SQL statement, giving up if database is busy or locked.
Definition: sql.c:342
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
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
char * sql_string(char *sql,...)
Get a particular cell from a SQL query, as an string.
Definition: sql.c:489
void init_iterator(iterator_t *iterator, const char *sql,...)
Initialise an iterator.
Definition: sql.c:592
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 * sql_quote(const char *string)
Quotes a string to be passed to sql statements.
Definition: sql.c:146
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
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
gchar * sql_insert(const char *string)
Get the SQL insert expression for a string.
Definition: sql.c:198
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
const char * sql_regexp_op()
Get regular expression operator.
Definition: sql_pg.c:165
void sql_close_fork()
Close the database in a forked process.
Definition: sql_pg.c:415
void sql_rollback()
Roll a transaction back.
Definition: sql_pg.c:600
void sql_commit()
Commit a transaction.
Definition: sql_pg.c:591
void sql_close()
Close the database.
Definition: sql_pg.c:405
const char * sql_database()
Return name of current database.
Definition: sql_pg.c:250
int sql_begin_immediate_giveup()
Begin an immediate transaction.
Definition: sql_pg.c:577
void sql_begin_immediate()
Begin an immediate transaction.
Definition: sql_pg.c:566
int sql_is_open()
Check whether the database is open.
Definition: sql_pg.c:176
const char * sql_default_database()
Return name of default database.
Definition: sql_pg.c:261
resource_t sql_last_insert_id()
Get the ID of the last inserted row.
Definition: sql_pg.c:438
const char * sql_schema()
Get main schema name.
Definition: sql_pg.c:95
int sql_changes()
Return 0.
Definition: sql_pg.c:426
const char * sql_select_limit(int max)
Setup a LIMIT argument.
Definition: sql_pg.c:119
int iterator_null(iterator_t *iterator, int col)
Get whether a column is NULL.
Definition: sql_pg.c:617
void iterator_rewind(iterator_t *iterator)
Rewind an iterator to the beginning.
Definition: sql_pg.c:632
const char * sql_ilike_op()
Get case insensitive LIKE operator.
Definition: sql_pg.c:154
const char * sql_greatest()
Get keyword for "greatest" SQL function.
Definition: sql_pg.c:106
int sql_cancel_internal()
Cancels the current SQL statement.
Definition: sql_pg.c:823
int sql_open(const db_conn_info_t *database)
Open the database.
Definition: sql_pg.c:274
Data structure for info used to connect to the database.
Definition: manage.h:47
A generic SQL iterator structure.
Definition: iterator.h:50