GNUnet  0.10.x
Functions
sq_prepare.c File Reference

helper functions for executing SQL statements More...

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

Go to the source code of this file.

Functions

struct GNUNET_SQ_PrepareStatement GNUNET_SQ_make_prepare (const char *sql, sqlite3_stmt **pstmt)
 Create a struct GNUNET_SQ_PrepareStatement More...
 
int GNUNET_SQ_prepare (sqlite3 *dbh, const struct GNUNET_SQ_PrepareStatement *ps)
 Prepare all statements given in the (NULL,NULL)-terminated array at ps. More...
 

Detailed Description

helper functions for executing SQL statements

Author
Christian Grothoff

Definition in file sq_prepare.c.

Function Documentation

◆ GNUNET_SQ_make_prepare()

struct GNUNET_SQ_PrepareStatement GNUNET_SQ_make_prepare ( const char *  sql,
sqlite3_stmt **  pstmt 
)

Create a struct GNUNET_SQ_PrepareStatement

Parameters
sqlactual SQL statement
pstmtwhere to store the handle
Returns
initialized struct

Definition at line 37 of file sq_prepare.c.

References GNUNET_SQ_PrepareStatement::pstmt, and GNUNET_SQ_PrepareStatement::sql.

Referenced by database_setup().

39 {
40  struct GNUNET_SQ_PrepareStatement ps = {
41  .sql = sql,
42  .pstmt = pstmt
43  };
44 
45  return ps;
46 }
Information needed to run a list of SQL statements using GNUNET_SQ_exec_statements().
const char * sql
Actual SQL statement.
sqlite3_stmt ** pstmt
Where to store handle?
Here is the caller graph for this function:

◆ GNUNET_SQ_prepare()

int GNUNET_SQ_prepare ( sqlite3 *  dbh,
const struct GNUNET_SQ_PrepareStatement ps 
)

Prepare all statements given in the (NULL,NULL)-terminated array at ps.

Parameters
dbhdatabase to use
psarray of statements to prepare
Returns
GNUNET_OK on success

Definition at line 59 of file sq_prepare.c.

References GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_OK, GNUNET_SYSERR, GNUNET_SQ_PrepareStatement::pstmt, ret, and GNUNET_SQ_PrepareStatement::sql.

Referenced by database_setup().

61 {
62  for (unsigned int i = 0; NULL != ps[i].sql; i++)
63  {
64  const char *epos = NULL;
65  int ret;
66 
67  if (SQLITE_OK !=
68  (ret = sqlite3_prepare_v2(dbh,
69  ps[i].sql,
70  strlen(ps[i].sql),
71  ps[i].pstmt,
72  &epos)))
73  {
75  "Failed to prepare SQL `%s': error %d at %s\n",
76  ps[i].sql,
77  ret,
78  epos);
79  return GNUNET_SYSERR;
80  }
81  }
82  return GNUNET_OK;
83 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
static int ret
Final status code.
Definition: gnunet-arm.c:89
const char * sql
Actual SQL statement.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
#define GNUNET_log(kind,...)
sqlite3_stmt ** pstmt
Where to store handle?
Here is the caller graph for this function: