OpenVAS Manager  7.0.3~git
sql.h
Go to the documentation of this file.
1 /* OpenVAS Manager
2  * $Id$
3  * Description: Headers for OpenVAS Manager: the SQL library.
4  *
5  * Authors:
6  * Matthew Mundell <matthew.mundell@greenbone.net>
7  *
8  * Copyright:
9  * Copyright (C) 2012 Greenbone Networks GmbH
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24  */
25 
26 #ifndef OPENVAS_MANAGER_SQL_H
27 #define OPENVAS_MANAGER_SQL_H
28 
29 #include "iterator.h"
30 
31 #include <glib.h>
32 
33 
34 /* Helpers. */
35 
36 int
38 
39 const char *
40 sql_schema ();
41 
42 const char *
43 sql_greatest ();
44 
45 const char *
46 sql_select_limit (int);
47 
48 const char *
49 sql_regexp_op ();
50 
51 const char *
52 sql_ilike_op ();
53 
54 const char *
55 sql_database ();
56 
57 const char *
59 
60 int
61 sql_is_open ();
62 
63 int
64 sql_open (const char *);
65 
66 void
67 sql_close ();
68 
69 void
71 
72 int
73 sql_changes ();
74 
77 
78 gchar *
79 sql_nquote (const char *, size_t);
80 
81 gchar *
82 sql_quote (const char *);
83 
84 gchar *
85 sql_insert (const char *);
86 
87 void
88 sql (char * sql, ...);
89 
90 void
91 sqli (resource_t *, char *, ...);
92 
93 int
94 sql_error (char* sql, ...);
95 
96 int
97 sql_giveup (char * sql, ...);
98 
99 void
100 sql_quiet (char * sql, ...);
101 
102 double
103 sql_double (char* sql, ...);
104 
105 int
106 sql_int (char *, ...);
107 
108 char *
109 sql_string (char *, ...);
110 
111 int
112 sql_int64 (long long int * ret, char *, ...);
113 
114 void
115 sql_rename_column (const char *, const char *, const char *, const char *);
116 
117 
118 /* Transactions. */
119 
120 void
122 
123 int
125 
126 void
128 
129 int
131 
132 void
133 sql_commit ();
134 
135 void
136 sql_rollback ();
137 
138 
139 /* Iterators. */
140 
141 /* These functions are for "internal" use. They may only be accessed by code
142  * that is allowed to run SQL statements directly. */
143 
144 void
146 
147 void
148 init_iterator (iterator_t*, const char*, ...);
149 
150 double
152 
153 int
154 iterator_int (iterator_t*, int);
155 
156 long long int
157 iterator_int64 (iterator_t*, int);
158 
159 int
160 iterator_null (iterator_t*, int);
161 
162 const char*
164 
165 const char*
167 
168 int
170 
171 
172 /* Prepared statements. */
173 
174 sql_stmt_t *
175 sql_prepare (const char* sql, ...);
176 
177 int
178 sql_bind_blob (sql_stmt_t *, int, const void *, int);
179 
180 int
181 sql_bind_int64 (sql_stmt_t *, int, long long int *);
182 
183 int
184 sql_bind_text (sql_stmt_t *, int, const gchar *, gsize);
185 
186 int
187 sql_bind_double (sql_stmt_t *, int, double *);
188 
189 int
190 sql_exec (sql_stmt_t *);
191 
192 void
194 
195 int
197 
198 double
200 
201 const char *
202 sql_column_text (sql_stmt_t *, int);
203 
204 int
205 sql_column_int (sql_stmt_t *, int);
206 
207 long long int
209 
210 int
212 
213 #endif /* not OPENVAS_MANAGER_SQL_H */
int sql_is_sqlite3()
Get whether backend is SQLite3.
Definition: sql_pg.c:92
void sql_close_fork()
Close the database in a forked process.
Definition: sql_pg.c:373
int sql_is_open()
Check whether the database is open.
Definition: sql_pg.c:201
void sqli(resource_t *, char *,...)
Perform an SQL statement, retrying if database is busy or locked.
Definition: sql_pg.c:408
const char * sql_schema()
Get main schema name.
Definition: sql_pg.c:103
int sql_begin_exclusive_giveup()
Begin an exclusive transaction, giving up on failure.
Definition: sql_pg.c:610
int sql_bind_double(sql_stmt_t *, int, double *)
Bind a double value to a statement.
Definition: sql_pg.c:787
int sql_int64(long long int *ret, char *,...)
Get a particular cell from a SQL query, as an int64.
Definition: sql.c:501
double sql_column_double(sql_stmt_t *, int)
Return a column as a double from a prepared statement.
Definition: sql_pg.c:868
int sql_giveup(char *sql,...)
Perform an SQL statement, giving up if database is busy or locked.
Definition: sql.c:257
void sql_begin_exclusive()
Begin an exclusive transaction.
Definition: sql_pg.c:598
resource_t sql_last_insert_id()
Get the ID of the last inserted row.
Definition: sql_pg.c:395
const char * iterator_string(iterator_t *, int)
Get a string column from an iterator.
Definition: sql.c:652
const char * sql_greatest()
Get keyword for "greatest" SQL function.
Definition: sql_pg.c:114
A generic SQL iterator.
Definition: iterator.h:52
gchar * sql_insert(const char *)
Get the SQL insert expression for a string.
Definition: sql.c:136
void sql(char *sql,...)
Perform an SQL statement, retrying if database is busy or locked.
Definition: sql.c:199
void sql_rollback()
Roll a transaction back.
Definition: sql_pg.c:658
void sql_rename_column(const char *, const char *, const char *, const char *)
Move data from a table to a new table, heeding column rename.
Definition: manage_pg.c:101
int sql_begin_immediate_giveup()
Begin an immediate transaction.
Definition: sql_pg.c:639
void sql_quiet(char *sql,...)
Perform an SQL statement, without logging.
Definition: sql.c:275
int iterator_int(iterator_t *, int)
Get a int column from an iterator.
Definition: sql.c:622
long long int sql_column_int64(sql_stmt_t *, int)
Return a column as an int64 from a prepared statement.
Definition: sql_pg.c:936
int sql_column_int(sql_stmt_t *, int)
Return a column as an integer from a prepared statement.
Definition: sql_pg.c:906
gchar * sql_quote(const char *)
Quotes a string to be passed to sql statements.
Definition: sql.c:121
int sql_changes()
Return 0.
Definition: sql_pg.c:385
int sql_open(const char *)
Open the database.
Definition: sql_pg.c:250
int sql_exec(sql_stmt_t *)
Execute a prepared statement.
Definition: sql.c:776
const char * iterator_column_name(iterator_t *, int)
Get a column name from an iterator.
Definition: sql_pg.c:691
const char * sql_column_text(sql_stmt_t *, int)
Return a column as text from a prepared statement.
Definition: sql_pg.c:887
int iterator_null(iterator_t *, int)
Get whether a column is NULL.
Definition: sql_pg.c:675
double iterator_double(iterator_t *, int)
Get a double column from an iterator.
Definition: sql.c:607
int sql_error(char *sql,...)
Perform an SQL statement, retrying if database is busy or locked.
Definition: sql.c:229
const char * sql_regexp_op()
Get regular expression operator.
Definition: sql_pg.c:190
gchar * sql_nquote(const char *, size_t)
Quotes a string of a known length to be passed to sql statements.
Definition: sql.c:76
int sql_bind_int64(sql_stmt_t *, int, long long int *)
Bind an int64 value to a statement.
Definition: sql_pg.c:768
void sql_close()
Close the database.
Definition: sql_pg.c:363
void sql_begin_immediate()
Begin an immediate transaction.
Definition: sql_pg.c:627
const char * sql_default_database()
Return name of default database.
Definition: sql_pg.c:237
long long int iterator_int64(iterator_t *, int)
Get an integer column from an iterator.
Definition: sql.c:637
void init_prepared_iterator(iterator_t *, sql_stmt_t *)
Initialise an iterator.
Definition: sql.c:561
double sql_double(char *sql,...)
Get the first value from a SQL query, as a double.
Definition: sql.c:404
int sql_bind_blob(sql_stmt_t *, int, const void *, int)
Bind a blob to a statement.
Definition: sql_pg.c:751
char * sql_string(char *,...)
Get a particular cell from a SQL query, as an string.
Definition: sql.c:469
int iterator_column_count(iterator_t *)
Get number of columns from an iterator.
Definition: sql_pg.c:706
void sql_commit()
Commit a transaction.
Definition: sql_pg.c:649
const char * sql_ilike_op()
Get case insensitive LIKE operator.
Definition: sql_pg.c:179
void init_iterator(iterator_t *, const char *,...)
Initialise an iterator.
Definition: sql.c:577
const char * sql_database()
Return name of current database.
Definition: sql_pg.c:226
int sql_cancel_internal()
Cancels the current SQL statement.
Definition: sql_pg.c:961
int sql_int(char *,...)
Get a particular cell from a SQL query, as an int.
Definition: sql.c:438
const char * sql_select_limit(int)
Setup a LIMIT argument.
Definition: sql_pg.c:127
int sql_bind_text(sql_stmt_t *, int, const gchar *, gsize)
Bind a text value to a statement.
Definition: sql_pg.c:807
int sql_reset(sql_stmt_t *)
Reset a prepared statement.
Definition: sql_pg.c:842
sql_stmt_t * sql_prepare(const char *sql,...)
Prepare a statement.
Definition: sql.c:753
void sql_finalize(sql_stmt_t *)
Free a prepared statement.
Definition: sql_pg.c:824
long long int resource_t
A resource, like a task or target.
Definition: iterator.h:42