aboutsummaryrefslogtreecommitdiff
path: root/src/include/gnunet_pq_lib.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/include/gnunet_pq_lib.h')
-rw-r--r--src/include/gnunet_pq_lib.h102
1 files changed, 93 insertions, 9 deletions
diff --git a/src/include/gnunet_pq_lib.h b/src/include/gnunet_pq_lib.h
index fe3fabbea..6a2227581 100644
--- a/src/include/gnunet_pq_lib.h
+++ b/src/include/gnunet_pq_lib.h
@@ -470,7 +470,8 @@ GNUNET_PQ_result_spec_absolute_time_nbo (const char *name,
470 * @return array entry for the result specification to use 470 * @return array entry for the result specification to use
471 */ 471 */
472struct GNUNET_PQ_ResultSpec 472struct GNUNET_PQ_ResultSpec
473GNUNET_PQ_result_spec_uint16 (const char *name, uint16_t *u16); 473GNUNET_PQ_result_spec_uint16 (const char *name,
474 uint16_t *u16);
474 475
475 476
476/** 477/**
@@ -481,7 +482,8 @@ GNUNET_PQ_result_spec_uint16 (const char *name, uint16_t *u16);
481 * @return array entry for the result specification to use 482 * @return array entry for the result specification to use
482 */ 483 */
483struct GNUNET_PQ_ResultSpec 484struct GNUNET_PQ_ResultSpec
484GNUNET_PQ_result_spec_uint32 (const char *name, uint32_t *u32); 485GNUNET_PQ_result_spec_uint32 (const char *name,
486 uint32_t *u32);
485 487
486 488
487/** 489/**
@@ -492,7 +494,8 @@ GNUNET_PQ_result_spec_uint32 (const char *name, uint32_t *u32);
492 * @return array entry for the result specification to use 494 * @return array entry for the result specification to use
493 */ 495 */
494struct GNUNET_PQ_ResultSpec 496struct GNUNET_PQ_ResultSpec
495GNUNET_PQ_result_spec_uint64 (const char *name, uint64_t *u64); 497GNUNET_PQ_result_spec_uint64 (const char *name,
498 uint64_t *u64);
496 499
497 500
498/* ************************* pq.c functions ************************ */ 501/* ************************* pq.c functions ************************ */
@@ -641,11 +644,11 @@ GNUNET_PQ_eval_prepared_multi_select (struct GNUNET_PQ_Context *db,
641 * codes to `enum GNUNET_DB_QueryStatus`. 644 * codes to `enum GNUNET_DB_QueryStatus`.
642 */ 645 */
643enum GNUNET_DB_QueryStatus 646enum GNUNET_DB_QueryStatus
644GNUNET_PQ_eval_prepared_singleton_select (struct GNUNET_PQ_Context *db, 647GNUNET_PQ_eval_prepared_singleton_select (
645 const char *statement_name, 648 struct GNUNET_PQ_Context *db,
646 const struct 649 const char *statement_name,
647 GNUNET_PQ_QueryParam *params, 650 const struct GNUNET_PQ_QueryParam *params,
648 struct GNUNET_PQ_ResultSpec *rs); 651 struct GNUNET_PQ_ResultSpec *rs);
649 652
650 653
651/* ******************** pq_prepare.c functions ************** */ 654/* ******************** pq_prepare.c functions ************** */
@@ -772,7 +775,7 @@ GNUNET_PQ_make_try_execute (const char *sql);
772 * @return #GNUNET_OK on success (modulo statements where errors can be ignored) 775 * @return #GNUNET_OK on success (modulo statements where errors can be ignored)
773 * #GNUNET_SYSERR on error 776 * #GNUNET_SYSERR on error
774 */ 777 */
775int 778enum GNUNET_GenericReturnValue
776GNUNET_PQ_exec_statements (struct GNUNET_PQ_Context *db, 779GNUNET_PQ_exec_statements (struct GNUNET_PQ_Context *db,
777 const struct GNUNET_PQ_ExecuteStatement *es); 780 const struct GNUNET_PQ_ExecuteStatement *es);
778 781
@@ -781,6 +784,29 @@ GNUNET_PQ_exec_statements (struct GNUNET_PQ_Context *db,
781 784
782 785
783/** 786/**
787 * Flags to control PQ operation.
788 */
789enum GNUNET_PQ_Options
790{
791 /**
792 * Traditional default. Do nothing special.
793 */
794 GNUNET_PQ_FLAG_NONE = 0,
795
796 /**
797 * Dropping database. Do not attempt to initialize
798 * versioning schema if not present.
799 */
800 GNUNET_PQ_FLAG_DROP = 1,
801
802 /**
803 * Check database version is current. Fail to connect if it is not.
804 */
805 GNUNET_PQ_FLAG_CHECK_CURRENT = 2
806};
807
808
809/**
784 * Create a connection to the Postgres database using @a config_str for the 810 * Create a connection to the Postgres database using @a config_str for the
785 * configuration. Initialize logging via GNUnet's log routines and disable 811 * configuration. Initialize logging via GNUnet's log routines and disable
786 * Postgres's logger. Also ensures that the statements in @a load_path and @a 812 * Postgres's logger. Also ensures that the statements in @a load_path and @a
@@ -810,6 +836,37 @@ GNUNET_PQ_connect (const char *config_str,
810 836
811 837
812/** 838/**
839 * Create a connection to the Postgres database using @a config_str for the
840 * configuration. Initialize logging via GNUnet's log routines and disable
841 * Postgres's logger. Also ensures that the statements in @a load_path and @a
842 * es are executed whenever we (re)connect to the database, and that the
843 * prepared statements in @a ps are "ready". If statements in @es fail that
844 * were created with #GNUNET_PQ_make_execute(), then the entire operation
845 * fails.
846 *
847 * In @a load_path, a list of "$XXXX.sql" files is expected where $XXXX
848 * must be a sequence of contiguous integer values starting at 0000.
849 * These files are then loaded in sequence using "psql $config_str" before
850 * running statements from @e es. The directory is inspected again on
851 * reconnect.
852 *
853 * @param config_str configuration to use
854 * @param load_path path to directory with SQL transactions to run, can be NULL
855 * @param es #GNUNET_PQ_PREPARED_STATEMENT_END-terminated
856 * array of statements to execute upon EACH connection, can be NULL
857 * @param ps array of prepared statements to prepare, can be NULL
858 * @param flags connection flags
859 * @return NULL on error
860 */
861struct GNUNET_PQ_Context *
862GNUNET_PQ_connect2 (const char *config_str,
863 const char *load_path,
864 const struct GNUNET_PQ_ExecuteStatement *es,
865 const struct GNUNET_PQ_PreparedStatement *ps,
866 enum GNUNET_PQ_Options flags);
867
868
869/**
813 * Connect to a postgres database using the configuration 870 * Connect to a postgres database using the configuration
814 * option "CONFIG" in @a section. Also ensures that the 871 * option "CONFIG" in @a section. Also ensures that the
815 * statements in @a es are executed whenever we (re)connect to the 872 * statements in @a es are executed whenever we (re)connect to the
@@ -835,6 +892,33 @@ GNUNET_PQ_connect_with_cfg (const struct GNUNET_CONFIGURATION_Handle *cfg,
835 892
836 893
837/** 894/**
895 * Connect to a postgres database using the configuration
896 * option "CONFIG" in @a section. Also ensures that the
897 * statements in @a es are executed whenever we (re)connect to the
898 * database, and that the prepared statements in @a ps are "ready".
899 *
900 * The caller does not have to ensure that @a es and @a ps remain allocated
901 * and initialized in memory until #GNUNET_PQ_disconnect() is called, as a copy will be made.
902 *
903 * @param cfg configuration
904 * @param section configuration section to use to get Postgres configuration options
905 * @param load_path_suffix suffix to append to the SQL_DIR in the configuration
906 * @param es #GNUNET_PQ_PREPARED_STATEMENT_END-terminated
907 * array of statements to execute upon EACH connection, can be NULL
908 * @param ps array of prepared statements to prepare, can be NULL
909 * @param flags connection flags
910 * @return the postgres handle, NULL on error
911 */
912struct GNUNET_PQ_Context *
913GNUNET_PQ_connect_with_cfg2 (const struct GNUNET_CONFIGURATION_Handle *cfg,
914 const char *section,
915 const char *load_path_suffix,
916 const struct GNUNET_PQ_ExecuteStatement *es,
917 const struct GNUNET_PQ_PreparedStatement *ps,
918 enum GNUNET_PQ_Options flags);
919
920
921/**
838 * Reinitialize the database @a db if the connection is down. 922 * Reinitialize the database @a db if the connection is down.
839 * 923 *
840 * @param db database connection to reinitialize 924 * @param db database connection to reinitialize