2 This file is part of GNUnet
3 Copyright (C) 2012 GNUnet e.V.
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., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
21 * @author Christian Grothoff
24 * Helper library to access a PostgreSQL database
26 * @defgroup postgres PostgreSQL library
27 * Helper library to access a PostgreSQL database.
30 #ifndef GNUNET_POSTGRES_LIB_H
31 #define GNUNET_POSTGRES_LIB_H
33 #include "gnunet_util_lib.h"
34 #include <postgresql/libpq-fe.h>
39 #if 0 /* keep Emacsens' auto-indent happy */
46 * Check if the result obtained from Postgres has
47 * the desired status code. If not, log an error, clear the
48 * result and return #GNUNET_SYSERR.
50 * @param dbh database handle
51 * @param ret return value from database operation to check
52 * @param expected_status desired status
53 * @param command description of the command that was run
54 * @param args arguments given to the command
55 * @param filename name of the source file where the command was run
56 * @param line line number in the source file
57 * @return #GNUNET_OK if the result is acceptable
60 GNUNET_POSTGRES_check_result_ (PGconn *dbh,
70 * Check if the result obtained from Postgres has
71 * the desired status code. If not, log an error, clear the
72 * result and return #GNUNET_SYSERR.
74 * @param dbh database handle
75 * @param ret return value from database operation to check
76 * @param expected_status desired status
77 * @param command description of the command that was run
78 * @param args arguments given to the command
79 * @return #GNUNET_OK if the result is acceptable
81 #define GNUNET_POSTGRES_check_result(dbh,ret,expected_status,command,args) GNUNET_POSTGRES_check_result_(dbh,ret,expected_status,command,args,__FILE__,__LINE__)
85 * Run simple SQL statement (without results).
87 * @param dbh database handle
88 * @param sql statement to run
89 * @param filename filename for error reporting
90 * @param line code line for error reporting
91 * @return #GNUNET_OK on success
94 GNUNET_POSTGRES_exec_ (PGconn *dbh,
101 * Run simple SQL statement (without results).
103 * @param dbh database handle
104 * @param sql statement to run
105 * @return #GNUNET_OK on success
107 #define GNUNET_POSTGRES_exec(dbh,sql) GNUNET_POSTGRES_exec_(dbh,sql,__FILE__,__LINE__)
111 * Prepare SQL statement.
113 * @param dbh database handle
114 * @param name name for the prepared SQL statement
115 * @param sql SQL code to prepare
116 * @param nparams number of parameters in sql
117 * @param filename filename for error reporting
118 * @param line code line for error reporting
119 * @return #GNUNET_OK on success
122 GNUNET_POSTGRES_prepare_ (PGconn *dbh,
126 const char *filename,
131 * Prepare SQL statement.
133 * @param dbh database handle
134 * @param name name for the prepared SQL statement
135 * @param sql SQL code to prepare
136 * @param nparams number of parameters in sql
137 * @return #GNUNET_OK on success
139 #define GNUNET_POSTGRES_prepare(dbh,name,sql,nparams) GNUNET_POSTGRES_prepare_(dbh,name,sql,nparams,__FILE__,__LINE__)
143 * Connect to a postgres database
145 * @param cfg configuration
146 * @param section configuration section to use to get Postgres configuration options
147 * @return the postgres handle
150 GNUNET_POSTGRES_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
151 const char *section);
155 * Delete the row identified by the given rowid (qid
158 * @param dbh database handle
159 * @param stmt name of the prepared statement
160 * @param rowid which row to delete
161 * @return #GNUNET_OK on success
164 GNUNET_POSTGRES_delete_by_rowid (PGconn *dbh,
169 #if 0 /* keep Emacsens' auto-indent happy */
178 /** @} */ /* end of group */