Greenbone Vulnerability Manager  9.0.1
sql.h
1 /* Copyright (C) 2012-2018 Greenbone Networks GmbH
2  *
3  * SPDX-License-Identifier: GPL-2.0-or-later
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the 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 General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 /*
21  * @file sql.h
22  * @brief Headers for Greenbone Vulnerability Manager: the SQL library.
23  */
24 
25 #ifndef _GVMD_SQL_H
26 #define _GVMD_SQL_H
27 
28 #include "iterator.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
57 
58 int
59 sql_is_open ();
60 
61 int
62 sql_open (const char *);
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_insert (const char *);
84 
85 void
86 sql (char *sql, ...);
87 
88 void
89 sqli (resource_t *, char *, ...);
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 /* Transactions. */
119 
120 void
122 
123 int
125 
126 void
127 sql_commit ();
128 
129 void
130 sql_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 
137 void
139 
140 void
141 init_iterator (iterator_t *, const char *, ...);
142 
143 double
144 iterator_double (iterator_t *, int);
145 
146 int
147 iterator_int (iterator_t *, int);
148 
149 long long int
150 iterator_int64 (iterator_t *, int);
151 
152 int
153 iterator_null (iterator_t *, int);
154 
155 const char *
156 iterator_string (iterator_t *, int);
157 
158 const char *
159 iterator_column_name (iterator_t *, int);
160 
161 int
162 iterator_column_count (iterator_t *);
163 
164 /* Prepared statements. */
165 
166 sql_stmt_t *
167 sql_prepare (const char *sql, ...);
168 
169 int
170 sql_bind_blob (sql_stmt_t *, int, const void *, int);
171 
172 int
173 sql_bind_int64 (sql_stmt_t *, int, long long int *);
174 
175 int
176 sql_bind_text (sql_stmt_t *, int, const gchar *, gsize);
177 
178 int
179 sql_bind_double (sql_stmt_t *, int, double *);
180 
181 int
182 sql_exec (sql_stmt_t *);
183 
184 void
186 
187 int
189 
190 double
192 
193 const char *
194 sql_column_text (sql_stmt_t *, int);
195 
196 int
197 sql_column_int (sql_stmt_t *, int);
198 
199 long long int
201 
202 int
204 
205 #endif /* not _GVMD_SQL_H */
Headers for Iterators.
long long int resource_t
A resource, like a task or target.
Definition: iterator.h:40
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:496
double iterator_double(iterator_t *iterator, int col)
Get a double column from an iterator.
Definition: sql.c:605
int sql_giveup(char *sql,...)
Perform an SQL statement, giving up if database is busy or locked.
Definition: sql.c:270
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:509
int iterator_int(iterator_t *iterator, int col)
Get a int column from an iterator.
Definition: sql.c:620
char * sql_string(char *sql,...)
Get a particular cell from a SQL query, as an string.
Definition: sql.c:436
void init_iterator(iterator_t *iterator, const char *sql,...)
Initialise an iterator.
Definition: sql.c:575
int sql_error(char *sql,...)
Perform an SQL statement, retrying if database is busy or locked.
Definition: sql.c:238
const char * iterator_string(iterator_t *iterator, int col)
Get a string column from an iterator.
Definition: sql.c:650
void init_prepared_iterator(iterator_t *iterator, sql_stmt_t *stmt)
Initialise an iterator.
Definition: sql.c:559
int sql_exec(sql_stmt_t *stmt)
Execute a prepared statement.
Definition: sql.c:756
int sql_int64(long long int *ret, char *sql,...)
Get a particular cell from a SQL query, as an int64.
Definition: sql.c:468
gchar * sql_quote(const char *string)
Quotes a string to be passed to sql statements.
Definition: sql.c:123
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:78
void sql(char *sql,...)
Perform an SQL statement, retrying if database is busy or locked.
Definition: sql.c:207
int sql_int(char *sql,...)
Get a particular cell from a SQL query, as an int.
Definition: sql.c:405
gchar * sql_insert(const char *string)
Get the SQL insert expression for a string.
Definition: sql.c:138
long long int iterator_int64(iterator_t *iterator, int col)
Get an integer column from an iterator.
Definition: sql.c:635
sql_stmt_t * sql_prepare(const char *sql,...)
Prepare a statement.
Definition: sql.c:733
double sql_double(char *sql,...)
Get the first value from a SQL query, as a double.
Definition: sql.c:371
double sql_column_double(sql_stmt_t *stmt, int position)
Return a column as a double from a prepared statement.
Definition: sql_pg.c:809
int sql_column_int(sql_stmt_t *stmt, int position)
Return a column as an integer from a prepared statement.
Definition: sql_pg.c:847
int sql_bind_blob(sql_stmt_t *stmt, int position, const void *value, int value_size)
Bind a blob to a statement.
Definition: sql_pg.c:730
const char * sql_regexp_op()
Get regular expression operator.
Definition: sql_pg.c:183
void sql_close_fork()
Close the database in a forked process.
Definition: sql_pg.c:388
const char * sql_column_text(sql_stmt_t *stmt, int position)
Return a column as text from a prepared statement.
Definition: sql_pg.c:828
int sql_bind_text(sql_stmt_t *stmt, int position, const gchar *value, gsize value_size)
Bind a text value to a statement.
Definition: sql_pg.c:748
void sql_rollback()
Roll a transaction back.
Definition: sql_pg.c:668
void sqli(resource_t *resource, char *sql,...)
Perform an SQL statement, retrying if database is busy or locked.
Definition: sql_pg.c:425
int sql_open(const char *database)
Open the database.
Definition: sql_pg.c:254
void sql_recursive_triggers_off()
Turn off recursive triggers.
Definition: sql_pg.c:241
void sql_commit()
Commit a transaction.
Definition: sql_pg.c:659
void sql_close()
Close the database.
Definition: sql_pg.c:378
const char * sql_database()
Return name of current database.
Definition: sql_pg.c:219
int sql_begin_immediate_giveup()
Begin an immediate transaction.
Definition: sql_pg.c:645
void sql_begin_immediate()
Begin an immediate transaction.
Definition: sql_pg.c:634
int sql_reset(sql_stmt_t *stmt)
Reset a prepared statement.
Definition: sql_pg.c:783
int sql_is_open()
Check whether the database is open.
Definition: sql_pg.c:194
const char * sql_default_database()
Return name of default database.
Definition: sql_pg.c:230
void sql_finalize(sql_stmt_t *stmt)
Free a prepared statement.
Definition: sql_pg.c:765
resource_t sql_last_insert_id()
Get the ID of the last inserted row.
Definition: sql_pg.c:412
const char * sql_schema()
Get main schema name.
Definition: sql_pg.c:96
int sql_changes()
Return 0.
Definition: sql_pg.c:400
const char * sql_select_limit(int max)
Setup a LIMIT argument.
Definition: sql_pg.c:120
int iterator_null(iterator_t *iterator, int col)
Get whether a column is NULL.
Definition: sql_pg.c:685
const char * sql_ilike_op()
Get case insensitive LIKE operator.
Definition: sql_pg.c:172
const char * sql_greatest()
Get keyword for "greatest" SQL function.
Definition: sql_pg.c:107
long long int sql_column_int64(sql_stmt_t *stmt, int position)
Return a column as an int64 from a prepared statement.
Definition: sql_pg.c:877
int sql_cancel_internal()
Cancels the current SQL statement.
Definition: sql_pg.c:902
A generic SQL iterator structure.
Definition: iterator.h:51
An SQL statement.
Definition: sql_pg.c:61