donau

Donation authority for GNU Taler (experimental)
Log | Files | Refs | Submodules | README | LICENSE

pg_create_tables.c (2676B)


      1 /*
      2    This file is part of TALER
      3    Copyright (C) 2024 Taler Systems SA
      4 
      5    TALER is free software; you can redistribute it and/or modify it under the
      6    terms of the GNU General Public License as published by the Free Software
      7    Foundation; either version 3, or (at your option) any later version.
      8 
      9    TALER is distributed in the hope that it will be useful, but WITHOUT ANY
     10    WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
     11    A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
     12 
     13    You should have received a copy of the GNU General Public License along with
     14    TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
     15  */
     16 /**
     17  * @file donaudb/pg_create_tables.c
     18  * @brief Implementation of the create_tables function for Postgres
     19  * @author Johannes Casaburi
     20  */
     21 #include <donau_config.h>
     22 #include <taler/taler_error_codes.h>
     23 #include <taler/taler_dbevents.h>
     24 #include <taler/taler_pq_lib.h>
     25 #include "pg_create_tables.h"
     26 #include "pg_helper.h"
     27 
     28 
     29 enum GNUNET_GenericReturnValue
     30 DH_PG_create_tables (void *cls)
     31 {
     32   struct PostgresClosure *pg = cls;
     33   struct GNUNET_PQ_Context *conn;
     34   enum GNUNET_GenericReturnValue ret = GNUNET_OK;
     35 
     36   struct GNUNET_PQ_QueryParam params[] = {
     37     GNUNET_PQ_query_param_end
     38   };
     39   struct GNUNET_PQ_PreparedStatement ps[] = {
     40     GNUNET_PQ_make_prepare ("create_tables",
     41                             "CALL"
     42                             " donau.do_create_tables"
     43                             " ();"),
     44     GNUNET_PQ_PREPARED_STATEMENT_END
     45   };
     46   struct GNUNET_PQ_ExecuteStatement es[] = {
     47     GNUNET_PQ_make_try_execute ("SET search_path TO donau;"),
     48     GNUNET_PQ_EXECUTE_STATEMENT_END
     49   };
     50 
     51   conn = GNUNET_PQ_connect_with_cfg (pg->cfg,
     52                                      "donaudb-postgres",
     53                                      "donau-",
     54                                      es,
     55                                      ps);
     56   if (NULL == conn)
     57   {
     58     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     59                 "Failed to connect to database\n");
     60     return GNUNET_SYSERR;
     61   }
     62   if (0 >
     63       GNUNET_PQ_eval_prepared_non_select (conn,
     64                                           "create_tables",
     65                                           params))
     66   {
     67     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     68                 "Failed to create tables\n");
     69     ret = GNUNET_SYSERR;
     70   }
     71   if (GNUNET_OK == ret)
     72   {
     73     ret = GNUNET_PQ_exec_sql (conn,
     74                               "procedures");
     75     if (GNUNET_OK != ret)
     76       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     77                   "Failed to load stored procedures: %d\n",
     78                   ret);
     79   }
     80   GNUNET_PQ_disconnect (conn);
     81   return ret;
     82 }