aboutsummaryrefslogtreecommitdiff
path: root/src/datacache
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2010-07-02 21:23:20 +0000
committerChristian Grothoff <christian@grothoff.org>2010-07-02 21:23:20 +0000
commit6db15a9b351f73ec2786a854e14d1d707b379f12 (patch)
tree86a32ea72c3239fb803788d6f0a162d9a29cb74a /src/datacache
parentcf04a3c0e93eba4001a47c7bb21d1de020fd7211 (diff)
downloadgnunet-6db15a9b351f73ec2786a854e14d1d707b379f12.tar.gz
gnunet-6db15a9b351f73ec2786a854e14d1d707b379f12.zip
fixing issue with sqlite not supporting unsigned 64-bit numbers
Diffstat (limited to 'src/datacache')
-rw-r--r--src/datacache/plugin_datacache_sqlite.c12
-rw-r--r--src/datacache/test_datacache.c2
2 files changed, 12 insertions, 2 deletions
diff --git a/src/datacache/plugin_datacache_sqlite.c b/src/datacache/plugin_datacache_sqlite.c
index 336f1c045..8c144baa2 100644
--- a/src/datacache/plugin_datacache_sqlite.c
+++ b/src/datacache/plugin_datacache_sqlite.c
@@ -104,6 +104,7 @@ sqlite_plugin_put (void *cls,
104{ 104{
105 struct Plugin *plugin = cls; 105 struct Plugin *plugin = cls;
106 sqlite3_stmt *stmt; 106 sqlite3_stmt *stmt;
107 int64_t dval;
107 108
108#if DEBUG_DATACACHE_SQLITE 109#if DEBUG_DATACACHE_SQLITE
109 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 110 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -113,6 +114,9 @@ sqlite_plugin_put (void *cls,
113 GNUNET_h2s (key), 114 GNUNET_h2s (key),
114 (unsigned long long) GNUNET_TIME_absolute_get_remaining (discard_time).value); 115 (unsigned long long) GNUNET_TIME_absolute_get_remaining (discard_time).value);
115#endif 116#endif
117 dval = (int64_t) discard_time.value;
118 if (dval < 0)
119 dval = INT64_MAX;
116 if (sq_prepare (plugin->dbh, 120 if (sq_prepare (plugin->dbh,
117 "INSERT INTO ds090 " 121 "INSERT INTO ds090 "
118 "(type, expire, key, value) " 122 "(type, expire, key, value) "
@@ -125,7 +129,7 @@ sqlite_plugin_put (void *cls,
125 return 0; 129 return 0;
126 } 130 }
127 if ( (SQLITE_OK != sqlite3_bind_int (stmt, 1, type)) || 131 if ( (SQLITE_OK != sqlite3_bind_int (stmt, 1, type)) ||
128 (SQLITE_OK != sqlite3_bind_int64 (stmt, 2, discard_time.value)) || 132 (SQLITE_OK != sqlite3_bind_int64 (stmt, 2, dval)) ||
129 (SQLITE_OK != sqlite3_bind_blob (stmt, 3, key, sizeof (GNUNET_HashCode), 133 (SQLITE_OK != sqlite3_bind_blob (stmt, 3, key, sizeof (GNUNET_HashCode),
130 SQLITE_TRANSIENT)) || 134 SQLITE_TRANSIENT)) ||
131 (SQLITE_OK != sqlite3_bind_blob (stmt, 4, data, size, SQLITE_TRANSIENT))) 135 (SQLITE_OK != sqlite3_bind_blob (stmt, 4, data, size, SQLITE_TRANSIENT)))
@@ -180,6 +184,7 @@ sqlite_plugin_get (void *cls,
180 unsigned int off; 184 unsigned int off;
181 unsigned int total; 185 unsigned int total;
182 char scratch[256]; 186 char scratch[256];
187 int64_t ntime;
183 188
184 now = GNUNET_TIME_absolute_get (); 189 now = GNUNET_TIME_absolute_get ();
185#if DEBUG_DATACACHE_SQLITE 190#if DEBUG_DATACACHE_SQLITE
@@ -201,6 +206,8 @@ sqlite_plugin_get (void *cls,
201 sqlite3_bind_blob (stmt, 1, key, sizeof (GNUNET_HashCode), 206 sqlite3_bind_blob (stmt, 1, key, sizeof (GNUNET_HashCode),
202 SQLITE_TRANSIENT); 207 SQLITE_TRANSIENT);
203 sqlite3_bind_int (stmt, 2, type); 208 sqlite3_bind_int (stmt, 2, type);
209 ntime = (int64_t) now.value;
210 GNUNET_assert (ntime >= 0);
204 sqlite3_bind_int64 (stmt, 3, now.value); 211 sqlite3_bind_int64 (stmt, 3, now.value);
205 if (SQLITE_ROW != sqlite3_step (stmt)) 212 if (SQLITE_ROW != sqlite3_step (stmt))
206 { 213 {
@@ -241,6 +248,9 @@ sqlite_plugin_get (void *cls,
241 size = sqlite3_column_bytes (stmt, 0); 248 size = sqlite3_column_bytes (stmt, 0);
242 dat = sqlite3_column_blob (stmt, 0); 249 dat = sqlite3_column_blob (stmt, 0);
243 exp.value = sqlite3_column_int64 (stmt, 1); 250 exp.value = sqlite3_column_int64 (stmt, 1);
251 ntime = (int64_t) exp.value;
252 if (ntime == INT64_MAX)
253 exp = GNUNET_TIME_UNIT_FOREVER_ABS;
244 cnt++; 254 cnt++;
245 if (GNUNET_OK != iter (iter_cls, 255 if (GNUNET_OK != iter (iter_cls,
246 exp, 256 exp,
diff --git a/src/datacache/test_datacache.c b/src/datacache/test_datacache.c
index 5d90bd497..8e09a7692 100644
--- a/src/datacache/test_datacache.c
+++ b/src/datacache/test_datacache.c
@@ -106,7 +106,7 @@ run (void *cls,
106 (const char *) &n, 106 (const char *) &n,
107 792, 107 792,
108 GNUNET_TIME_UNIT_FOREVER_ABS)); 108 GNUNET_TIME_UNIT_FOREVER_ABS));
109 ASSERT (1 == 109 ASSERT (0 !=
110 GNUNET_DATACACHE_get (h, &k, 792, 110 GNUNET_DATACACHE_get (h, &k, 792,
111 &checkIt, &n)); 111 &checkIt, &n));
112 112