donau

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

create_tables.c (2664B)


      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 src/donaudb/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 "create_tables.h"
     26 #include "helper.h"
     27 
     28 
     29 enum GNUNET_GenericReturnValue
     30 DONAUDB_create_tables (struct DONAUDB_PostgresContext *ctx)
     31 {
     32   struct GNUNET_PQ_Context *conn;
     33   enum GNUNET_GenericReturnValue ret = GNUNET_OK;
     34 
     35   struct GNUNET_PQ_QueryParam params[] = {
     36     GNUNET_PQ_query_param_end
     37   };
     38   struct GNUNET_PQ_PreparedStatement ps[] = {
     39     GNUNET_PQ_make_prepare ("create_tables",
     40                             "CALL"
     41                             " donau.do_create_tables"
     42                             " ();"),
     43     GNUNET_PQ_PREPARED_STATEMENT_END
     44   };
     45   struct GNUNET_PQ_ExecuteStatement es[] = {
     46     GNUNET_PQ_make_try_execute ("SET search_path TO donau;"),
     47     GNUNET_PQ_EXECUTE_STATEMENT_END
     48   };
     49 
     50   conn = GNUNET_PQ_connect_with_cfg (ctx->cfg,
     51                                      "donaudb-postgres",
     52                                      "donau-",
     53                                      es,
     54                                      ps);
     55   if (NULL == conn)
     56   {
     57     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     58                 "Failed to connect to database\n");
     59     return GNUNET_SYSERR;
     60   }
     61   if (0 >
     62       GNUNET_PQ_eval_prepared_non_select (conn,
     63                                           "create_tables",
     64                                           params))
     65   {
     66     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     67                 "Failed to create tables\n");
     68     ret = GNUNET_SYSERR;
     69   }
     70   if (GNUNET_OK == ret)
     71   {
     72     ret = GNUNET_PQ_exec_sql (conn,
     73                               "procedures");
     74     if (GNUNET_OK != ret)
     75       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     76                   "Failed to load stored procedures: %d\n",
     77                   ret);
     78   }
     79   GNUNET_PQ_disconnect (conn);
     80   return ret;
     81 }