GNUnet 0.21.1
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...
 
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 37 of file sq_prepare.c.

39{
41 .sql = sql,
42 .pstmt = pstmt
43 };
44
45 return ps;
46}
static struct GNUNET_PEERSTORE_Handle * ps
Handle to the PEERSTORE service.
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 ps, GNUNET_SQ_PrepareStatement::pstmt, and GNUNET_SQ_PrepareStatement::sql.

Referenced by database_prepare(), and 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 50 of file sq_prepare.c.

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

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

Referenced by database_prepare(), and database_setup().

Here is the caller graph for this function: