GNUnet 0.22.2
sq_exec.c File Reference

helper functions for executing SQL statements More...

#include "platform.h"
#include "gnunet_sq_lib.h"
Include dependency graph for sq_exec.c:

Go to the source code of this file.

Functions

struct GNUNET_SQ_ExecuteStatement GNUNET_SQ_make_execute (const char *sql)
 Create a struct GNUNET_SQ_ExecuteStatement where errors are fatal. More...
 
struct GNUNET_SQ_ExecuteStatement GNUNET_SQ_make_try_execute (const char *sql)
 Create a struct GNUNET_SQ_ExecuteStatement where errors should be tolerated. More...
 
enum GNUNET_GenericReturnValue GNUNET_SQ_exec_statements (sqlite3 *dbh, const struct GNUNET_SQ_ExecuteStatement *es)
 Request execution of an array of statements es from Postgres. More...
 

Detailed Description

helper functions for executing SQL statements

Author
Christian Grothoff

Definition in file sq_exec.c.

Function Documentation

◆ GNUNET_SQ_make_execute()

struct GNUNET_SQ_ExecuteStatement GNUNET_SQ_make_execute ( const char *  sql)

Create a struct GNUNET_SQ_ExecuteStatement where errors are fatal.

Parameters
sqlactual SQL statement
Returns
initialized struct

Definition at line 36 of file sq_exec.c.

37{
38 struct GNUNET_SQ_ExecuteStatement es = {
39 .sql = sql,
40 .ignore_errors = GNUNET_NO
41 };
42
43 return es;
44}
@ GNUNET_NO
Information needed to run a list of SQL statements using GNUNET_SQ_exec_statements().
const char * sql
Actual SQL statement.

References GNUNET_NO, and GNUNET_SQ_ExecuteStatement::sql.

Referenced by database_setup(), namestore_sqlite_begin_tx(), namestore_sqlite_commit_tx(), namestore_sqlite_create_tables(), namestore_sqlite_drop_tables(), and namestore_sqlite_rollback_tx().

Here is the caller graph for this function:

◆ GNUNET_SQ_make_try_execute()

struct GNUNET_SQ_ExecuteStatement GNUNET_SQ_make_try_execute ( const char *  sql)

Create a struct GNUNET_SQ_ExecuteStatement where errors should be tolerated.

Parameters
sqlactual SQL statement
Returns
initialized struct

Definition at line 55 of file sq_exec.c.

56{
57 struct GNUNET_SQ_ExecuteStatement es = {
58 .sql = sql,
59 .ignore_errors = GNUNET_YES
60 };
61
62 return es;
63}
@ GNUNET_YES

References GNUNET_YES, and GNUNET_SQ_ExecuteStatement::sql.

Referenced by database_prepare(), database_setup(), and namestore_sqlite_create_tables().

Here is the caller graph for this function:

◆ GNUNET_SQ_exec_statements()

enum GNUNET_GenericReturnValue GNUNET_SQ_exec_statements ( sqlite3 *  dbh,
const struct GNUNET_SQ_ExecuteStatement es 
)

Request execution of an array of statements es from Postgres.

Parameters
dbhdatabase to execute the statements over
esGNUNET_PQ_PREPARED_STATEMENT_END-terminated array of prepared statements.
Returns
GNUNET_OK on success (modulo statements where errors can be ignored) GNUNET_SYSERR on error

Definition at line 76 of file sq_exec.c.

78{
79 for (unsigned int i = 0; NULL != es[i].sql; i++)
80 {
81 char *emsg = NULL;
82
83 if (SQLITE_OK !=
84 sqlite3_exec (dbh,
85 es[i].sql,
86 NULL,
87 NULL,
88 &emsg))
89 {
90 if (es[i].ignore_errors)
91 {
93 "Failed to run SQL `%s': %s\n",
94 es[i].sql,
95 emsg);
96 }
97 else
98 {
100 "Failed to run SQL `%s': %s\n",
101 es[i].sql,
102 emsg);
103 sqlite3_free (emsg);
104 return GNUNET_SYSERR;
105 }
106 sqlite3_free (emsg);
107 }
108 }
109 return GNUNET_OK;
110}
#define GNUNET_log(kind,...)
@ GNUNET_OK
@ GNUNET_SYSERR
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_DEBUG

References GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_OK, GNUNET_SYSERR, GNUNET_SQ_ExecuteStatement::ignore_errors, and GNUNET_SQ_ExecuteStatement::sql.

Referenced by database_prepare(), database_setup(), namestore_sqlite_begin_tx(), namestore_sqlite_commit_tx(), namestore_sqlite_create_tables(), namestore_sqlite_drop_tables(), and namestore_sqlite_rollback_tx().

Here is the caller graph for this function: