GNUnet  0.10.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 56 of file sq_exec.c.

References GNUNET_YES, and GNUNET_SQ_ExecuteStatement::sql.

Referenced by database_setup().

57 {
58  struct GNUNET_SQ_ExecuteStatement es = {
59  .sql = sql,
60  .ignore_errors = GNUNET_YES
61  };
62 
63  return es;
64 }
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 77 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().

79 {
80  for (unsigned int i = 0; NULL != es[i].sql; i++)
81  {
82  char *emsg = NULL;
83 
84  if (SQLITE_OK !=
85  sqlite3_exec(dbh,
86  es[i].sql,
87  NULL,
88  NULL,
89  &emsg))
90  {
91  if (es[i].ignore_errors)
92  {
94  "Failed to run SQL `%s': %s\n",
95  es[i].sql,
96  emsg);
97  }
98  else
99  {
101  "Failed to run SQL `%s': %s\n",
102  es[i].sql,
103  emsg);
104  sqlite3_free(emsg);
105  return GNUNET_SYSERR;
106  }
107  sqlite3_free(emsg);
108  }
109  }
110  return GNUNET_OK;
111 }
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: