diff options
Diffstat (limited to 'src/datacache/plugin_datacache_postgres.c')
-rw-r--r-- | src/datacache/plugin_datacache_postgres.c | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/src/datacache/plugin_datacache_postgres.c b/src/datacache/plugin_datacache_postgres.c index d9e25992b..b1f9a1b8e 100644 --- a/src/datacache/plugin_datacache_postgres.c +++ b/src/datacache/plugin_datacache_postgres.c | |||
@@ -71,11 +71,12 @@ init_connection (struct Plugin *plugin) | |||
71 | "CREATE TEMPORARY SEQUENCE IF NOT EXISTS gn180dc_oid_seq"), | 71 | "CREATE TEMPORARY SEQUENCE IF NOT EXISTS gn180dc_oid_seq"), |
72 | GNUNET_PQ_make_execute ("CREATE TEMPORARY TABLE IF NOT EXISTS gn180dc (" | 72 | GNUNET_PQ_make_execute ("CREATE TEMPORARY TABLE IF NOT EXISTS gn180dc (" |
73 | " oid OID NOT NULL DEFAULT nextval('gn180dc_oid_seq')," | 73 | " oid OID NOT NULL DEFAULT nextval('gn180dc_oid_seq')," |
74 | " type INTEGER NOT NULL," | 74 | " type INT4 NOT NULL," |
75 | " ro INTEGER NOT NULL," | 75 | " ro INT4 NOT NULL," |
76 | " prox INTEGER NOT NULL," | 76 | " prox INT4 NOT NULL," |
77 | " expiration_time BIGINT NOT NULL," | 77 | " expiration_time INT8 NOT NULL," |
78 | " key BYTEA NOT NULL," | 78 | " key BYTEA NOT NULL CHECK(LENGTH(key)=64)," |
79 | " trunc BYTEA NOT NULL CHECK(LENGTH(trunc)=32)," | ||
79 | " value BYTEA NOT NULL," | 80 | " value BYTEA NOT NULL," |
80 | " path BYTEA DEFAULT NULL)"), | 81 | " path BYTEA DEFAULT NULL)"), |
81 | GNUNET_PQ_make_try_execute ( | 82 | GNUNET_PQ_make_try_execute ( |
@@ -93,11 +94,11 @@ init_connection (struct Plugin *plugin) | |||
93 | }; | 94 | }; |
94 | struct GNUNET_PQ_PreparedStatement ps[] = { | 95 | struct GNUNET_PQ_PreparedStatement ps[] = { |
95 | GNUNET_PQ_make_prepare ("getkt", | 96 | GNUNET_PQ_make_prepare ("getkt", |
96 | "SELECT expiration_time,type,ro,value,path FROM gn180dc " | 97 | "SELECT expiration_time,type,ro,value,trunc,path FROM gn180dc " |
97 | "WHERE key=$1 AND type=$2 AND expiration_time >= $3", | 98 | "WHERE key=$1 AND type=$2 AND expiration_time >= $3", |
98 | 3), | 99 | 3), |
99 | GNUNET_PQ_make_prepare ("getk", | 100 | GNUNET_PQ_make_prepare ("getk", |
100 | "SELECT expiration_time,type,ro,value,path FROM gn180dc " | 101 | "SELECT expiration_time,type,ro,value,trunc,path FROM gn180dc " |
101 | "WHERE key=$1 AND expiration_time >= $2", | 102 | "WHERE key=$1 AND expiration_time >= $2", |
102 | 2), | 103 | 2), |
103 | GNUNET_PQ_make_prepare ("getex", | 104 | GNUNET_PQ_make_prepare ("getex", |
@@ -110,14 +111,14 @@ init_connection (struct Plugin *plugin) | |||
110 | " ORDER BY prox ASC, expiration_time ASC LIMIT 1", | 111 | " ORDER BY prox ASC, expiration_time ASC LIMIT 1", |
111 | 0), | 112 | 0), |
112 | GNUNET_PQ_make_prepare ("get_closest", | 113 | GNUNET_PQ_make_prepare ("get_closest", |
113 | "(SELECT expiration_time,type,ro,value,path,key FROM gn180dc" | 114 | "(SELECT expiration_time,type,ro,value,trunc,path,key FROM gn180dc" |
114 | " WHERE key >= $1" | 115 | " WHERE key >= $1" |
115 | " AND expiration_time >= $2" | 116 | " AND expiration_time >= $2" |
116 | " AND ( (type = $3) OR ( 0 = $3) )" | 117 | " AND ( (type = $3) OR ( 0 = $3) )" |
117 | " ORDER BY key ASC" | 118 | " ORDER BY key ASC" |
118 | " LIMIT $4)" | 119 | " LIMIT $4)" |
119 | " UNION " | 120 | " UNION " |
120 | "(SELECT expiration_time,type,ro,value,path,key FROM gn180dc" | 121 | "(SELECT expiration_time,type,ro,value,trunc,path,key FROM gn180dc" |
121 | " WHERE key <= $1" | 122 | " WHERE key <= $1" |
122 | " AND expiration_time >= $2" | 123 | " AND expiration_time >= $2" |
123 | " AND ( (type = $3) OR ( 0 = $3) )" | 124 | " AND ( (type = $3) OR ( 0 = $3) )" |
@@ -129,9 +130,9 @@ init_connection (struct Plugin *plugin) | |||
129 | 1), | 130 | 1), |
130 | GNUNET_PQ_make_prepare ("put", | 131 | GNUNET_PQ_make_prepare ("put", |
131 | "INSERT INTO gn180dc" | 132 | "INSERT INTO gn180dc" |
132 | " (type, ro, prox, expiration_time, key, value, path) " | 133 | " (type, ro, prox, expiration_time, key, value, trunc, path) " |
133 | "VALUES ($1, $2, $3, $4, $5, $6, $7)", | 134 | "VALUES ($1, $2, $3, $4, $5, $6, $7, $8)", |
134 | 7), | 135 | 8), |
135 | GNUNET_PQ_PREPARED_STATEMENT_END | 136 | GNUNET_PQ_PREPARED_STATEMENT_END |
136 | }; | 137 | }; |
137 | 138 | ||
@@ -170,6 +171,7 @@ postgres_plugin_put (void *cls, | |||
170 | GNUNET_PQ_query_param_auto_from_type (&block->key), | 171 | GNUNET_PQ_query_param_auto_from_type (&block->key), |
171 | GNUNET_PQ_query_param_fixed_size (block->data, | 172 | GNUNET_PQ_query_param_fixed_size (block->data, |
172 | block->data_size), | 173 | block->data_size), |
174 | GNUNET_PQ_query_param_auto_from_type (&block->trunc_peer), | ||
173 | GNUNET_PQ_query_param_fixed_size (block->put_path, | 175 | GNUNET_PQ_query_param_fixed_size (block->put_path, |
174 | block->put_path_length | 176 | block->put_path_length |
175 | * sizeof(struct GNUNET_DHT_PathElement)), | 177 | * sizeof(struct GNUNET_DHT_PathElement)), |
@@ -243,6 +245,8 @@ handle_results (void *cls, | |||
243 | GNUNET_PQ_result_spec_variable_size ("value", | 245 | GNUNET_PQ_result_spec_variable_size ("value", |
244 | &data, | 246 | &data, |
245 | &block.data_size), | 247 | &block.data_size), |
248 | GNUNET_PQ_result_spec_auto_from_type ("trunc", | ||
249 | &block.trunc_peer), | ||
246 | GNUNET_PQ_result_spec_variable_size ("path", | 250 | GNUNET_PQ_result_spec_variable_size ("path", |
247 | &path, | 251 | &path, |
248 | &path_size), | 252 | &path_size), |
@@ -465,6 +469,8 @@ extract_result_cb (void *cls, | |||
465 | GNUNET_PQ_result_spec_variable_size ("value", | 469 | GNUNET_PQ_result_spec_variable_size ("value", |
466 | &data, | 470 | &data, |
467 | &block.data_size), | 471 | &block.data_size), |
472 | GNUNET_PQ_result_spec_auto_from_type ("trunc", | ||
473 | &block.trunc_peer), | ||
468 | GNUNET_PQ_result_spec_variable_size ("path", | 474 | GNUNET_PQ_result_spec_variable_size ("path", |
469 | &path, | 475 | &path, |
470 | &path_size), | 476 | &path_size), |