diff options
Diffstat (limited to 'modules/postgres')
-rw-r--r-- | modules/postgres/postgres.c | 32 |
1 files changed, 6 insertions, 26 deletions
diff --git a/modules/postgres/postgres.c b/modules/postgres/postgres.c index 3e696ca..1218564 100644 --- a/modules/postgres/postgres.c +++ b/modules/postgres/postgres.c | |||
@@ -32,9 +32,8 @@ | |||
32 | #include <smap/stream.h> | 32 | #include <smap/stream.h> |
33 | #include <smap/wordsplit.h> | 33 | #include <smap/wordsplit.h> |
34 | 34 | ||
35 | #define MDB_INIT 0x01 | 35 | #define MDB_OPEN 0x01 |
36 | #define MDB_OPEN 0x02 | 36 | #define MDB_DEFDB 0x02 |
37 | #define MDB_DEFDB 0x04 | ||
38 | 37 | ||
39 | struct modpg_db { | 38 | struct modpg_db { |
40 | int flags; | 39 | int flags; |
@@ -83,12 +82,6 @@ opendb(struct modpg_db *db) | |||
83 | return 0; | 82 | return 0; |
84 | } | 83 | } |
85 | 84 | ||
86 | if (!(db->flags & MDB_INIT)) { | ||
87 | smap_error("%s: module settings do not include opendb flag", | ||
88 | db->name); | ||
89 | return 1; | ||
90 | } | ||
91 | |||
92 | db->pgconn = PQconnectdb(db->conninfo); | 85 | db->pgconn = PQconnectdb(db->conninfo); |
93 | if (!db->pgconn) { | 86 | if (!db->pgconn) { |
94 | smap_error("%s: out of memory", db->name); | 87 | smap_error("%s: out of memory", db->name); |
@@ -202,12 +195,9 @@ modpg_init(int argc, char **argv) | |||
202 | { | 195 | { |
203 | int i; | 196 | int i; |
204 | int rc; | 197 | int rc; |
205 | int opendb = 0; | ||
206 | 198 | ||
207 | dbgid = smap_debug_alloc("postgres"); | 199 | dbgid = smap_debug_alloc("postgres"); |
208 | struct smap_option init_option[] = { | 200 | struct smap_option init_option[] = { |
209 | { SMAP_OPTSTR(open), smap_opt_bool, | ||
210 | &opendb }, | ||
211 | { SMAP_OPTSTR(query), smap_opt_string, | 201 | { SMAP_OPTSTR(query), smap_opt_string, |
212 | &def_db.template }, | 202 | &def_db.template }, |
213 | { SMAP_OPTSTR(positive-reply), smap_opt_string, | 203 | { SMAP_OPTSTR(positive-reply), smap_opt_string, |
@@ -227,13 +217,7 @@ modpg_init(int argc, char **argv) | |||
227 | smap_error("out of memory"); | 217 | smap_error("out of memory"); |
228 | return 1; | 218 | return 1; |
229 | } | 219 | } |
230 | } | 220 | def_db.flags = 0; |
231 | if (opendb) { | ||
232 | if (!def_db.conninfo) { | ||
233 | smap_error("no connection info given"); | ||
234 | return 1; | ||
235 | } | ||
236 | def_db.flags = MDB_INIT; | ||
237 | def_db.name = "postgres"; | 221 | def_db.name = "postgres"; |
238 | } | 222 | } |
239 | return 0; | 223 | return 0; |
@@ -251,8 +235,6 @@ modpg_init_db(const char *dbid, int argc, char **argv) | |||
251 | int i; | 235 | int i; |
252 | 236 | ||
253 | struct smap_option init_option[] = { | 237 | struct smap_option init_option[] = { |
254 | { SMAP_OPTSTR(defaultdb), smap_opt_bitmask, | ||
255 | &flags, { MDB_DEFDB } }, | ||
256 | { SMAP_OPTSTR(query), smap_opt_string, | 238 | { SMAP_OPTSTR(query), smap_opt_string, |
257 | &query }, | 239 | &query }, |
258 | { SMAP_OPTSTR(positive-reply), smap_opt_string, | 240 | { SMAP_OPTSTR(positive-reply), smap_opt_string, |
@@ -279,12 +261,10 @@ modpg_init_db(const char *dbid, int argc, char **argv) | |||
279 | free(db); | 261 | free(db); |
280 | return NULL; | 262 | return NULL; |
281 | } | 263 | } |
282 | } else if (!(flags & MDB_DEFDB)) { | 264 | } else |
283 | smap_error("%s: no connection info given", dbid); | 265 | flags |= MDB_DEFDB; |
284 | return NULL; | ||
285 | } | ||
286 | 266 | ||
287 | db->flags = MDB_INIT | flags; | 267 | db->flags = flags; |
288 | db->name = dbid; | 268 | db->name = dbid; |
289 | db->template = query; | 269 | db->template = query; |
290 | db->positive_reply = positive_reply; | 270 | db->positive_reply = positive_reply; |