GNUnet 0.22.2
sq.c File Reference

helper functions for Sqlite3 DB interactions More...

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

Go to the source code of this file.

Functions

enum GNUNET_GenericReturnValue GNUNET_SQ_bind (sqlite3_stmt *stmt, const struct GNUNET_SQ_QueryParam *params)
 Execute binding operations for a prepared statement. More...
 
enum GNUNET_GenericReturnValue GNUNET_SQ_extract_result (sqlite3_stmt *result, struct GNUNET_SQ_ResultSpec *rs)
 Extract results from a query result according to the given specification. More...
 
void GNUNET_SQ_cleanup_result (struct GNUNET_SQ_ResultSpec *rs)
 Free all memory that was allocated in rs during GNUNET_SQ_extract_result(). More...
 
void GNUNET_SQ_reset (sqlite3 *dbh, sqlite3_stmt *stmt)
 Reset stmt and log error. More...
 

Detailed Description

helper functions for Sqlite3 DB interactions

Author
Christian Grothoff

Definition in file sq.c.

Function Documentation

◆ GNUNET_SQ_bind()

enum GNUNET_GenericReturnValue GNUNET_SQ_bind ( sqlite3_stmt *  stmt,
const struct GNUNET_SQ_QueryParam params 
)

Execute binding operations for a prepared statement.

Parameters
db_conndatabase connection
paramsparameters to the statement
Returns
GNUNET_OK on success, GNUNET_SYSERR on error

Definition at line 30 of file sq.c.

32{
33 unsigned int j;
34
35 j = 1;
36 for (unsigned int i = 0; NULL != params[i].conv; i++)
37 {
38 if (GNUNET_OK !=
39 params[i].conv (params[i].conv_cls,
40 params[i].data,
41 params[i].size,
42 stmt,
43 j))
44 {
46 "sq",
47 _ ("Failure to bind %u-th SQL parameter\n"),
48 i);
49 if (SQLITE_OK !=
50 sqlite3_reset (stmt))
51 {
53 "sq",
54 _ ("Failure in sqlite3_reset (!)\n"));
55 return GNUNET_SYSERR;
56 }
57 }
58 GNUNET_assert (0 != params[i].num_params);
59 j += params[i].num_params;
60 }
61 return GNUNET_OK;
62}
static char * data
The data to insert into the dht.
static GstElement * conv
#define GNUNET_log_from(kind, comp,...)
@ GNUNET_OK
@ GNUNET_SYSERR
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
@ GNUNET_ERROR_TYPE_WARNING
static unsigned int size
Size of the "table".
Definition: peer.c:68
#define _(String)
GNU gettext support macro.
Definition: platform.h:179
GNUNET_SQ_QueryConverter conv
Function for how to handle this type of entry.
Definition: gnunet_sq_lib.h:60
unsigned int num_params
Number of parameters eaten by this operation.
Definition: gnunet_sq_lib.h:80

References _, conv, GNUNET_SQ_QueryParam::conv, data, GNUNET_assert, GNUNET_ERROR_TYPE_WARNING, GNUNET_log_from, GNUNET_OK, GNUNET_SYSERR, GNUNET_SQ_QueryParam::num_params, and size.

Referenced by delete_by_rowid(), get_any(), get_typed(), lookup_records(), namecache_sqlite_cache_block(), namecache_sqlite_expire_blocks(), namecache_sqlite_lookup_block(), namestore_sqlite_editor_hint_clear(), namestore_sqlite_iterate_records(), namestore_sqlite_store_records(), namestore_sqlite_zone_to_name(), peerstore_sqlite_delete_records(), peerstore_sqlite_expire_records(), peerstore_sqlite_iterate_records(), peerstore_sqlite_store_record(), sqlite_plugin_del(), sqlite_plugin_get_closest(), sqlite_plugin_get_expiration(), sqlite_plugin_get_key(), sqlite_plugin_get_replication(), sqlite_plugin_get_zero_anonymity(), sqlite_plugin_put(), and sqlite_plugin_remove_key().

Here is the caller graph for this function:

◆ GNUNET_SQ_extract_result()

enum GNUNET_GenericReturnValue GNUNET_SQ_extract_result ( sqlite3_stmt *  result,
struct GNUNET_SQ_ResultSpec rs 
)

Extract results from a query result according to the given specification.

Parameters
resultresult to process
[in,out]rsresult specification to extract for
Returns
GNUNET_OK if all results could be extracted GNUNET_SYSERR if a result was invalid (non-existing field)

Definition at line 75 of file sq.c.

77{
78 unsigned int j = 0;
79
80 for (unsigned int i = 0; NULL != rs[i].conv; i++)
81 {
82 if (NULL == rs[i].result_size)
83 rs[i].result_size = &rs[i].dst_size;
84 if (GNUNET_OK !=
85 rs[i].conv (rs[i].cls,
86 result,
87 j,
88 rs[i].result_size,
89 rs[i].dst))
90 {
91 for (unsigned int k = 0; k < i; k++)
92 if (NULL != rs[k].cleaner)
93 rs[k].cleaner (rs[k].cls);
94 return GNUNET_SYSERR;
95 }
96 GNUNET_assert (0 != rs[i].num_params);
97 j += rs[i].num_params;
98 }
99 return GNUNET_OK;
100}
static int result
Global testing status.
size_t * result_size
Where to store actual size of the result.
GNUNET_SQ_ResultConverter conv
What is the format of the result?
GNUNET_SQ_ResultCleanup cleaner
Function to clean up result data, NULL if cleanup is not necessary.
unsigned int num_params
Number of parameters (columns) eaten by this operation.
size_t dst_size
Allowed size for the data, 0 for variable-size (in this case, the type of dst is a void ** and we nee...

References GNUNET_SQ_ResultSpec::cleaner, conv, GNUNET_SQ_ResultSpec::conv, GNUNET_SQ_ResultSpec::dst_size, GNUNET_assert, GNUNET_OK, GNUNET_SYSERR, GNUNET_SQ_ResultSpec::num_params, result, and GNUNET_SQ_ResultSpec::result_size.

Referenced by execute_get(), get_any(), get_records_and_call_iterator(), get_typed(), namecache_sqlite_lookup_block(), peerstore_sqlite_iterate_records(), sqlite_plugin_del(), sqlite_plugin_get_closest(), and sqlite_plugin_get_keys().

Here is the caller graph for this function:

◆ GNUNET_SQ_cleanup_result()

void GNUNET_SQ_cleanup_result ( struct GNUNET_SQ_ResultSpec rs)

Free all memory that was allocated in rs during GNUNET_SQ_extract_result().

Parameters
rsreult specification to clean up

Definition at line 104 of file sq.c.

105{
106 for (unsigned int i = 0; NULL != rs[i].conv; i++)
107 if (NULL != rs[i].cleaner)
108 rs[i].cleaner (rs[i].cls);
109}

References GNUNET_SQ_ResultSpec::cleaner, and GNUNET_SQ_ResultSpec::conv.

Referenced by execute_get(), get_any(), get_records_and_call_iterator(), get_typed(), namecache_sqlite_lookup_block(), peerstore_sqlite_iterate_records(), sqlite_plugin_del(), and sqlite_plugin_get_closest().

Here is the caller graph for this function:

◆ GNUNET_SQ_reset()

void GNUNET_SQ_reset ( sqlite3 *  dbh,
sqlite3_stmt *  stmt 
)

Reset stmt and log error.

Parameters
dbhdatabase handle
stmtstatement to reset

Definition at line 119 of file sq.c.

121{
122 if (SQLITE_OK !=
123 sqlite3_reset (stmt))
125 "sqlite",
126 _ ("Failed to reset sqlite statement with error: %s\n"),
127 sqlite3_errmsg (dbh));
128}
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_BULK

References _, GNUNET_ERROR_TYPE_BULK, GNUNET_ERROR_TYPE_ERROR, and GNUNET_log_from.

Referenced by delete_by_rowid(), execute_get(), get_any(), get_records_and_call_iterator(), get_typed(), lookup_records(), namecache_sqlite_cache_block(), namecache_sqlite_expire_blocks(), namecache_sqlite_lookup_block(), namestore_sqlite_editor_hint_clear(), namestore_sqlite_iterate_records(), namestore_sqlite_store_records(), namestore_sqlite_zone_to_name(), peerstore_sqlite_delete_records(), peerstore_sqlite_expire_records(), peerstore_sqlite_iterate_records(), peerstore_sqlite_store_record(), sqlite_plugin_del(), sqlite_plugin_get_closest(), sqlite_plugin_get_replication(), sqlite_plugin_put(), and sqlite_plugin_remove_key().

Here is the caller graph for this function: