aboutsummaryrefslogtreecommitdiff
path: root/src/peerstore/plugin_peerstore_sqlite.c
diff options
context:
space:
mode:
authorOmar Tarabai <tarabai@devegypt.com>2014-05-13 22:08:22 +0000
committerOmar Tarabai <tarabai@devegypt.com>2014-05-13 22:08:22 +0000
commitdb2ee15ca4302b0e7fa78e318833cd136265b746 (patch)
tree118bf881b689d5f2f42353611e9e132ea128eadb /src/peerstore/plugin_peerstore_sqlite.c
parent748449cc89a8ef631b8c3c5c3b9168634fc355a5 (diff)
downloadgnunet-db2ee15ca4302b0e7fa78e318833cd136265b746.tar.gz
gnunet-db2ee15ca4302b0e7fa78e318833cd136265b746.zip
PEERSTORE api overhaul
Diffstat (limited to 'src/peerstore/plugin_peerstore_sqlite.c')
-rw-r--r--src/peerstore/plugin_peerstore_sqlite.c25
1 files changed, 14 insertions, 11 deletions
diff --git a/src/peerstore/plugin_peerstore_sqlite.c b/src/peerstore/plugin_peerstore_sqlite.c
index 6aa6edf3b..ac6d30931 100644
--- a/src/peerstore/plugin_peerstore_sqlite.c
+++ b/src/peerstore/plugin_peerstore_sqlite.c
@@ -213,9 +213,10 @@ peerstore_sqlite_iterate_records (void *cls,
213 * @return #GNUNET_OK on success, else #GNUNET_SYSERR 213 * @return #GNUNET_OK on success, else #GNUNET_SYSERR
214 */ 214 */
215static int 215static int
216peerstore_sqlite_store_record (void *cls, 216peerstore_sqlite_store_record(void *cls,
217 const struct GNUNET_PeerIdentity *peer,
218 const char *sub_system, 217 const char *sub_system,
218 const struct GNUNET_PeerIdentity *peer,
219 const char *key,
219 const void *value, 220 const void *value,
220 size_t size) 221 size_t size)
221{ 222{
@@ -224,9 +225,10 @@ peerstore_sqlite_store_record (void *cls,
224 225
225 //FIXME: check if value exists with the same key first 226 //FIXME: check if value exists with the same key first
226 227
227 if(SQLITE_OK != sqlite3_bind_blob(stmt, 1, peer, sizeof(struct GNUNET_PeerIdentity), SQLITE_STATIC) 228 if(SQLITE_OK != sqlite3_bind_text(stmt, 1, sub_system, strlen(sub_system) + 1, SQLITE_STATIC)
228 || SQLITE_OK != sqlite3_bind_text(stmt, 2, sub_system, strlen(sub_system) + 1, SQLITE_STATIC) 229 || SQLITE_OK != sqlite3_bind_blob(stmt, 2, peer, sizeof(struct GNUNET_PeerIdentity), SQLITE_STATIC)
229 || SQLITE_OK != sqlite3_bind_blob(stmt, 3, value, size, SQLITE_STATIC)) 230 || SQLITE_OK != sqlite3_bind_text(stmt, 3, key, strlen(key) + 1, SQLITE_STATIC)
231 || SQLITE_OK != sqlite3_bind_blob(stmt, 4, value, size, SQLITE_STATIC))
230 LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 232 LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
231 "sqlite3_bind"); 233 "sqlite3_bind");
232 else if (SQLITE_DONE != sqlite3_step (stmt)) 234 else if (SQLITE_DONE != sqlite3_step (stmt))
@@ -347,16 +349,17 @@ database_setup (struct Plugin *plugin)
347 /* Create tables */ 349 /* Create tables */
348 350
349 sql_exec (plugin->dbh, 351 sql_exec (plugin->dbh,
350 "CREATE TABLE IF NOT EXISTS peerstoredata (\n" 352 "CREATE TABLE IF NOT EXISTS peerstoredata (\n"
351 " peer_id BLOB NOT NULL,\n" 353 " sub_system TEXT NOT NULL,\n"
352 " sub_system TEXT NOT NULL,\n" 354 " peer_id BLOB NOT NULL,\n"
353 " value BLOB NULL" 355 " key TEXT NOT NULL,\n"
354 ");"); 356 " value BLOB NULL"
357 ");");
355 358
356 /* Prepare statements */ 359 /* Prepare statements */
357 360
358 sql_prepare (plugin->dbh, 361 sql_prepare (plugin->dbh,
359 "INSERT INTO peerstoredata (peer_id, sub_system, value) VALUES (?,?,?);", 362 "INSERT INTO peerstoredata (sub_system, peer_id, key, value) VALUES (?,?,?,?);",
360 &plugin->insert_peerstoredata); 363 &plugin->insert_peerstoredata);
361 sql_prepare(plugin->dbh, 364 sql_prepare(plugin->dbh,
362 "SELECT peer_id, sub_system, value FROM peerstoredata", 365 "SELECT peer_id, sub_system, value FROM peerstoredata",