Greenbone Vulnerability Manager  8.0.1~git
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 int
36 
37 const char *
38 sql_schema ();
39 
40 const char *
41 sql_greatest ();
42 
43 const char *
44 sql_select_limit (int);
45 
46 const char *
47 sql_regexp_op ();
48 
49 const char *
50 sql_ilike_op ();
51 
52 const char *
53 sql_database ();
54 
55 const char *
57 
58 void
60 
61 int
62 sql_is_open ();
63 
64 int
65 sql_open (const char *);
66 
67 void
68 sql_close ();
69 
70 void
72 
73 int
74 sql_changes ();
75 
78 
79 gchar *
80 sql_nquote (const char *, size_t);
81 
82 gchar *
83 sql_quote (const char *);
84 
85 gchar *
86 sql_insert (const char *);
87 
88 void
89 sql (char *sql, ...);
90 
91 void
92 sqli (resource_t *, char *, ...);
93 
94 int
95 sql_error (char *sql, ...);
96 
97 int
98 sql_giveup (char *sql, ...);
99 
100 void
101 sql_quiet (char *sql, ...);
102 
103 double
104 sql_double (char *sql, ...);
105 
106 int
107 sql_int (char *, ...);
108 
109 char *
110 sql_string (char *, ...);
111 
112 int
113 sql_int64 (long long int *ret, char *, ...);
114 
115 long long int
116 sql_int64_0 (char *sql, ...);
117 
118 void
119 sql_rename_column (const char *, const char *, const char *, const char *);
120 
121 /* Transactions. */
122 
123 void
125 
126 int
128 
129 void
131 
132 int
134 
135 void
136 sql_commit ();
137 
138 void
139 sql_rollback ();
140 
141 /* Iterators. */
142 
143 /* These functions are for "internal" use. They may only be accessed by code
144  * that is allowed to run SQL statements directly. */
145 
146 void
148 
149 void
150 init_iterator (iterator_t *, const char *, ...);
151 
152 double
153 iterator_double (iterator_t *, int);
154 
155 int
156 iterator_int (iterator_t *, int);
157 
158 long long int
159 iterator_int64 (iterator_t *, int);
160 
161 int
162 iterator_null (iterator_t *, int);
163 
164 const char *
165 iterator_string (iterator_t *, int);
166 
167 const char *
169 
170 int
172 
173 /* Prepared statements. */
174 
175 sql_stmt_t *
176 sql_prepare (const char *sql, ...);
177 
178 int
179 sql_bind_blob (sql_stmt_t *, int, const void *, int);
180 
181 int
182 sql_bind_int64 (sql_stmt_t *, int, long long int *);
183 
184 int
185 sql_bind_text (sql_stmt_t *, int, const gchar *, gsize);
186 
187 int
188 sql_bind_double (sql_stmt_t *, int, double *);
189 
190 int
191 sql_exec (sql_stmt_t *);
192 
193 void
195 
196 int
198 
199 double
201 
202 const char *
203 sql_column_text (sql_stmt_t *, int);
204 
205 int
206 sql_column_int (sql_stmt_t *, int);
207 
208 long long int
210 
211 int
213 
214 #endif /* not _GVMD_SQL_H */
double iterator_double(iterator_t *iterator, int col)
Get a double column from an iterator.
Definition: sql.c:594
const char * sql_schema()
Get main schema name.
Definition: sql_pg.c:102
const char * sql_select_limit(int max)
Setup a LIMIT argument.
Definition: sql_pg.c:126
int sql_int(char *sql,...)
Get a particular cell from a SQL query, as an int.
Definition: sql.c:395
const char * iterator_column_name(iterator_t *iterator, int col)
Get a column name from an iterator.
Definition: sql_sqlite3.c:612
int sql_reset(sql_stmt_t *stmt)
Reset a prepared statement.
Definition: sql_pg.c:798
int iterator_int(iterator_t *iterator, int col)
Get a int column from an iterator.
Definition: sql.c:610
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:499
int sql_begin_exclusive_giveup()
Begin an exclusive transaction, giving up on failure.
Definition: sql_pg.c:634
int sql_is_open()
Check whether the database is open.
Definition: sql_pg.c:202
void sql_begin_exclusive()
Begin an exclusive transaction.
Definition: sql_pg.c:621
int sql_giveup(char *sql,...)
Perform an SQL statement, giving up if database is busy or locked.
Definition: sql.c:260
A generic SQL iterator structure.
Definition: iterator.h:50
void sql_commit()
Commit a transaction.
Definition: sql_pg.c:671
void sql(char *sql,...)
Perform an SQL statement, retrying if database is busy or locked.
Definition: sql.c:202
int sql_int64(long long int *ret, char *sql,...)
Get a particular cell from a SQL query, as an int64.
Definition: sql.c:458
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:744
const char * sql_default_database()
Return name of default database.
Definition: sql_pg.c:238
int sql_exec(sql_stmt_t *stmt)
Execute a prepared statement.
Definition: sql.c:768
void sql_close_fork()
Close the database in a forked process.
Definition: sql_pg.c:384
int sql_open(const char *database)
Open the database.
Definition: sql_pg.c:262
gchar * sql_quote(const char *string)
Quotes a string to be passed to sql statements.
Definition: sql.c:121
An SQL statement.
Definition: sql_pg.c:57
double sql_double(char *sql,...)
Get the first value from a SQL query, as a double.
Definition: sql.c:361
int sql_begin_immediate_giveup()
Begin an immediate transaction.
Definition: sql_pg.c:657
void sql_finalize(sql_stmt_t *stmt)
Free a prepared statement.
Definition: sql_pg.c:780
const char * sql_greatest()
Get keyword for "greatest" SQL function.
Definition: sql_pg.c:113
void init_prepared_iterator(iterator_t *iterator, sql_stmt_t *stmt)
Initialise an iterator.
Definition: sql.c:548
int sql_cancel_internal()
Cancels the current SQL statement.
Definition: sql_pg.c:917
int sql_is_sqlite3()
Get whether backend is SQLite3.
Definition: sql_pg.c:91
const char * sql_regexp_op()
Get regular expression operator.
Definition: sql_pg.c:191
void sql_recursive_triggers_off()
Turn off recursive triggers.
Definition: sql_pg.c:249
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:892
int sql_changes()
Return 0.
Definition: sql_pg.c:396
int sql_error(char *sql,...)
Perform an SQL statement, retrying if database is busy or locked.
Definition: sql.c:232
void sql_close()
Close the database.
Definition: sql_pg.c:374
const char * sql_column_text(sql_stmt_t *stmt, int position)
Return a column as text from a prepared statement.
Definition: sql_pg.c:843
void sql_begin_immediate()
Begin an immediate transaction.
Definition: sql_pg.c:646
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:764
const char * sql_database()
Return name of current database.
Definition: sql_pg.c:227
int iterator_null(iterator_t *iterator, int col)
Get whether a column is NULL.
Definition: sql_pg.c:696
int iterator_column_count(iterator_t *iterator)
Get number of columns from an iterator.
Definition: sql_sqlite3.c:627
const char * iterator_string(iterator_t *iterator, int col)
Get a string column from an iterator.
Definition: sql.c:642
double sql_column_double(sql_stmt_t *stmt, int position)
Return a column as a double from a prepared statement.
Definition: sql_pg.c:824
int sql_column_int(sql_stmt_t *stmt, int position)
Return a column as an integer from a prepared statement.
Definition: sql_pg.c:862
sql_stmt_t * sql_prepare(const char *sql,...)
Prepare a statement.
Definition: sql.c:745
char * sql_string(char *sql,...)
Get a particular cell from a SQL query, as an string.
Definition: sql.c:426
gchar * sql_insert(const char *string)
Get the SQL insert expression for a string.
Definition: sql.c:136
Headers for Iterators.
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:492
void sqli(resource_t *resource, char *sql,...)
Perform an SQL statement, retrying if database is busy or locked.
Definition: sql_pg.c:421
void init_iterator(iterator_t *iterator, const char *sql,...)
Initialise an iterator.
Definition: sql.c:564
void sql_rollback()
Roll a transaction back.
Definition: sql_pg.c:680
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:75
resource_t sql_last_insert_id()
Get the ID of the last inserted row.
Definition: sql_pg.c:408
const char * sql_ilike_op()
Get case insensitive LIKE operator.
Definition: sql_pg.c:180
long long int iterator_int64(iterator_t *iterator, int col)
Get an integer column from an iterator.
Definition: sql.c:626
long long int resource_t
A resource, like a task or target.
Definition: iterator.h:40