GNUnet  0.20.0
sq_prepare.c File Reference

helper functions for executing SQL statements More...

#include "gnunet_common.h"
#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...
 
enum GNUNET_GenericReturnValue 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 1 of file sq_prepare.c.

40 {
41  struct GNUNET_SQ_PrepareStatement ps = {
42  .sql = sql,
43  .pstmt = pstmt
44  };
45 
46  return ps;
47 }
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?

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

Referenced by database_setup().

Here is the caller graph for this function:

◆ GNUNET_SQ_prepare()

enum GNUNET_GenericReturnValue 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 handle
psarray of statements to prepare
Returns
GNUNET_OK on success

Definition at line 1 of file sq_prepare.c.

53 {
54  for (unsigned int i = 0; NULL != ps[i].sql; i++)
55  {
56  const char *epos = NULL;
57  int ret;
58 
59  if (SQLITE_OK !=
60  (ret = sqlite3_prepare_v2 (dbh,
61  ps[i].sql,
62  strlen (ps[i].sql),
63  ps[i].pstmt,
64  &epos)))
65  {
67  "Failed to prepare SQL `%s': error %d at %s\n",
68  ps[i].sql,
69  ret,
70  epos);
71  return GNUNET_SYSERR;
72  }
73  }
74  return GNUNET_OK;
75 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
#define GNUNET_log(kind,...)
@ GNUNET_OK
@ GNUNET_SYSERR
@ GNUNET_ERROR_TYPE_ERROR

Referenced by database_setup().

Here is the caller graph for this function: