GNUnet  0.11.x
Functions
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...
 
int 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.

References GNUNET_NO, and GNUNET_SQ_ExecuteStatement::sql.

Referenced by database_setup().

37 {
38  struct GNUNET_SQ_ExecuteStatement es = {
39  .sql = sql,
40  .ignore_errors = GNUNET_NO
41  };
42 
43  return es;
44 }
#define GNUNET_NO
Definition: gnunet_common.h:78
Information needed to run a list of SQL statements using GNUNET_SQ_exec_statements().
const char * sql
Actual SQL statement.
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.

References GNUNET_YES, and GNUNET_SQ_ExecuteStatement::sql.

Referenced by database_setup().

56 {
57  struct GNUNET_SQ_ExecuteStatement es = {
58  .sql = sql,
59  .ignore_errors = GNUNET_YES
60  };
61 
62  return es;
63 }
Information needed to run a list of SQL statements using GNUNET_SQ_exec_statements().
const char * sql
Actual SQL statement.
#define GNUNET_YES
Definition: gnunet_common.h:77
Here is the caller graph for this function:

◆ GNUNET_SQ_exec_statements()

int 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.

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_setup().

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 }
int ignore_errors
Should we ignore errors?
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
const char * sql
Actual SQL statement.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
#define GNUNET_log(kind,...)
Here is the caller graph for this function: