diff options
Diffstat (limited to 'src/namestore/plugin_namestore_postgres.c')
-rw-r--r-- | src/namestore/plugin_namestore_postgres.c | 64 |
1 files changed, 17 insertions, 47 deletions
diff --git a/src/namestore/plugin_namestore_postgres.c b/src/namestore/plugin_namestore_postgres.c index 5148ca0f5..23893538b 100644 --- a/src/namestore/plugin_namestore_postgres.c +++ b/src/namestore/plugin_namestore_postgres.c | |||
@@ -45,9 +45,9 @@ struct Plugin | |||
45 | const struct GNUNET_CONFIGURATION_Handle *cfg; | 45 | const struct GNUNET_CONFIGURATION_Handle *cfg; |
46 | 46 | ||
47 | /** | 47 | /** |
48 | * Native Postgres database handle. | 48 | * Postgres database handle. |
49 | */ | 49 | */ |
50 | PGconn *dbh; | 50 | struct GNUNET_PQ_Context *dbh; |
51 | }; | 51 | }; |
52 | 52 | ||
53 | 53 | ||
@@ -88,30 +88,8 @@ database_setup (struct Plugin *plugin) | |||
88 | ")" | 88 | ")" |
89 | "WITH OIDS"); | 89 | "WITH OIDS"); |
90 | const struct GNUNET_PQ_ExecuteStatement *cr; | 90 | const struct GNUNET_PQ_ExecuteStatement *cr; |
91 | struct GNUNET_PQ_ExecuteStatement sc = GNUNET_PQ_EXECUTE_STATEMENT_END; | ||
91 | 92 | ||
92 | plugin->dbh = GNUNET_PQ_connect_with_cfg (plugin->cfg, | ||
93 | "namestore-postgres"); | ||
94 | if (NULL == plugin->dbh) | ||
95 | return GNUNET_SYSERR; | ||
96 | if (GNUNET_YES == | ||
97 | GNUNET_CONFIGURATION_get_value_yesno (plugin->cfg, | ||
98 | "namestore-postgres", | ||
99 | "ASYNC_COMMIT")) | ||
100 | { | ||
101 | struct GNUNET_PQ_ExecuteStatement es[] = { | ||
102 | GNUNET_PQ_make_try_execute ("SET synchronous_commit TO off"), | ||
103 | GNUNET_PQ_EXECUTE_STATEMENT_END | ||
104 | }; | ||
105 | |||
106 | if (GNUNET_OK != | ||
107 | GNUNET_PQ_exec_statements (plugin->dbh, | ||
108 | es)) | ||
109 | { | ||
110 | PQfinish (plugin->dbh); | ||
111 | plugin->dbh = NULL; | ||
112 | return GNUNET_SYSERR; | ||
113 | } | ||
114 | } | ||
115 | if (GNUNET_YES == | 93 | if (GNUNET_YES == |
116 | GNUNET_CONFIGURATION_get_value_yesno (plugin->cfg, | 94 | GNUNET_CONFIGURATION_get_value_yesno (plugin->cfg, |
117 | "namestore-postgres", | 95 | "namestore-postgres", |
@@ -124,6 +102,12 @@ database_setup (struct Plugin *plugin) | |||
124 | cr = &es_default; | 102 | cr = &es_default; |
125 | } | 103 | } |
126 | 104 | ||
105 | if (GNUNET_YES == | ||
106 | GNUNET_CONFIGURATION_get_value_yesno (plugin->cfg, | ||
107 | "namestore-postgres", | ||
108 | "ASYNC_COMMIT")) | ||
109 | sc = GNUNET_PQ_make_try_execute ("SET synchronous_commit TO off"); | ||
110 | |||
127 | { | 111 | { |
128 | struct GNUNET_PQ_ExecuteStatement es[] = { | 112 | struct GNUNET_PQ_ExecuteStatement es[] = { |
129 | *cr, | 113 | *cr, |
@@ -135,20 +119,9 @@ database_setup (struct Plugin *plugin) | |||
135 | "ON ns098records (label)"), | 119 | "ON ns098records (label)"), |
136 | GNUNET_PQ_make_try_execute ("CREATE INDEX IF NOT EXISTS zone_label " | 120 | GNUNET_PQ_make_try_execute ("CREATE INDEX IF NOT EXISTS zone_label " |
137 | "ON ns098records (zone_private_key,label)"), | 121 | "ON ns098records (zone_private_key,label)"), |
122 | sc, | ||
138 | GNUNET_PQ_EXECUTE_STATEMENT_END | 123 | GNUNET_PQ_EXECUTE_STATEMENT_END |
139 | }; | 124 | }; |
140 | |||
141 | if (GNUNET_OK != | ||
142 | GNUNET_PQ_exec_statements (plugin->dbh, | ||
143 | es)) | ||
144 | { | ||
145 | PQfinish (plugin->dbh); | ||
146 | plugin->dbh = NULL; | ||
147 | return GNUNET_SYSERR; | ||
148 | } | ||
149 | } | ||
150 | |||
151 | { | ||
152 | struct GNUNET_PQ_PreparedStatement ps[] = { | 125 | struct GNUNET_PQ_PreparedStatement ps[] = { |
153 | GNUNET_PQ_make_prepare ("store_records", | 126 | GNUNET_PQ_make_prepare ("store_records", |
154 | "INSERT INTO ns098records" | 127 | "INSERT INTO ns098records" |
@@ -183,16 +156,13 @@ database_setup (struct Plugin *plugin) | |||
183 | GNUNET_PQ_PREPARED_STATEMENT_END | 156 | GNUNET_PQ_PREPARED_STATEMENT_END |
184 | }; | 157 | }; |
185 | 158 | ||
186 | if (GNUNET_OK != | 159 | plugin->dbh = GNUNET_PQ_connect_with_cfg (plugin->cfg, |
187 | GNUNET_PQ_prepare_statements (plugin->dbh, | 160 | "namestore-postgres", |
188 | ps)) | 161 | es, |
189 | { | 162 | ps); |
190 | PQfinish (plugin->dbh); | ||
191 | plugin->dbh = NULL; | ||
192 | return GNUNET_SYSERR; | ||
193 | } | ||
194 | } | 163 | } |
195 | 164 | if (NULL == plugin->dbh) | |
165 | return GNUNET_SYSERR; | ||
196 | return GNUNET_OK; | 166 | return GNUNET_OK; |
197 | } | 167 | } |
198 | 168 | ||
@@ -593,7 +563,7 @@ namestore_postgres_zone_to_name (void *cls, | |||
593 | static void | 563 | static void |
594 | database_shutdown (struct Plugin *plugin) | 564 | database_shutdown (struct Plugin *plugin) |
595 | { | 565 | { |
596 | PQfinish (plugin->dbh); | 566 | GNUNET_PQ_disconnect (plugin->dbh); |
597 | plugin->dbh = NULL; | 567 | plugin->dbh = NULL; |
598 | } | 568 | } |
599 | 569 | ||