aboutsummaryrefslogtreecommitdiff
path: root/src/namecache/plugin_namecache_postgres.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/namecache/plugin_namecache_postgres.c')
-rw-r--r--src/namecache/plugin_namecache_postgres.c38
1 files changed, 9 insertions, 29 deletions
diff --git a/src/namecache/plugin_namecache_postgres.c b/src/namecache/plugin_namecache_postgres.c
index e4b360ef2..35bf5c2ff 100644
--- a/src/namecache/plugin_namecache_postgres.c
+++ b/src/namecache/plugin_namecache_postgres.c
@@ -42,9 +42,9 @@ struct Plugin
42 const struct GNUNET_CONFIGURATION_Handle *cfg; 42 const struct GNUNET_CONFIGURATION_Handle *cfg;
43 43
44 /** 44 /**
45 * Native Postgres database handle. 45 * Postgres database handle.
46 */ 46 */
47 PGconn *dbh; 47 struct GNUNET_PQ_Context *dbh;
48}; 48};
49 49
50 50
@@ -75,10 +75,6 @@ database_setup (struct Plugin *plugin)
75 "WITH OIDS"); 75 "WITH OIDS");
76 const struct GNUNET_PQ_ExecuteStatement *cr; 76 const struct GNUNET_PQ_ExecuteStatement *cr;
77 77
78 plugin->dbh = GNUNET_PQ_connect_with_cfg (plugin->cfg,
79 "namecache-postgres");
80 if (NULL == plugin->dbh)
81 return GNUNET_SYSERR;
82 if (GNUNET_YES == 78 if (GNUNET_YES ==
83 GNUNET_CONFIGURATION_get_value_yesno (plugin->cfg, 79 GNUNET_CONFIGURATION_get_value_yesno (plugin->cfg,
84 "namecache-postgres", 80 "namecache-postgres",
@@ -90,7 +86,6 @@ database_setup (struct Plugin *plugin)
90 { 86 {
91 cr = &es_default; 87 cr = &es_default;
92 } 88 }
93
94 { 89 {
95 struct GNUNET_PQ_ExecuteStatement es[] = { 90 struct GNUNET_PQ_ExecuteStatement es[] = {
96 *cr, 91 *cr,
@@ -100,18 +95,6 @@ database_setup (struct Plugin *plugin)
100 "CREATE INDEX ir_block_expiration ON ns096blocks (expiration_time)"), 95 "CREATE INDEX ir_block_expiration ON ns096blocks (expiration_time)"),
101 GNUNET_PQ_EXECUTE_STATEMENT_END 96 GNUNET_PQ_EXECUTE_STATEMENT_END
102 }; 97 };
103
104 if (GNUNET_OK !=
105 GNUNET_PQ_exec_statements (plugin->dbh,
106 es))
107 {
108 PQfinish (plugin->dbh);
109 plugin->dbh = NULL;
110 return GNUNET_SYSERR;
111 }
112 }
113
114 {
115 struct GNUNET_PQ_PreparedStatement ps[] = { 98 struct GNUNET_PQ_PreparedStatement ps[] = {
116 GNUNET_PQ_make_prepare ("cache_block", 99 GNUNET_PQ_make_prepare ("cache_block",
117 "INSERT INTO ns096blocks (query, block, expiration_time) VALUES " 100 "INSERT INTO ns096blocks (query, block, expiration_time) VALUES "
@@ -128,16 +111,13 @@ database_setup (struct Plugin *plugin)
128 GNUNET_PQ_PREPARED_STATEMENT_END 111 GNUNET_PQ_PREPARED_STATEMENT_END
129 }; 112 };
130 113
131 if (GNUNET_OK != 114 plugin->dbh = GNUNET_PQ_connect_with_cfg (plugin->cfg,
132 GNUNET_PQ_prepare_statements (plugin->dbh, 115 "namecache-postgres",
133 ps)) 116 es,
134 { 117 ps);
135 PQfinish (plugin->dbh);
136 plugin->dbh = NULL;
137 return GNUNET_SYSERR;
138 }
139 } 118 }
140 119 if (NULL == plugin->dbh)
120 return GNUNET_SYSERR;
141 return GNUNET_OK; 121 return GNUNET_OK;
142} 122}
143 123
@@ -311,7 +291,7 @@ namecache_postgres_lookup_block (void *cls,
311static void 291static void
312database_shutdown (struct Plugin *plugin) 292database_shutdown (struct Plugin *plugin)
313{ 293{
314 PQfinish (plugin->dbh); 294 GNUNET_PQ_disconnect (plugin->dbh);
315 plugin->dbh = NULL; 295 plugin->dbh = NULL;
316} 296}
317 297