aboutsummaryrefslogtreecommitdiff
path: root/src/include/gnunet_sq_lib.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/include/gnunet_sq_lib.h')
-rw-r--r--src/include/gnunet_sq_lib.h141
1 files changed, 131 insertions, 10 deletions
diff --git a/src/include/gnunet_sq_lib.h b/src/include/gnunet_sq_lib.h
index f3adbc4c2..d5aa839bd 100644
--- a/src/include/gnunet_sq_lib.h
+++ b/src/include/gnunet_sq_lib.h
@@ -2,16 +2,18 @@
2 This file is part of GNUnet 2 This file is part of GNUnet
3 Copyright (C) 2017 GNUnet e.V. 3 Copyright (C) 2017 GNUnet e.V.
4 4
5 GNUnet is free software; you can redistribute it and/or modify it under the 5 GNUnet is free software: you can redistribute it and/or modify it
6 terms of the GNU General Public License as published by the Free Software 6 under the terms of the GNU Affero General Public License as published
7 Foundation; either version 3, or (at your option) any later version. 7 by the Free Software Foundation, either version 3 of the License,
8 8 or (at your option) any later version.
9 GNUnet is distributed in the hope that it will be useful, but WITHOUT ANY 9
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 10 GNUnet is distributed in the hope that it will be useful, but
11 A PARTICULAR PURPOSE. See the GNU General Public License for more details. 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 You should have received a copy of the GNU General Public License along with 13 Affero General Public License for more details.
14 GNUnet; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/> 14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
15*/ 17*/
16/** 18/**
17 * @file include/gnunet_sq_lib.h 19 * @file include/gnunet_sq_lib.h
@@ -446,6 +448,125 @@ void
446GNUNET_SQ_cleanup_result (struct GNUNET_SQ_ResultSpec *rs); 448GNUNET_SQ_cleanup_result (struct GNUNET_SQ_ResultSpec *rs);
447 449
448 450
451
452/* ******************** sq_prepare.c functions ************** */
453
454
455/**
456 * Information needed to run a list of SQL statements using
457 * #GNUNET_SQ_exec_statements().
458 */
459struct GNUNET_SQ_PrepareStatement {
460
461 /**
462 * Actual SQL statement.
463 */
464 const char *sql;
465
466 /**
467 * Where to store handle?
468 */
469 sqlite3_stmt **pstmt;
470
471};
472
473
474/**
475 * Terminator for executable statement list.
476 */
477#define GNUNET_SQ_PREPARE_END { NULL, NULL }
478
479
480/**
481 * Create a `struct GNUNET_SQ_PrepareStatement`
482 *
483 * @param sql actual SQL statement
484 * @param pstmt where to store the handle
485 * @return initialized struct
486 */
487struct GNUNET_SQ_PrepareStatement
488GNUNET_SQ_make_prepare (const char *sql,
489 sqlite3_stmt **pstmt);
490
491
492
493/**
494 * Prepare all statements given in the (NULL,NULL)-terminated
495 * array at @a ps
496 *
497 * @param dbh database handle
498 * @param ps array of statements to prepare
499 * @return #GNUNET_OK on success
500 */
501int
502GNUNET_SQ_prepare (sqlite3 *dbh,
503 const struct GNUNET_SQ_PrepareStatement *ps);
504
505
506/* ******************** sq_exec.c functions ************** */
507
508
509/**
510 * Information needed to run a list of SQL statements using
511 * #GNUNET_SQ_exec_statements().
512 */
513struct GNUNET_SQ_ExecuteStatement {
514
515 /**
516 * Actual SQL statement.
517 */
518 const char *sql;
519
520 /**
521 * Should we ignore errors?
522 */
523 int ignore_errors;
524
525};
526
527
528/**
529 * Terminator for executable statement list.
530 */
531#define GNUNET_SQ_EXECUTE_STATEMENT_END { NULL, GNUNET_SYSERR }
532
533
534/**
535 * Create a `struct GNUNET_SQ_ExecuteStatement` where errors are fatal.
536 *
537 * @param sql actual SQL statement
538 * @return initialized struct
539 */
540struct GNUNET_SQ_ExecuteStatement
541GNUNET_SQ_make_execute (const char *sql);
542
543
544/**
545 * Create a `struct GNUNET_SQ_ExecuteStatement` where errors should
546 * be tolerated.
547 *
548 * @param sql actual SQL statement
549 * @return initialized struct
550 */
551struct GNUNET_SQ_ExecuteStatement
552GNUNET_SQ_make_try_execute (const char *sql);
553
554
555/**
556 * Request execution of an array of statements @a es from Postgres.
557 *
558 * @param dbh database to execute the statements over
559 * @param es #GNUNET_PQ_PREPARED_STATEMENT_END-terminated array of prepared
560 * statements.
561 * @return #GNUNET_OK on success (modulo statements where errors can be ignored)
562 * #GNUNET_SYSERR on error
563 */
564int
565GNUNET_SQ_exec_statements (sqlite3 *dbh,
566 const struct GNUNET_SQ_ExecuteStatement *es);
567
568
569
449#endif /* GNUNET_SQ_LIB_H_ */ 570#endif /* GNUNET_SQ_LIB_H_ */
450 571
451/* end of include/gnunet_sq_lib.h */ 572/* end of include/gnunet_sq_lib.h */