GNUnet  0.11.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:75
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
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 
76  return qp;
77 }
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:59
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 92 of file sq_query_helper.c.

References GNUNET_OK, and GNUNET_SYSERR.

Referenced by GNUNET_SQ_query_param_string().

97 {
98  if (NULL == data)
99  {
100  if (SQLITE_OK !=
101  sqlite3_bind_null (stmt,
102  (int) off))
103  return GNUNET_SYSERR;
104  return GNUNET_OK;
105  }
106  if (SQLITE_OK !=
107  sqlite3_bind_text (stmt,
108  (int) off,
109  (const char *) data,
110  -1,
111  SQLITE_TRANSIENT))
112  return GNUNET_SYSERR;
113  return GNUNET_OK;
114 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
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 123 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().

124 {
125  struct GNUNET_SQ_QueryParam qp = {
126  .conv = &bind_string,
127  .data = ptr,
128  .num_params = 1
129  };
130 
131  return qp;
132 }
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:59
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 147 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().

152 {
153  const struct GNUNET_CRYPTO_RsaPublicKey *rsa = data;
154  char *buf;
155  size_t buf_size;
156 
157  GNUNET_break (NULL == cls);
158  buf_size = GNUNET_CRYPTO_rsa_public_key_encode (rsa,
159  &buf);
160  if (SQLITE_OK !=
161  sqlite3_bind_blob64 (stmt,
162  (int) off,
163  buf,
164  (sqlite3_uint64) buf_size,
165  SQLITE_TRANSIENT))
166  {
167  GNUNET_free (buf);
168  return GNUNET_SYSERR;
169  }
170  GNUNET_free (buf);
171  return GNUNET_OK;
172 }
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:348
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
The public information of an RSA key pair.
Definition: crypto_rsa.c:53
#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:76
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 182 of file sq_query_helper.c.

References bind_rsa_pub(), and GNUNET_SQ_QueryParam::conv.

184 {
185  struct GNUNET_SQ_QueryParam qp = {
186  .conv = &bind_rsa_pub,
187  .data = x,
188  .num_params = 1
189  };
190 
191  return qp;
192 }
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:59
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 207 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().

212 {
213  const struct GNUNET_CRYPTO_RsaSignature *sig = data;
214  char *buf;
215  size_t buf_size;
216 
217  GNUNET_break (NULL == cls);
218  buf_size = GNUNET_CRYPTO_rsa_signature_encode (sig,
219  &buf);
220  if (SQLITE_OK !=
221  sqlite3_bind_blob64 (stmt,
222  (int) off,
223  buf,
224  (sqlite3_uint64) buf_size,
225  SQLITE_TRANSIENT))
226  {
227  GNUNET_free (buf);
228  return GNUNET_SYSERR;
229  }
230  GNUNET_free (buf);
231  return GNUNET_OK;
232 }
an RSA signature
Definition: crypto_rsa.c:65
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:1127
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#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:76
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 242 of file sq_query_helper.c.

References bind_rsa_sig(), and GNUNET_SQ_QueryParam::conv.

243 {
244  struct GNUNET_SQ_QueryParam qp = {
245  .conv = &bind_rsa_sig,
246  .data = x,
247  .num_params = 1
248  };
249 
250  return qp;
251 }
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:59
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 266 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().

271 {
272  const struct GNUNET_TIME_Absolute *u = data;
273  struct GNUNET_TIME_Absolute abs;
274 
275  abs = *u;
276  if (abs.abs_value_us > INT64_MAX)
277  abs.abs_value_us = INT64_MAX;
278  GNUNET_assert (sizeof(uint64_t) == data_len);
279  if (SQLITE_OK !=
280  sqlite3_bind_int64 (stmt,
281  (int) off,
282  (sqlite3_int64) abs.abs_value_us))
283  return GNUNET_SYSERR;
284  return GNUNET_OK;
285 }
#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:75
uint64_t abs_value_us
The actual value.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
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 295 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().

296 {
297  struct GNUNET_SQ_QueryParam qp = {
298  .conv = &bind_abstime,
299  .data = x,
300  .size = sizeof(struct GNUNET_TIME_Absolute),
301  .num_params = 1
302  };
303 
304  return qp;
305 }
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:59
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 320 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().

325 {
326  const struct GNUNET_TIME_AbsoluteNBO *u = data;
327  struct GNUNET_TIME_Absolute abs;
328 
329  abs = GNUNET_TIME_absolute_ntoh (*u);
330  if (abs.abs_value_us > INT64_MAX)
331  abs.abs_value_us = INT64_MAX;
332  GNUNET_assert (sizeof(uint64_t) == data_len);
333  if (SQLITE_OK !=
334  sqlite3_bind_int64 (stmt,
335  (int) off,
336  (sqlite3_int64) abs.abs_value_us))
337  return GNUNET_SYSERR;
338  return GNUNET_OK;
339 }
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
Definition: time.c:673
#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:75
Time for absolute time used by GNUnet, in microseconds and in network byte order. ...
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
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 349 of file sq_query_helper.c.

References bind_nbotime(), and GNUNET_SQ_QueryParam::conv.

351 {
352  struct GNUNET_SQ_QueryParam qp = {
353  .conv = &bind_nbotime,
354  .data = x,
355  .size = sizeof(struct GNUNET_TIME_AbsoluteNBO),
356  .num_params = 1
357  };
358 
359  return qp;
360 }
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:59
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 375 of file sq_query_helper.c.

References data, GNUNET_assert, GNUNET_OK, and GNUNET_SYSERR.

Referenced by GNUNET_SQ_query_param_uint16().

380 {
381  const uint16_t *u = data;
382 
383  GNUNET_assert (sizeof(uint16_t) == data_len);
384  if (SQLITE_OK !=
385  sqlite3_bind_int (stmt,
386  (int) off,
387  (int) *u))
388  return GNUNET_SYSERR;
389  return GNUNET_OK;
390 }
#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:75
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
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 399 of file sq_query_helper.c.

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

400 {
401  struct GNUNET_SQ_QueryParam qp = {
402  .conv = &bind_u16,
403  .data = x,
404  .size = sizeof(uint16_t),
405  .num_params = 1
406  };
407 
408  return qp;
409 }
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:79
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:59
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 424 of file sq_query_helper.c.

References data, GNUNET_assert, GNUNET_OK, and GNUNET_SYSERR.

Referenced by GNUNET_SQ_query_param_uint32().

429 {
430  const uint32_t *u = data;
431 
432  GNUNET_assert (sizeof(uint32_t) == data_len);
433  if (SQLITE_OK !=
434  sqlite3_bind_int64 (stmt,
435  (int) off,
436  (sqlite3_int64) * u))
437  return GNUNET_SYSERR;
438  return GNUNET_OK;
439 }
#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:75
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
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 448 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().

449 {
450  struct GNUNET_SQ_QueryParam qp = {
451  .conv = &bind_u32,
452  .data = x,
453  .size = sizeof(uint32_t),
454  .num_params = 1
455  };
456 
457  return qp;
458 }
unsigned int num_params
Number of parameters eaten by this operation.
Definition: gnunet_sq_lib.h:79
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:59
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 473 of file sq_query_helper.c.

References data, GNUNET_assert, GNUNET_OK, and GNUNET_SYSERR.

Referenced by GNUNET_SQ_query_param_uint64().

478 {
479  const uint64_t *u = data;
480 
481  GNUNET_assert (sizeof(uint64_t) == data_len);
482  if (SQLITE_OK !=
483  sqlite3_bind_int64 (stmt,
484  (int) off,
485  (sqlite3_int64) * u))
486  return GNUNET_SYSERR;
487  return GNUNET_OK;
488 }
#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:75
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
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 497 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().

498 {
499  struct GNUNET_SQ_QueryParam qp = {
500  .conv = &bind_u64,
501  .data = x,
502  .size = sizeof(uint64_t),
503  .num_params = 1
504  };
505 
506  return qp;
507 }
unsigned int num_params
Number of parameters eaten by this operation.
Definition: gnunet_sq_lib.h:79
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:59
Here is the call graph for this function:
Here is the caller graph for this function: