GNUnet  0.10.x
Functions
sq_query_helper.c File Reference

helper functions for queries More...

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

Go to the source code of this file.

Functions

static int bind_fixed_blob (void *cls, const void *data, size_t data_len, sqlite3_stmt *stmt, unsigned int off)
 Function called to convert input argument into SQL parameters. More...
 
struct GNUNET_SQ_QueryParam GNUNET_SQ_query_param_fixed_size (const void *ptr, size_t ptr_size)
 Generate query parameter for a buffer ptr of ptr_size bytes. More...
 
static int bind_string (void *cls, const void *data, size_t data_len, sqlite3_stmt *stmt, unsigned int off)
 Function called to convert input argument into SQL parameters. More...
 
struct GNUNET_SQ_QueryParam GNUNET_SQ_query_param_string (const char *ptr)
 Generate query parameter for a string. More...
 
static int bind_rsa_pub (void *cls, const void *data, size_t data_len, sqlite3_stmt *stmt, unsigned int off)
 Function called to convert input argument into SQL parameters. More...
 
struct GNUNET_SQ_QueryParam GNUNET_SQ_query_param_rsa_public_key (const struct GNUNET_CRYPTO_RsaPublicKey *x)
 Generate query parameter for an RSA public key. More...
 
static int bind_rsa_sig (void *cls, const void *data, size_t data_len, sqlite3_stmt *stmt, unsigned int off)
 Function called to convert input argument into SQL parameters. More...
 
struct GNUNET_SQ_QueryParam GNUNET_SQ_query_param_rsa_signature (const struct GNUNET_CRYPTO_RsaSignature *x)
 Generate query parameter for an RSA signature. More...
 
static int bind_abstime (void *cls, const void *data, size_t data_len, sqlite3_stmt *stmt, unsigned int off)
 Function called to convert input argument into SQL parameters. More...
 
struct GNUNET_SQ_QueryParam GNUNET_SQ_query_param_absolute_time (const struct GNUNET_TIME_Absolute *x)
 Generate query parameter for an absolute time value. More...
 
static int bind_nbotime (void *cls, const void *data, size_t data_len, sqlite3_stmt *stmt, unsigned int off)
 Function called to convert input argument into SQL parameters. More...
 
struct GNUNET_SQ_QueryParam GNUNET_SQ_query_param_absolute_time_nbo (const struct GNUNET_TIME_AbsoluteNBO *x)
 Generate query parameter for an absolute time value. More...
 
static int bind_u16 (void *cls, const void *data, size_t data_len, sqlite3_stmt *stmt, unsigned int off)
 Function called to convert input argument into SQL parameters. More...
 
struct GNUNET_SQ_QueryParam GNUNET_SQ_query_param_uint16 (const uint16_t *x)
 Generate query parameter for an uint16_t in host byte order. More...
 
static int bind_u32 (void *cls, const void *data, size_t data_len, sqlite3_stmt *stmt, unsigned int off)
 Function called to convert input argument into SQL parameters. More...
 
struct GNUNET_SQ_QueryParam GNUNET_SQ_query_param_uint32 (const uint32_t *x)
 Generate query parameter for an uint32_t in host byte order. More...
 
static int bind_u64 (void *cls, const void *data, size_t data_len, sqlite3_stmt *stmt, unsigned int off)
 Function called to convert input argument into SQL parameters. More...
 
struct GNUNET_SQ_QueryParam GNUNET_SQ_query_param_uint64 (const uint64_t *x)
 Generate query parameter for an uint16_t in host byte order. More...
 

Detailed Description

helper functions for queries

Author
Christian Grothoff

Definition in file sq_query_helper.c.

Function Documentation

◆ bind_fixed_blob()

static int bind_fixed_blob ( void *  cls,
const void *  data,
size_t  data_len,
sqlite3_stmt *  stmt,
unsigned int  off 
)
static

Function called to convert input argument into SQL parameters.

Parameters
clsclosure
datapointer to input argument
data_lennumber of bytes in data (if applicable)
stmtsqlite statement to bind parameters for
offoffset of the argument to bind in stmt, numbered from 1, so immediately suitable for passing to sqlite3_bind-functions.
Returns
GNUNET_SYSERR on error, GNUNET_OK on success

Definition at line 41 of file sq_query_helper.c.

References GNUNET_OK, and GNUNET_SYSERR.

Referenced by GNUNET_SQ_query_param_fixed_size().

46 {
47  if (SQLITE_OK !=
48  sqlite3_bind_blob64 (stmt,
49  (int) off,
50  data,
51  (sqlite3_uint64) data_len,
52  SQLITE_TRANSIENT))
53  return GNUNET_SYSERR;
54  return GNUNET_OK;
55 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
uint32_t data
The data value.
Here is the caller graph for this function:

◆ GNUNET_SQ_query_param_fixed_size()

struct GNUNET_SQ_QueryParam GNUNET_SQ_query_param_fixed_size ( const void *  ptr,
size_t  ptr_size 
)

Generate query parameter for a buffer ptr of ptr_size bytes.

Parameters
ptrpointer to the query parameter to pass ptr_size number of bytes in ptr

Definition at line 66 of file sq_query_helper.c.

References bind_fixed_blob(), GNUNET_SQ_QueryParam::conv, and GNUNET_SQ_QueryParam::size.

Referenced by namecache_sqlite_cache_block(), namestore_sqlite_store_records(), peerstore_sqlite_store_record(), sqlite_plugin_put(), and sqlite_plugin_remove_key().

68 {
69  struct GNUNET_SQ_QueryParam qp = {
71  .data = ptr,
72  .size = ptr_size,
73  .num_params = 1
74  };
75  return qp;
76 }
static int bind_fixed_blob(void *cls, const void *data, size_t data_len, sqlite3_stmt *stmt, unsigned int off)
Function called to convert input argument into SQL parameters.
Description of a DB query parameter.
Definition: gnunet_sq_lib.h:54
GNUNET_SQ_QueryConverter conv
Function for how to handle this type of entry.
Definition: gnunet_sq_lib.h:60
Here is the call graph for this function:
Here is the caller graph for this function:

◆ bind_string()

static int bind_string ( void *  cls,
const void *  data,
size_t  data_len,
sqlite3_stmt *  stmt,
unsigned int  off 
)
static

Function called to convert input argument into SQL parameters.

Parameters
clsclosure
datapointer to input argument
data_lennumber of bytes in data (if applicable)
stmtsqlite statement to bind parameters for
offoffset of the argument to bind in stmt, numbered from 1, so immediately suitable for passing to sqlite3_bind-functions.
Returns
GNUNET_SYSERR on error, GNUNET_OK on success

Definition at line 91 of file sq_query_helper.c.

References GNUNET_OK, and GNUNET_SYSERR.

Referenced by GNUNET_SQ_query_param_string().

96 {
97  if (NULL == data)
98  {
99  if (SQLITE_OK !=
100  sqlite3_bind_null (stmt,
101  (int) off))
102  return GNUNET_SYSERR;
103  return GNUNET_OK;
104  }
105  if (SQLITE_OK !=
106  sqlite3_bind_text (stmt,
107  (int) off,
108  (const char *) data,
109  -1,
110  SQLITE_TRANSIENT))
111  return GNUNET_SYSERR;
112  return GNUNET_OK;
113 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
uint32_t data
The data value.
Here is the caller graph for this function:

◆ GNUNET_SQ_query_param_string()

struct GNUNET_SQ_QueryParam GNUNET_SQ_query_param_string ( const char *  ptr)

Generate query parameter for a string.

Parameters
ptrpointer to the string query parameter to pass

Definition at line 122 of file sq_query_helper.c.

References bind_string(), GNUNET_SQ_QueryParam::conv, and GNUNET_SQ_QueryParam::num_params.

Referenced by namestore_sqlite_lookup_records(), namestore_sqlite_store_records(), peerstore_sqlite_delete_records(), peerstore_sqlite_iterate_records(), and peerstore_sqlite_store_record().

123 {
124  struct GNUNET_SQ_QueryParam qp = {
125  .conv = &bind_string,
126  .data = ptr,
127  .num_params = 1
128  };
129  return qp;
130 }
Description of a DB query parameter.
Definition: gnunet_sq_lib.h:54
GNUNET_SQ_QueryConverter conv
Function for how to handle this type of entry.
Definition: gnunet_sq_lib.h:60
static int bind_string(void *cls, const void *data, size_t data_len, sqlite3_stmt *stmt, unsigned int off)
Function called to convert input argument into SQL parameters.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ bind_rsa_pub()

static int bind_rsa_pub ( void *  cls,
const void *  data,
size_t  data_len,
sqlite3_stmt *  stmt,
unsigned int  off 
)
static

Function called to convert input argument into SQL parameters.

Parameters
clsclosure
datapointer to input argument
data_lennumber of bytes in data (if applicable)
stmtsqlite statement to bind parameters for
offoffset of the argument to bind in stmt, numbered from 1, so immediately suitable for passing to sqlite3_bind-functions.
Returns
GNUNET_SYSERR on error, GNUNET_OK on success

Definition at line 145 of file sq_query_helper.c.

References buf, data, GNUNET_break, GNUNET_CRYPTO_rsa_public_key_encode(), GNUNET_free, GNUNET_OK, and GNUNET_SYSERR.

Referenced by GNUNET_SQ_query_param_rsa_public_key().

150 {
151  const struct GNUNET_CRYPTO_RsaPublicKey *rsa = data;
152  char *buf;
153  size_t buf_size;
154 
155  GNUNET_break (NULL == cls);
156  buf_size = GNUNET_CRYPTO_rsa_public_key_encode (rsa,
157  &buf);
158  if (SQLITE_OK !=
159  sqlite3_bind_blob64 (stmt,
160  (int) off,
161  buf,
162  (sqlite3_uint64) buf_size,
163  SQLITE_TRANSIENT))
164  {
165  GNUNET_free (buf);
166  return GNUNET_SYSERR;
167  }
168  GNUNET_free (buf);
169  return GNUNET_OK;
170 }
size_t GNUNET_CRYPTO_rsa_public_key_encode(const struct GNUNET_CRYPTO_RsaPublicKey *key, char **buffer)
Encode the public key in a format suitable for storing it into a file.
Definition: crypto_rsa.c:318
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
The public information of an RSA key pair.
Definition: crypto_rsa.c:51
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static char buf[2048]
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
uint32_t data
The data value.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_SQ_query_param_rsa_public_key()

struct GNUNET_SQ_QueryParam GNUNET_SQ_query_param_rsa_public_key ( const struct GNUNET_CRYPTO_RsaPublicKey x)

Generate query parameter for an RSA public key.

The database must contain a BLOB type in the respective position.

Parameters
xthe query parameter to pass.

Definition at line 180 of file sq_query_helper.c.

References bind_rsa_pub(), and GNUNET_SQ_QueryParam::conv.

181 {
182  struct GNUNET_SQ_QueryParam qp = {
183  .conv = &bind_rsa_pub,
184  .data = x,
185  .num_params = 1
186  };
187  return qp;
188 }
Description of a DB query parameter.
Definition: gnunet_sq_lib.h:54
static int bind_rsa_pub(void *cls, const void *data, size_t data_len, sqlite3_stmt *stmt, unsigned int off)
Function called to convert input argument into SQL parameters.
GNUNET_SQ_QueryConverter conv
Function for how to handle this type of entry.
Definition: gnunet_sq_lib.h:60
Here is the call graph for this function:

◆ bind_rsa_sig()

static int bind_rsa_sig ( void *  cls,
const void *  data,
size_t  data_len,
sqlite3_stmt *  stmt,
unsigned int  off 
)
static

Function called to convert input argument into SQL parameters.

Parameters
clsclosure
datapointer to input argument
data_lennumber of bytes in data (if applicable)
stmtsqlite statement to bind parameters for
offoffset of the argument to bind in stmt, numbered from 1, so immediately suitable for passing to sqlite3_bind-functions.
Returns
GNUNET_SYSERR on error, GNUNET_OK on success

Definition at line 203 of file sq_query_helper.c.

References buf, data, GNUNET_break, GNUNET_CRYPTO_rsa_signature_encode(), GNUNET_free, GNUNET_OK, and GNUNET_SYSERR.

Referenced by GNUNET_SQ_query_param_rsa_signature().

208 {
209  const struct GNUNET_CRYPTO_RsaSignature *sig = data;
210  char *buf;
211  size_t buf_size;
212 
213  GNUNET_break (NULL == cls);
214  buf_size = GNUNET_CRYPTO_rsa_signature_encode (sig,
215  &buf);
216  if (SQLITE_OK !=
217  sqlite3_bind_blob64 (stmt,
218  (int) off,
219  buf,
220  (sqlite3_uint64) buf_size,
221  SQLITE_TRANSIENT))
222  {
223  GNUNET_free (buf);
224  return GNUNET_SYSERR;
225  }
226  GNUNET_free (buf);
227  return GNUNET_OK;
228 }
an RSA signature
Definition: crypto_rsa.c:63
size_t GNUNET_CRYPTO_rsa_signature_encode(const struct GNUNET_CRYPTO_RsaSignature *sig, char **buffer)
Encode the given signature in a format suitable for storing it into a file.
Definition: crypto_rsa.c:966
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static char buf[2048]
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
uint32_t data
The data value.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_SQ_query_param_rsa_signature()

struct GNUNET_SQ_QueryParam GNUNET_SQ_query_param_rsa_signature ( const struct GNUNET_CRYPTO_RsaSignature x)

Generate query parameter for an RSA signature.

The database must contain a BLOB type in the respective position.

Parameters
xthe query parameter to pass

Definition at line 238 of file sq_query_helper.c.

References bind_rsa_sig(), and GNUNET_SQ_QueryParam::conv.

239 {
240  struct GNUNET_SQ_QueryParam qp = {
241  .conv = &bind_rsa_sig,
242  .data = x,
243  .num_params = 1
244  };
245  return qp;
246 }
static int bind_rsa_sig(void *cls, const void *data, size_t data_len, sqlite3_stmt *stmt, unsigned int off)
Function called to convert input argument into SQL parameters.
Description of a DB query parameter.
Definition: gnunet_sq_lib.h:54
GNUNET_SQ_QueryConverter conv
Function for how to handle this type of entry.
Definition: gnunet_sq_lib.h:60
Here is the call graph for this function:

◆ bind_abstime()

static int bind_abstime ( void *  cls,
const void *  data,
size_t  data_len,
sqlite3_stmt *  stmt,
unsigned int  off 
)
static

Function called to convert input argument into SQL parameters.

Parameters
clsclosure
datapointer to input argument
data_lennumber of bytes in data (if applicable)
stmtsqlite statement to bind parameters for
offoffset of the argument to bind in stmt, numbered from 1, so immediately suitable for passing to sqlite3_bind-functions.
Returns
GNUNET_SYSERR on error, GNUNET_OK on success

Definition at line 261 of file sq_query_helper.c.

References GNUNET_TIME_Absolute::abs_value_us, data, GNUNET_assert, GNUNET_OK, and GNUNET_SYSERR.

Referenced by GNUNET_SQ_query_param_absolute_time().

266 {
267  const struct GNUNET_TIME_Absolute *u = data;
268  struct GNUNET_TIME_Absolute abs;
269 
270  abs = *u;
271  if (abs.abs_value_us > INT64_MAX)
272  abs.abs_value_us = INT64_MAX;
273  GNUNET_assert (sizeof (uint64_t) == data_len);
274  if (SQLITE_OK !=
275  sqlite3_bind_int64 (stmt,
276  (int) off,
277  (sqlite3_int64) abs.abs_value_us))
278  return GNUNET_SYSERR;
279  return GNUNET_OK;
280 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
uint64_t abs_value_us
The actual value.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
Time for absolute times used by GNUnet, in microseconds.
uint32_t data
The data value.
Here is the caller graph for this function:

◆ GNUNET_SQ_query_param_absolute_time()

struct GNUNET_SQ_QueryParam GNUNET_SQ_query_param_absolute_time ( const struct GNUNET_TIME_Absolute x)

Generate query parameter for an absolute time value.

The database must store a 64-bit integer.

Parameters
xpointer to the query parameter to pass

Definition at line 290 of file sq_query_helper.c.

References bind_abstime(), and GNUNET_SQ_QueryParam::conv.

Referenced by namecache_sqlite_cache_block(), namecache_sqlite_expire_blocks(), peerstore_sqlite_expire_records(), peerstore_sqlite_store_record(), sqlite_plugin_del(), sqlite_plugin_get(), sqlite_plugin_get_closest(), sqlite_plugin_get_expiration(), and sqlite_plugin_put().

291 {
292  struct GNUNET_SQ_QueryParam qp = {
293  .conv = &bind_abstime,
294  .data = x,
295  .size = sizeof (struct GNUNET_TIME_Absolute),
296  .num_params = 1
297  };
298  return qp;
299 }
static int bind_abstime(void *cls, const void *data, size_t data_len, sqlite3_stmt *stmt, unsigned int off)
Function called to convert input argument into SQL parameters.
Description of a DB query parameter.
Definition: gnunet_sq_lib.h:54
GNUNET_SQ_QueryConverter conv
Function for how to handle this type of entry.
Definition: gnunet_sq_lib.h:60
Time for absolute times used by GNUnet, in microseconds.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ bind_nbotime()

static int bind_nbotime ( void *  cls,
const void *  data,
size_t  data_len,
sqlite3_stmt *  stmt,
unsigned int  off 
)
static

Function called to convert input argument into SQL parameters.

Parameters
clsclosure
datapointer to input argument
data_lennumber of bytes in data (if applicable)
stmtsqlite statement to bind parameters for
offoffset of the argument to bind in stmt, numbered from 1, so immediately suitable for passing to sqlite3_bind-functions.
Returns
GNUNET_SYSERR on error, GNUNET_OK on success

Definition at line 314 of file sq_query_helper.c.

References data, GNUNET_assert, GNUNET_OK, GNUNET_SYSERR, and GNUNET_TIME_absolute_ntoh().

Referenced by GNUNET_SQ_query_param_absolute_time_nbo().

319 {
320  const struct GNUNET_TIME_AbsoluteNBO *u = data;
321  struct GNUNET_TIME_Absolute abs;
322 
323  abs = GNUNET_TIME_absolute_ntoh (*u);
324  if (abs.abs_value_us > INT64_MAX)
325  abs.abs_value_us = INT64_MAX;
326  GNUNET_assert (sizeof (uint64_t) == data_len);
327  if (SQLITE_OK !=
328  sqlite3_bind_int64 (stmt,
329  (int) off,
330  (sqlite3_int64) abs.abs_value_us))
331  return GNUNET_SYSERR;
332  return GNUNET_OK;
333 }
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
Definition: time.c:670
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
Time for absolute time used by GNUnet, in microseconds and in network byte order. ...
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
Time for absolute times used by GNUnet, in microseconds.
uint32_t data
The data value.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_SQ_query_param_absolute_time_nbo()

struct GNUNET_SQ_QueryParam GNUNET_SQ_query_param_absolute_time_nbo ( const struct GNUNET_TIME_AbsoluteNBO x)

Generate query parameter for an absolute time value.

The database must store a 64-bit integer.

Parameters
xpointer to the query parameter to pass

Definition at line 343 of file sq_query_helper.c.

References bind_nbotime(), and GNUNET_SQ_QueryParam::conv.

344 {
345  struct GNUNET_SQ_QueryParam qp = {
346  .conv = &bind_nbotime,
347  .data = x,
348  .size = sizeof (struct GNUNET_TIME_AbsoluteNBO),
349  .num_params = 1
350  };
351  return qp;
352 }
Time for absolute time used by GNUnet, in microseconds and in network byte order. ...
static int bind_nbotime(void *cls, const void *data, size_t data_len, sqlite3_stmt *stmt, unsigned int off)
Function called to convert input argument into SQL parameters.
Description of a DB query parameter.
Definition: gnunet_sq_lib.h:54
GNUNET_SQ_QueryConverter conv
Function for how to handle this type of entry.
Definition: gnunet_sq_lib.h:60
Here is the call graph for this function:

◆ bind_u16()

static int bind_u16 ( void *  cls,
const void *  data,
size_t  data_len,
sqlite3_stmt *  stmt,
unsigned int  off 
)
static

Function called to convert input argument into SQL parameters.

Parameters
clsclosure
datapointer to input argument
data_lennumber of bytes in data (if applicable)
stmtsqlite statement to bind parameters for
offoffset of the argument to bind in stmt, numbered from 1, so immediately suitable for passing to sqlite3_bind-functions.
Returns
GNUNET_SYSERR on error, GNUNET_OK on success

Definition at line 367 of file sq_query_helper.c.

References data, GNUNET_assert, GNUNET_OK, and GNUNET_SYSERR.

Referenced by GNUNET_SQ_query_param_uint16().

372 {
373  const uint16_t *u = data;
374 
375  GNUNET_assert (sizeof (uint16_t) == data_len);
376  if (SQLITE_OK !=
377  sqlite3_bind_int (stmt,
378  (int) off,
379  (int) *u))
380  return GNUNET_SYSERR;
381  return GNUNET_OK;
382 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
uint32_t data
The data value.
Here is the caller graph for this function:

◆ GNUNET_SQ_query_param_uint16()

struct GNUNET_SQ_QueryParam GNUNET_SQ_query_param_uint16 ( const uint16_t *  x)

Generate query parameter for an uint16_t in host byte order.

Parameters
xpointer to the query parameter to pass

Definition at line 391 of file sq_query_helper.c.

References bind_u16(), GNUNET_SQ_QueryParam::conv, and GNUNET_SQ_QueryParam::num_params.

392 {
393  struct GNUNET_SQ_QueryParam qp = {
394  .conv = &bind_u16,
395  .data = x,
396  .size = sizeof (uint16_t),
397  .num_params = 1
398  };
399  return qp;
400 }
static int bind_u16(void *cls, const void *data, size_t data_len, sqlite3_stmt *stmt, unsigned int off)
Function called to convert input argument into SQL parameters.
unsigned int num_params
Number of parameters eaten by this operation.
Definition: gnunet_sq_lib.h:80
Description of a DB query parameter.
Definition: gnunet_sq_lib.h:54
GNUNET_SQ_QueryConverter conv
Function for how to handle this type of entry.
Definition: gnunet_sq_lib.h:60
Here is the call graph for this function:

◆ bind_u32()

static int bind_u32 ( void *  cls,
const void *  data,
size_t  data_len,
sqlite3_stmt *  stmt,
unsigned int  off 
)
static

Function called to convert input argument into SQL parameters.

Parameters
clsclosure
datapointer to input argument
data_lennumber of bytes in data (if applicable)
stmtsqlite statement to bind parameters for
offoffset of the argument to bind in stmt, numbered from 1, so immediately suitable for passing to sqlite3_bind-functions.
Returns
GNUNET_SYSERR on error, GNUNET_OK on success

Definition at line 415 of file sq_query_helper.c.

References data, GNUNET_assert, GNUNET_OK, and GNUNET_SYSERR.

Referenced by GNUNET_SQ_query_param_uint32().

420 {
421  const uint32_t *u = data;
422 
423  GNUNET_assert (sizeof (uint32_t) == data_len);
424  if (SQLITE_OK !=
425  sqlite3_bind_int64 (stmt,
426  (int) off,
427  (sqlite3_int64) *u))
428  return GNUNET_SYSERR;
429  return GNUNET_OK;
430 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
uint32_t data
The data value.
Here is the caller graph for this function:

◆ GNUNET_SQ_query_param_uint32()

struct GNUNET_SQ_QueryParam GNUNET_SQ_query_param_uint32 ( const uint32_t *  x)

Generate query parameter for an uint32_t in host byte order.

Parameters
xpointer to the query parameter to pass

Definition at line 438 of file sq_query_helper.c.

References bind_u32(), GNUNET_SQ_QueryParam::conv, and GNUNET_SQ_QueryParam::num_params.

Referenced by namestore_sqlite_store_records(), sqlite_plugin_get(), sqlite_plugin_get_closest(), sqlite_plugin_get_key(), sqlite_plugin_get_random(), sqlite_plugin_get_replication(), sqlite_plugin_get_zero_anonymity(), and sqlite_plugin_put().

439 {
440  struct GNUNET_SQ_QueryParam qp = {
441  .conv = &bind_u32,
442  .data = x,
443  .size = sizeof (uint32_t),
444  .num_params = 1
445  };
446  return qp;
447 }
unsigned int num_params
Number of parameters eaten by this operation.
Definition: gnunet_sq_lib.h:80
static int bind_u32(void *cls, const void *data, size_t data_len, sqlite3_stmt *stmt, unsigned int off)
Function called to convert input argument into SQL parameters.
Description of a DB query parameter.
Definition: gnunet_sq_lib.h:54
GNUNET_SQ_QueryConverter conv
Function for how to handle this type of entry.
Definition: gnunet_sq_lib.h:60
Here is the call graph for this function:
Here is the caller graph for this function:

◆ bind_u64()

static int bind_u64 ( void *  cls,
const void *  data,
size_t  data_len,
sqlite3_stmt *  stmt,
unsigned int  off 
)
static

Function called to convert input argument into SQL parameters.

Parameters
clsclosure
datapointer to input argument
data_lennumber of bytes in data (if applicable)
stmtsqlite statement to bind parameters for
offoffset of the argument to bind in stmt, numbered from 1, so immediately suitable for passing to sqlite3_bind-functions.
Returns
GNUNET_SYSERR on error, GNUNET_OK on success

Definition at line 462 of file sq_query_helper.c.

References data, GNUNET_assert, GNUNET_OK, and GNUNET_SYSERR.

Referenced by GNUNET_SQ_query_param_uint64().

467 {
468  const uint64_t *u = data;
469 
470  GNUNET_assert (sizeof (uint64_t) == data_len);
471  if (SQLITE_OK !=
472  sqlite3_bind_int64 (stmt,
473  (int) off,
474  (sqlite3_int64) *u))
475  return GNUNET_SYSERR;
476  return GNUNET_OK;
477 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
uint32_t data
The data value.
Here is the caller graph for this function:

◆ GNUNET_SQ_query_param_uint64()

struct GNUNET_SQ_QueryParam GNUNET_SQ_query_param_uint64 ( const uint64_t *  x)

Generate query parameter for an uint16_t in host byte order.

Parameters
xpointer to the query parameter to pass

Definition at line 486 of file sq_query_helper.c.

References bind_u64(), GNUNET_SQ_QueryParam::conv, and GNUNET_SQ_QueryParam::num_params.

Referenced by delete_by_rowid(), namestore_sqlite_iterate_records(), namestore_sqlite_store_records(), sqlite_plugin_del(), sqlite_plugin_get_key(), sqlite_plugin_get_replication(), sqlite_plugin_get_zero_anonymity(), and sqlite_plugin_put().

487 {
488  struct GNUNET_SQ_QueryParam qp = {
489  .conv = &bind_u64,
490  .data = x,
491  .size = sizeof (uint64_t),
492  .num_params = 1
493  };
494  return qp;
495 }
unsigned int num_params
Number of parameters eaten by this operation.
Definition: gnunet_sq_lib.h:80
static int bind_u64(void *cls, const void *data, size_t data_len, sqlite3_stmt *stmt, unsigned int off)
Function called to convert input argument into SQL parameters.
Description of a DB query parameter.
Definition: gnunet_sq_lib.h:54
GNUNET_SQ_QueryConverter conv
Function for how to handle this type of entry.
Definition: gnunet_sq_lib.h:60
Here is the call graph for this function:
Here is the caller graph for this function: