2 This file is part of GNUnet
3 (C) 2012 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
21 * @file include/gnunet_postgres_lib.h
22 * @brief library to help with access to a Postgres database
23 * @author Christian Grothoff
25 #ifndef GNUNET_POSTGRES_LIB_H
26 #define GNUNET_POSTGRES_LIB_H
28 #include "gnunet_util_lib.h"
29 #include <postgresql/libpq-fe.h>
34 #if 0 /* keep Emacsens' auto-indent happy */
41 * Check if the result obtained from Postgres has
42 * the desired status code. If not, log an error, clear the
43 * result and return GNUNET_SYSERR.
45 * @param dbh database handle
46 * @param ret return value from database operation to check
47 * @param expected_status desired status
48 * @param command description of the command that was run
49 * @param args arguments given to the command
50 * @param filename name of the source file where the command was run
51 * @param line line number in the source file
52 * @return GNUNET_OK if the result is acceptable
55 GNUNET_POSTGRES_check_result_ (PGconn *dbh, PGresult * ret, int expected_status,
56 const char *command, const char *args,
57 const char *filename, int line);
61 * Check if the result obtained from Postgres has
62 * the desired status code. If not, log an error, clear the
63 * result and return GNUNET_SYSERR.
65 * @param dbh database handle
66 * @param ret return value from database operation to check
67 * @param expected_status desired status
68 * @param command description of the command that was run
69 * @param args arguments given to the command
70 * @return GNUNET_OK if the result is acceptable
72 #define GNUNET_POSTGRES_check_result(dbh,ret,expected_status,command,args) GNUNET_POSTGRES_check_result_(dbh,ret,expected_status,command,args,__FILE__,__LINE__)
76 * Run simple SQL statement (without results).
78 * @param dbh database handle
79 * @param sql statement to run
80 * @param filename filename for error reporting
81 * @param line code line for error reporting
82 * @return GNUNET_OK on success
85 GNUNET_POSTGRES_exec_ (PGconn *dbh, const char *sql, const char *filename, int line);
89 * Run simple SQL statement (without results).
91 * @param dbh database handle
92 * @param sql statement to run
93 * @return GNUNET_OK on success
95 #define GNUNET_POSTGRES_exec(dbh,sql) GNUNET_POSTGRES_exec_(dbh,sql,__FILE__,__LINE__)
99 * Prepare SQL statement.
101 * @param dbh database handle
102 * @param name name for the prepared SQL statement
103 * @param sql SQL code to prepare
104 * @param nparams number of parameters in sql
105 * @param filename filename for error reporting
106 * @param line code line for error reporting
107 * @return GNUNET_OK on success
110 GNUNET_POSTGRES_prepare_ (PGconn *dbh, const char *name, const char *sql,
112 const char *filename, int line);
116 * Prepare SQL statement.
118 * @param dbh database handle
119 * @param name name for the prepared SQL statement
120 * @param sql SQL code to prepare
121 * @param nparams number of parameters in sql
122 * @return GNUNET_OK on success
124 #define GNUNET_POSTGRES_prepare(dbh,name,sql,nparams) GNUNET_POSTGRES_prepare_(dbh,name,sql,nparams,__FILE__,__LINE__)
128 * Connect to a postgres database
130 * @param cfg configuration
131 * @param section configuration section to use to get Postgres configuration options
132 * @return the postgres handle
135 GNUNET_POSTGRES_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
136 const char *section);
140 * Delete the row identified by the given rowid (qid
143 * @param dbh database handle
144 * @param stmt name of the prepared statement
145 * @param rowid which row to delete
146 * @return GNUNET_OK on success
149 GNUNET_POSTGRES_delete_by_rowid (PGconn *dbh,
155 #if 0 /* keep Emacsens' auto-indent happy */
162 /* end of gnunet_postgres_lib.h */