aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-03-22 19:01:04 +0000
committerChristian Grothoff <christian@grothoff.org>2012-03-22 19:01:04 +0000
commit552bbe0f48ea680af5b862338b7c562e62fdc184 (patch)
tree2d56507c4cc3564c70ea5b890736e3312ece4225 /src
parent4c01d543d10a24b30e279cdb061d9ebe459cdcaf (diff)
downloadgnunet-552bbe0f48ea680af5b862338b7c562e62fdc184.tar.gz
gnunet-552bbe0f48ea680af5b862338b7c562e62fdc184.zip
-indenting
Diffstat (limited to 'src')
-rw-r--r--src/mysql/mysql.c140
-rw-r--r--src/postgres/postgres.c51
2 files changed, 86 insertions, 105 deletions
diff --git a/src/mysql/mysql.c b/src/mysql/mysql.c
index ac37a1b49..e4f095396 100644
--- a/src/mysql/mysql.c
+++ b/src/mysql/mysql.c
@@ -53,12 +53,12 @@
53 */ 53 */
54struct GNUNET_MYSQL_Context 54struct GNUNET_MYSQL_Context
55{ 55{
56 56
57 /** 57 /**
58 * Our configuration. 58 * Our configuration.
59 */ 59 */
60 const struct GNUNET_CONFIGURATION_Handle *cfg; 60 const struct GNUNET_CONFIGURATION_Handle *cfg;
61 61
62 /** 62 /**
63 * Our section. 63 * Our section.
64 */ 64 */
@@ -129,7 +129,7 @@ struct GNUNET_MYSQL_StatementHandle
129 */ 129 */
130static char * 130static char *
131get_my_cnf_path (const struct GNUNET_CONFIGURATION_Handle *cfg, 131get_my_cnf_path (const struct GNUNET_CONFIGURATION_Handle *cfg,
132 const char *section) 132 const char *section)
133{ 133{
134 char *cnffile; 134 char *cnffile;
135 char *home_dir; 135 char *home_dir;
@@ -147,12 +147,10 @@ get_my_cnf_path (const struct GNUNET_CONFIGURATION_Handle *cfg,
147 GNUNET_log_from_strerror (GNUNET_ERROR_TYPE_ERROR, "mysql", "getpwuid"); 147 GNUNET_log_from_strerror (GNUNET_ERROR_TYPE_ERROR, "mysql", "getpwuid");
148 return NULL; 148 return NULL;
149 } 149 }
150 if (GNUNET_YES == 150 if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (cfg, section, "CONFIG"))
151 GNUNET_CONFIGURATION_have_value (cfg, section, "CONFIG"))
152 { 151 {
153 GNUNET_assert (GNUNET_OK == 152 GNUNET_assert (GNUNET_OK ==
154 GNUNET_CONFIGURATION_get_value_filename (cfg, 153 GNUNET_CONFIGURATION_get_value_filename (cfg, section,
155 section,
156 "CONFIG", 154 "CONFIG",
157 &cnffile)); 155 &cnffile));
158 configured = GNUNET_YES; 156 configured = GNUNET_YES;
@@ -171,17 +169,16 @@ get_my_cnf_path (const struct GNUNET_CONFIGURATION_Handle *cfg,
171 GNUNET_free (home_dir); 169 GNUNET_free (home_dir);
172 configured = GNUNET_NO; 170 configured = GNUNET_NO;
173#endif 171#endif
174 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, 172 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "mysql",
175 "mysql", 173 _("Trying to use file `%s' for MySQL configuration.\n"),
176 _("Trying to use file `%s' for MySQL configuration.\n"), cnffile); 174 cnffile);
177 if ((0 != STAT (cnffile, &st)) || (0 != ACCESS (cnffile, R_OK)) || 175 if ((0 != STAT (cnffile, &st)) || (0 != ACCESS (cnffile, R_OK)) ||
178 (!S_ISREG (st.st_mode))) 176 (!S_ISREG (st.st_mode)))
179 { 177 {
180 if (configured == GNUNET_YES) 178 if (configured == GNUNET_YES)
181 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, 179 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "mysql",
182 "mysql", 180 _("Could not access file `%s': %s\n"), cnffile,
183 _("Could not access file `%s': %s\n"), cnffile, 181 STRERROR (errno));
184 STRERROR (errno));
185 GNUNET_free (cnffile); 182 GNUNET_free (cnffile);
186 return NULL; 183 return NULL;
187 } 184 }
@@ -222,55 +219,45 @@ iopen (struct GNUNET_MYSQL_Context *mc)
222 mysql_options (mc->dbf, MYSQL_OPT_WRITE_TIMEOUT, (const void *) &timeout); 219 mysql_options (mc->dbf, MYSQL_OPT_WRITE_TIMEOUT, (const void *) &timeout);
223 mysql_dbname = NULL; 220 mysql_dbname = NULL;
224 if (GNUNET_YES == 221 if (GNUNET_YES ==
225 GNUNET_CONFIGURATION_have_value (mc->cfg, mc->section, 222 GNUNET_CONFIGURATION_have_value (mc->cfg, mc->section, "DATABASE"))
226 "DATABASE"))
227 GNUNET_assert (GNUNET_OK == 223 GNUNET_assert (GNUNET_OK ==
228 GNUNET_CONFIGURATION_get_value_string (mc->cfg, 224 GNUNET_CONFIGURATION_get_value_string (mc->cfg, mc->section,
229 mc->section,
230 "DATABASE", 225 "DATABASE",
231 &mysql_dbname)); 226 &mysql_dbname));
232 else 227 else
233 mysql_dbname = GNUNET_strdup ("gnunet"); 228 mysql_dbname = GNUNET_strdup ("gnunet");
234 mysql_user = NULL; 229 mysql_user = NULL;
235 if (GNUNET_YES == 230 if (GNUNET_YES ==
236 GNUNET_CONFIGURATION_have_value (mc->cfg, mc->section, 231 GNUNET_CONFIGURATION_have_value (mc->cfg, mc->section, "USER"))
237 "USER"))
238 { 232 {
239 GNUNET_assert (GNUNET_OK == 233 GNUNET_assert (GNUNET_OK ==
240 GNUNET_CONFIGURATION_get_value_string (mc->cfg, 234 GNUNET_CONFIGURATION_get_value_string (mc->cfg, mc->section,
241 mc->section,
242 "USER", &mysql_user)); 235 "USER", &mysql_user));
243 } 236 }
244 mysql_password = NULL; 237 mysql_password = NULL;
245 if (GNUNET_YES == 238 if (GNUNET_YES ==
246 GNUNET_CONFIGURATION_have_value (mc->cfg, mc->section, 239 GNUNET_CONFIGURATION_have_value (mc->cfg, mc->section, "PASSWORD"))
247 "PASSWORD"))
248 { 240 {
249 GNUNET_assert (GNUNET_OK == 241 GNUNET_assert (GNUNET_OK ==
250 GNUNET_CONFIGURATION_get_value_string (mc->cfg, 242 GNUNET_CONFIGURATION_get_value_string (mc->cfg, mc->section,
251 mc->section,
252 "PASSWORD", 243 "PASSWORD",
253 &mysql_password)); 244 &mysql_password));
254 } 245 }
255 mysql_server = NULL; 246 mysql_server = NULL;
256 if (GNUNET_YES == 247 if (GNUNET_YES ==
257 GNUNET_CONFIGURATION_have_value (mc->cfg, mc->section, 248 GNUNET_CONFIGURATION_have_value (mc->cfg, mc->section, "HOST"))
258 "HOST"))
259 { 249 {
260 GNUNET_assert (GNUNET_OK == 250 GNUNET_assert (GNUNET_OK ==
261 GNUNET_CONFIGURATION_get_value_string (mc->cfg, 251 GNUNET_CONFIGURATION_get_value_string (mc->cfg, mc->section,
262 mc->section,
263 "HOST", 252 "HOST",
264 &mysql_server)); 253 &mysql_server));
265 } 254 }
266 mysql_port = 0; 255 mysql_port = 0;
267 if (GNUNET_YES == 256 if (GNUNET_YES ==
268 GNUNET_CONFIGURATION_have_value (mc->cfg, mc->section, 257 GNUNET_CONFIGURATION_have_value (mc->cfg, mc->section, "PORT"))
269 "PORT"))
270 { 258 {
271 GNUNET_assert (GNUNET_OK == 259 GNUNET_assert (GNUNET_OK ==
272 GNUNET_CONFIGURATION_get_value_number (mc->cfg, 260 GNUNET_CONFIGURATION_get_value_number (mc->cfg, mc->section,
273 mc->section,
274 "PORT", &mysql_port)); 261 "PORT", &mysql_port));
275 } 262 }
276 263
@@ -300,7 +287,7 @@ iopen (struct GNUNET_MYSQL_Context *mc)
300 */ 287 */
301struct GNUNET_MYSQL_Context * 288struct GNUNET_MYSQL_Context *
302GNUNET_MYSQL_context_create (const struct GNUNET_CONFIGURATION_Handle *cfg, 289GNUNET_MYSQL_context_create (const struct GNUNET_CONFIGURATION_Handle *cfg,
303 const char *section) 290 const char *section)
304{ 291{
305 struct GNUNET_MYSQL_Context *mc; 292 struct GNUNET_MYSQL_Context *mc;
306 293
@@ -308,7 +295,7 @@ GNUNET_MYSQL_context_create (const struct GNUNET_CONFIGURATION_Handle *cfg,
308 mc->cfg = cfg; 295 mc->cfg = cfg;
309 mc->section = section; 296 mc->section = section;
310 mc->cnffile = get_my_cnf_path (cfg, section); 297 mc->cnffile = get_my_cnf_path (cfg, section);
311 298
312 return mc; 299 return mc;
313} 300}
314 301
@@ -343,7 +330,7 @@ GNUNET_MYSQL_statements_invalidate (struct GNUNET_MYSQL_Context *mc)
343 330
344/** 331/**
345 * Destroy a mysql context. Also frees all associated prepared statements. 332 * Destroy a mysql context. Also frees all associated prepared statements.
346 * 333 *
347 * @param mc context to destroy 334 * @param mc context to destroy
348 */ 335 */
349void 336void
@@ -373,7 +360,7 @@ GNUNET_MYSQL_context_destroy (struct GNUNET_MYSQL_Context *mc)
373 */ 360 */
374struct GNUNET_MYSQL_StatementHandle * 361struct GNUNET_MYSQL_StatementHandle *
375GNUNET_MYSQL_statement_prepare (struct GNUNET_MYSQL_Context *mc, 362GNUNET_MYSQL_statement_prepare (struct GNUNET_MYSQL_Context *mc,
376 const char *query) 363 const char *query)
377{ 364{
378 struct GNUNET_MYSQL_StatementHandle *sh; 365 struct GNUNET_MYSQL_StatementHandle *sh;
379 366
@@ -393,8 +380,7 @@ GNUNET_MYSQL_statement_prepare (struct GNUNET_MYSQL_Context *mc,
393 * GNUNET_SYSERR if there was a problem 380 * GNUNET_SYSERR if there was a problem
394 */ 381 */
395int 382int
396GNUNET_MYSQL_statement_run (struct GNUNET_MYSQL_Context *mc, 383GNUNET_MYSQL_statement_run (struct GNUNET_MYSQL_Context *mc, const char *sql)
397 const char *sql)
398{ 384{
399 if ((NULL == mc->dbf) && (GNUNET_OK != iopen (mc))) 385 if ((NULL == mc->dbf) && (GNUNET_OK != iopen (mc)))
400 return GNUNET_SYSERR; 386 return GNUNET_SYSERR;
@@ -453,8 +439,8 @@ prepare_statement (struct GNUNET_MYSQL_Context *mc,
453 * @return MySQL statement handle, NULL on error 439 * @return MySQL statement handle, NULL on error
454 */ 440 */
455MYSQL_STMT * 441MYSQL_STMT *
456GNUNET_MYSQL_statement_get_stmt (struct GNUNET_MYSQL_Context *mc, 442GNUNET_MYSQL_statement_get_stmt (struct GNUNET_MYSQL_Context * mc,
457 struct GNUNET_MYSQL_StatementHandle *sh) 443 struct GNUNET_MYSQL_StatementHandle * sh)
458{ 444{
459 (void) prepare_statement (mc, sh); 445 (void) prepare_statement (mc, sh);
460 return sh->statement; 446 return sh->statement;
@@ -471,9 +457,8 @@ GNUNET_MYSQL_statement_get_stmt (struct GNUNET_MYSQL_Context *mc,
471 * @return GNUNET_SYSERR on error, GNUNET_OK on success 457 * @return GNUNET_SYSERR on error, GNUNET_OK on success
472 */ 458 */
473static int 459static int
474init_params (struct GNUNET_MYSQL_Context *mc, 460init_params (struct GNUNET_MYSQL_Context *mc,
475 struct GNUNET_MYSQL_StatementHandle *sh, 461 struct GNUNET_MYSQL_StatementHandle *sh, va_list ap)
476 va_list ap)
477{ 462{
478 MYSQL_BIND qbind[MAX_PARAM]; 463 MYSQL_BIND qbind[MAX_PARAM];
479 unsigned int pc; 464 unsigned int pc;
@@ -532,21 +517,19 @@ init_params (struct GNUNET_MYSQL_Context *mc,
532 } 517 }
533 if (mysql_stmt_bind_param (sh->statement, qbind)) 518 if (mysql_stmt_bind_param (sh->statement, qbind))
534 { 519 {
535 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, 520 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "mysql",
536 "mysql", 521 _("`%s' failed at %s:%d with error: %s\n"),
537 _("`%s' failed at %s:%d with error: %s\n"), 522 "mysql_stmt_bind_param", __FILE__, __LINE__,
538 "mysql_stmt_bind_param", __FILE__, __LINE__, 523 mysql_stmt_error (sh->statement));
539 mysql_stmt_error (sh->statement));
540 GNUNET_MYSQL_statements_invalidate (mc); 524 GNUNET_MYSQL_statements_invalidate (mc);
541 return GNUNET_SYSERR; 525 return GNUNET_SYSERR;
542 } 526 }
543 if (mysql_stmt_execute (sh->statement)) 527 if (mysql_stmt_execute (sh->statement))
544 { 528 {
545 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, 529 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "mysql",
546 "mysql", 530 _("`%s' failed at %s:%d with error: %s\n"),
547 _("`%s' failed at %s:%d with error: %s\n"), 531 "mysql_stmt_execute", __FILE__, __LINE__,
548 "mysql_stmt_execute", __FILE__, __LINE__, 532 mysql_stmt_error (sh->statement));
549 mysql_stmt_error (sh->statement));
550 GNUNET_MYSQL_statements_invalidate (mc); 533 GNUNET_MYSQL_statements_invalidate (mc);
551 return GNUNET_SYSERR; 534 return GNUNET_SYSERR;
552 } 535 }
@@ -573,12 +556,13 @@ init_params (struct GNUNET_MYSQL_Context *mc,
573 */ 556 */
574int 557int
575GNUNET_MYSQL_statement_run_prepared_select_va (struct GNUNET_MYSQL_Context *mc, 558GNUNET_MYSQL_statement_run_prepared_select_va (struct GNUNET_MYSQL_Context *mc,
576 struct GNUNET_MYSQL_StatementHandle *s, 559 struct
577 unsigned int result_size, 560 GNUNET_MYSQL_StatementHandle *s,
578 MYSQL_BIND * results, 561 unsigned int result_size,
579 GNUNET_MYSQL_DataProcessor processor, 562 MYSQL_BIND * results,
580 void *processor_cls, 563 GNUNET_MYSQL_DataProcessor
581 va_list ap) 564 processor, void *processor_cls,
565 va_list ap)
582{ 566{
583 int ret; 567 int ret;
584 unsigned int rsize; 568 unsigned int rsize;
@@ -609,7 +593,7 @@ GNUNET_MYSQL_statement_run_prepared_select_va (struct GNUNET_MYSQL_Context *mc,
609 GNUNET_MYSQL_statements_invalidate (mc); 593 GNUNET_MYSQL_statements_invalidate (mc);
610 return GNUNET_SYSERR; 594 return GNUNET_SYSERR;
611 } 595 }
612 596
613 total = 0; 597 total = 0;
614 while (1) 598 while (1)
615 { 599 {
@@ -618,17 +602,16 @@ GNUNET_MYSQL_statement_run_prepared_select_va (struct GNUNET_MYSQL_Context *mc,
618 break; 602 break;
619 if (ret != 0) 603 if (ret != 0)
620 { 604 {
621 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, 605 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "mysql",
622 "mysql", 606 _("`%s' failed at %s:%d with error: %s\n"),
623 _("`%s' failed at %s:%d with error: %s\n"), 607 "mysql_stmt_fetch", __FILE__, __LINE__,
624 "mysql_stmt_fetch", __FILE__, __LINE__, 608 mysql_stmt_error (s->statement));
625 mysql_stmt_error (s->statement));
626 GNUNET_MYSQL_statements_invalidate (mc); 609 GNUNET_MYSQL_statements_invalidate (mc);
627 return GNUNET_SYSERR; 610 return GNUNET_SYSERR;
628 } 611 }
629 total++; 612 total++;
630 if ( (NULL == processor) || 613 if ((NULL == processor) ||
631 (GNUNET_OK != processor (processor_cls, rsize, results)) ) 614 (GNUNET_OK != processor (processor_cls, rsize, results)))
632 break; 615 break;
633 } 616 }
634 mysql_stmt_reset (s->statement); 617 mysql_stmt_reset (s->statement);
@@ -654,16 +637,20 @@ GNUNET_MYSQL_statement_run_prepared_select_va (struct GNUNET_MYSQL_Context *mc,
654 */ 637 */
655int 638int
656GNUNET_MYSQL_statement_run_prepared_select (struct GNUNET_MYSQL_Context *mc, 639GNUNET_MYSQL_statement_run_prepared_select (struct GNUNET_MYSQL_Context *mc,
657 struct GNUNET_MYSQL_StatementHandle *sh, 640 struct GNUNET_MYSQL_StatementHandle
658 unsigned int result_size, MYSQL_BIND * results, 641 *sh, unsigned int result_size,
659 GNUNET_MYSQL_DataProcessor processor, 642 MYSQL_BIND * results,
660 void *processor_cls, ...) 643 GNUNET_MYSQL_DataProcessor
644 processor, void *processor_cls, ...)
661{ 645{
662 va_list ap; 646 va_list ap;
663 int ret; 647 int ret;
664 648
665 va_start (ap, processor_cls); 649 va_start (ap, processor_cls);
666 ret = GNUNET_MYSQL_statement_run_prepared_select_va (mc, sh, result_size, results, processor, processor_cls, ap); 650 ret =
651 GNUNET_MYSQL_statement_run_prepared_select_va (mc, sh, result_size,
652 results, processor,
653 processor_cls, ap);
667 va_end (ap); 654 va_end (ap);
668 return ret; 655 return ret;
669} 656}
@@ -684,8 +671,8 @@ GNUNET_MYSQL_statement_run_prepared_select (struct GNUNET_MYSQL_Context *mc,
684 */ 671 */
685int 672int
686GNUNET_MYSQL_statement_run_prepared (struct GNUNET_MYSQL_Context *mc, 673GNUNET_MYSQL_statement_run_prepared (struct GNUNET_MYSQL_Context *mc,
687 struct GNUNET_MYSQL_StatementHandle *sh, 674 struct GNUNET_MYSQL_StatementHandle *sh,
688 unsigned long long *insert_id, ...) 675 unsigned long long *insert_id, ...)
689{ 676{
690 va_list ap; 677 va_list ap;
691 int affected; 678 int affected;
@@ -708,4 +695,3 @@ GNUNET_MYSQL_statement_run_prepared (struct GNUNET_MYSQL_Context *mc,
708 695
709 696
710/* end of mysql.c */ 697/* end of mysql.c */
711
diff --git a/src/postgres/postgres.c b/src/postgres/postgres.c
index c6b9a5aa6..40bda2436 100644
--- a/src/postgres/postgres.c
+++ b/src/postgres/postgres.c
@@ -35,15 +35,15 @@
35 * @param ret return value from database operation to check 35 * @param ret return value from database operation to check
36 * @param expected_status desired status 36 * @param expected_status desired status
37 * @param command description of the command that was run 37 * @param command description of the command that was run
38 * @param args arguments given to the command 38 * @param args arguments given to the command
39 * @param filename name of the source file where the command was run 39 * @param filename name of the source file where the command was run
40 * @param line line number in the source file 40 * @param line line number in the source file
41 * @return GNUNET_OK if the result is acceptable 41 * @return GNUNET_OK if the result is acceptable
42 */ 42 */
43int 43int
44GNUNET_POSTGRES_check_result_ (PGconn *dbh, PGresult * ret, int expected_status, 44GNUNET_POSTGRES_check_result_ (PGconn * dbh, PGresult * ret,
45 const char *command, const char *args, const char *filename, 45 int expected_status, const char *command,
46 int line) 46 const char *args, const char *filename, int line)
47{ 47{
48 if (ret == NULL) 48 if (ret == NULL)
49 { 49 {
@@ -56,9 +56,8 @@ GNUNET_POSTGRES_check_result_ (PGconn *dbh, PGresult * ret, int expected_status,
56 if (PQresultStatus (ret) != expected_status) 56 if (PQresultStatus (ret) != expected_status)
57 { 57 {
58 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 58 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
59 "postgres", 59 "postgres", _("`%s:%s' failed at %s:%d with error: %s"),
60 _("`%s:%s' failed at %s:%d with error: %s"), command, args, 60 command, args, filename, line, PQerrorMessage (dbh));
61 filename, line, PQerrorMessage (dbh));
62 PQclear (ret); 61 PQclear (ret);
63 return GNUNET_SYSERR; 62 return GNUNET_SYSERR;
64 } 63 }
@@ -72,19 +71,19 @@ GNUNET_POSTGRES_check_result_ (PGconn *dbh, PGresult * ret, int expected_status,
72 * @param dbh database handle 71 * @param dbh database handle
73 * @param sql statement to run 72 * @param sql statement to run
74 * @param filename filename for error reporting 73 * @param filename filename for error reporting
75 * @param line code line for error reporting 74 * @param line code line for error reporting
76 * @return GNUNET_OK on success 75 * @return GNUNET_OK on success
77 */ 76 */
78int 77int
79GNUNET_POSTGRES_exec_ (PGconn *dbh, const char *sql, 78GNUNET_POSTGRES_exec_ (PGconn * dbh, const char *sql, const char *filename,
80 const char *filename, 79 int line)
81 int line)
82{ 80{
83 PGresult *ret; 81 PGresult *ret;
84 82
85 ret = PQexec (dbh, sql); 83 ret = PQexec (dbh, sql);
86 if (GNUNET_OK != 84 if (GNUNET_OK !=
87 GNUNET_POSTGRES_check_result_ (dbh, ret, PGRES_COMMAND_OK, "PQexec", sql, filename, line)) 85 GNUNET_POSTGRES_check_result_ (dbh, ret, PGRES_COMMAND_OK, "PQexec", sql,
86 filename, line))
88 return GNUNET_SYSERR; 87 return GNUNET_SYSERR;
89 PQclear (ret); 88 PQclear (ret);
90 return GNUNET_OK; 89 return GNUNET_OK;
@@ -103,14 +102,15 @@ GNUNET_POSTGRES_exec_ (PGconn *dbh, const char *sql,
103 * @return GNUNET_OK on success 102 * @return GNUNET_OK on success
104 */ 103 */
105int 104int
106GNUNET_POSTGRES_prepare_ (PGconn *dbh, const char *name, const char *sql, 105GNUNET_POSTGRES_prepare_ (PGconn * dbh, const char *name, const char *sql,
107 int nparms, const char *filename, int line) 106 int nparms, const char *filename, int line)
108{ 107{
109 PGresult *ret; 108 PGresult *ret;
110 109
111 ret = PQprepare (dbh, name, sql, nparms, NULL); 110 ret = PQprepare (dbh, name, sql, nparms, NULL);
112 if (GNUNET_OK != 111 if (GNUNET_OK !=
113 GNUNET_POSTGRES_check_result_ (dbh, ret, PGRES_COMMAND_OK, "PQprepare", sql, filename, line)) 112 GNUNET_POSTGRES_check_result_ (dbh, ret, PGRES_COMMAND_OK, "PQprepare",
113 sql, filename, line))
114 return GNUNET_SYSERR; 114 return GNUNET_SYSERR;
115 PQclear (ret); 115 PQclear (ret);
116 return GNUNET_OK; 116 return GNUNET_OK;
@@ -125,17 +125,15 @@ GNUNET_POSTGRES_prepare_ (PGconn *dbh, const char *name, const char *sql,
125 * @return the postgres handle 125 * @return the postgres handle
126 */ 126 */
127PGconn * 127PGconn *
128GNUNET_POSTGRES_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, 128GNUNET_POSTGRES_connect (const struct GNUNET_CONFIGURATION_Handle * cfg,
129 const char *section) 129 const char *section)
130{ 130{
131 PGconn *dbh; 131 PGconn *dbh;
132 char *conninfo; 132 char *conninfo;
133 133
134 /* Open database and precompile statements */ 134 /* Open database and precompile statements */
135 if (GNUNET_OK != 135 if (GNUNET_OK !=
136 GNUNET_CONFIGURATION_get_value_string (cfg, 136 GNUNET_CONFIGURATION_get_value_string (cfg, section, "CONFIG", &conninfo))
137 section, "CONFIG",
138 &conninfo))
139 conninfo = NULL; 137 conninfo = NULL;
140 dbh = PQconnectdb (conninfo == NULL ? "" : conninfo); 138 dbh = PQconnectdb (conninfo == NULL ? "" : conninfo);
141 GNUNET_free_non_null (conninfo); 139 GNUNET_free_non_null (conninfo);
@@ -166,9 +164,7 @@ GNUNET_POSTGRES_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
166 * @return GNUNET_OK on success 164 * @return GNUNET_OK on success
167 */ 165 */
168int 166int
169GNUNET_POSTGRES_delete_by_rowid (PGconn *dbh, 167GNUNET_POSTGRES_delete_by_rowid (PGconn * dbh, const char *stmt, uint32_t rowid)
170 const char *stmt,
171 uint32_t rowid)
172{ 168{
173 uint32_t brow = htonl (rowid); 169 uint32_t brow = htonl (rowid);
174 const char *paramValues[] = { (const char *) &brow }; 170 const char *paramValues[] = { (const char *) &brow };
@@ -177,12 +173,11 @@ GNUNET_POSTGRES_delete_by_rowid (PGconn *dbh,
177 PGresult *ret; 173 PGresult *ret;
178 174
179 ret = 175 ret =
180 PQexecPrepared (dbh, stmt, 1, paramValues, paramLengths, 176 PQexecPrepared (dbh, stmt, 1, paramValues, paramLengths, paramFormats, 1);
181 paramFormats, 1);
182 if (GNUNET_OK != 177 if (GNUNET_OK !=
183 GNUNET_POSTGRES_check_result_ (dbh, ret, PGRES_COMMAND_OK, "PQexecPrepared", "delrow", 178 GNUNET_POSTGRES_check_result_ (dbh, ret, PGRES_COMMAND_OK,
184 __FILE__, 179 "PQexecPrepared", "delrow", __FILE__,
185 __LINE__)) 180 __LINE__))
186 { 181 {
187 return GNUNET_SYSERR; 182 return GNUNET_SYSERR;
188 } 183 }