aboutsummaryrefslogtreecommitdiff
path: root/src/datastore/plugin_datastore_sqlite.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/datastore/plugin_datastore_sqlite.c')
-rw-r--r--src/datastore/plugin_datastore_sqlite.c136
1 files changed, 0 insertions, 136 deletions
diff --git a/src/datastore/plugin_datastore_sqlite.c b/src/datastore/plugin_datastore_sqlite.c
index f14855219..501c9f292 100644
--- a/src/datastore/plugin_datastore_sqlite.c
+++ b/src/datastore/plugin_datastore_sqlite.c
@@ -1079,141 +1079,6 @@ sqlite_plugin_iter_zero_anonymity (void *cls,
1079 1079
1080 1080
1081/** 1081/**
1082 * Closure for 'all_next_prepare'.
1083 */
1084struct IterateAllContext
1085{
1086
1087 /**
1088 * Offset for the current result.
1089 */
1090 unsigned int off;
1091
1092 /**
1093 * Requested block type.
1094 */
1095 enum GNUNET_BLOCK_Type type;
1096
1097 /**
1098 * Our prepared statement.
1099 */
1100 sqlite3_stmt *stmt;
1101};
1102
1103
1104/**
1105 * Call sqlite using the already prepared query to get
1106 * the next result.
1107 *
1108 * @param cls context with the prepared query (of type 'struct IterateAllContext')
1109 * @param nc generic context with the prepared query
1110 * @return GNUNET_OK on success, GNUNET_SYSERR on error, GNUNET_NO if
1111 * there are no more results
1112 */
1113static int
1114all_next_prepare (void *cls,
1115 struct NextContext *nc)
1116{
1117 struct IterateAllContext *iac = cls;
1118 struct Plugin *plugin;
1119 int ret;
1120 unsigned int sqoff;
1121
1122 if (nc == NULL)
1123 {
1124#if DEBUG_SQLITE
1125 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1126 "Asked to clean up iterator state.\n");
1127#endif
1128 if (NULL != iac->stmt)
1129 {
1130 sqlite3_finalize (iac->stmt);
1131 iac->stmt = NULL;
1132 }
1133 return GNUNET_SYSERR;
1134 }
1135 plugin = nc->plugin;
1136 sqoff = 1;
1137 ret = SQLITE_OK;
1138 if (iac->type != 0)
1139 ret = sqlite3_bind_int (nc->stmt, sqoff++, iac->type);
1140 if (SQLITE_OK == ret)
1141 ret = sqlite3_bind_int64 (nc->stmt, sqoff++, iac->off++);
1142 if (ret != SQLITE_OK)
1143 {
1144 LOG_SQLITE (plugin, NULL,
1145 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "sqlite3_bind_XXXX");
1146 return GNUNET_SYSERR;
1147 }
1148 ret = sqlite3_step (nc->stmt);
1149 switch (ret)
1150 {
1151 case SQLITE_ROW:
1152 return GNUNET_OK;
1153 case SQLITE_DONE:
1154 return GNUNET_NO;
1155 default:
1156 LOG_SQLITE (plugin, NULL,
1157 GNUNET_ERROR_TYPE_ERROR |
1158 GNUNET_ERROR_TYPE_BULK,
1159 "sqlite3_step");
1160 return GNUNET_SYSERR;
1161 }
1162}
1163
1164
1165/**
1166 * Select a subset of the items in the datastore and call
1167 * the given iterator for each of them.
1168 *
1169 * @param cls our plugin context
1170 * @param type entries of which type should be considered?
1171 * Use 0 for any type.
1172 * @param iter function to call on each matching value;
1173 * will be called once with a NULL value at the end
1174 * @param iter_cls closure for iter
1175 */
1176static void
1177sqlite_plugin_iter_all_now (void *cls,
1178 enum GNUNET_BLOCK_Type type,
1179 PluginIterator iter,
1180 void *iter_cls)
1181{
1182 struct Plugin *plugin = cls;
1183 struct NextContext *nc;
1184 struct IterateAllContext *iac;
1185 sqlite3_stmt *stmt;
1186 const char *q;
1187
1188 if (type == 0)
1189 q = "SELECT type,prio,anonLevel,expire,hash,value,_ROWID_ FROM gn090 ORDER BY _ROWID_ ASC LIMIT 1 OFFSET ?";
1190 else
1191 q = "SELECT type,prio,anonLevel,expire,hash,value,_ROWID_ FROM gn090 WHERE type=? ORDER BY _ROWID_ ASC LIMIT 1 OFFSET ?";
1192 if (sq_prepare (plugin->dbh, q, &stmt) != SQLITE_OK)
1193 {
1194 LOG_SQLITE (plugin, NULL,
1195 GNUNET_ERROR_TYPE_ERROR |
1196 GNUNET_ERROR_TYPE_BULK, "sqlite3_prepare_v2");
1197 iter (iter_cls, NULL, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
1198 return;
1199 }
1200 nc = GNUNET_malloc (sizeof(struct NextContext) +
1201 sizeof(struct IterateAllContext));
1202 iac = (struct IterateAllContext*) &nc[1];
1203 nc->plugin = plugin;
1204 nc->iter = iter;
1205 nc->iter_cls = iter_cls;
1206 nc->stmt = stmt;
1207 nc->prep = &all_next_prepare;
1208 nc->prep_cls = iac;
1209 iac->off = 0;
1210 iac->type = type;
1211 iac->stmt = stmt; /* alias used for freeing at the end */
1212 sqlite_next_request (nc, GNUNET_NO);
1213}
1214
1215
1216/**
1217 * Context for get_next_prepare. 1082 * Context for get_next_prepare.
1218 */ 1083 */
1219struct GetNextContext 1084struct GetNextContext
@@ -1732,7 +1597,6 @@ libgnunet_plugin_datastore_sqlite_init (void *cls)
1732 api->expiration_get = &sqlite_plugin_expiration_get; 1597 api->expiration_get = &sqlite_plugin_expiration_get;
1733 api->update = &sqlite_plugin_update; 1598 api->update = &sqlite_plugin_update;
1734 api->iter_zero_anonymity = &sqlite_plugin_iter_zero_anonymity; 1599 api->iter_zero_anonymity = &sqlite_plugin_iter_zero_anonymity;
1735 api->iter_all_now = &sqlite_plugin_iter_all_now;
1736 api->drop = &sqlite_plugin_drop; 1600 api->drop = &sqlite_plugin_drop;
1737 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, 1601 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO,
1738 "sqlite", _("Sqlite database running\n")); 1602 "sqlite", _("Sqlite database running\n"));