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"
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, PGresult * ret, int expected_status,
61 const char *command, const char *args,
62 const char *filename, int line);
66 * Check if the result obtained from Postgres has
67 * the desired status code. If not, log an error, clear the
68 * result and return GNUNET_SYSERR.
70 * @param dbh database handle
71 * @param ret return value from database operation to check
72 * @param expected_status desired status
73 * @param command description of the command that was run
74 * @param args arguments given to the command
75 * @return GNUNET_OK if the result is acceptable
77 #define GNUNET_POSTGRES_check_result(dbh,ret,expected_status,command,args) GNUNET_POSTGRES_check_result_(dbh,ret,expected_status,command,args,__FILE__,__LINE__)
81 * Run simple SQL statement (without results).
83 * @param dbh database handle
84 * @param sql statement to run
85 * @param filename filename for error reporting
86 * @param line code line for error reporting
87 * @return GNUNET_OK on success
90 GNUNET_POSTGRES_exec_ (PGconn *dbh, const char *sql, const char *filename, int line);
94 * Run simple SQL statement (without results).
96 * @param dbh database handle
97 * @param sql statement to run
98 * @return GNUNET_OK on success
100 #define GNUNET_POSTGRES_exec(dbh,sql) GNUNET_POSTGRES_exec_(dbh,sql,__FILE__,__LINE__)
104 * Prepare SQL statement.
106 * @param dbh database handle
107 * @param name name for the prepared SQL statement
108 * @param sql SQL code to prepare
109 * @param nparams number of parameters in sql
110 * @param filename filename for error reporting
111 * @param line code line for error reporting
112 * @return GNUNET_OK on success
115 GNUNET_POSTGRES_prepare_ (PGconn *dbh, const char *name, const char *sql,
117 const char *filename, int line);
121 * Prepare SQL statement.
123 * @param dbh database handle
124 * @param name name for the prepared SQL statement
125 * @param sql SQL code to prepare
126 * @param nparams number of parameters in sql
127 * @return GNUNET_OK on success
129 #define GNUNET_POSTGRES_prepare(dbh,name,sql,nparams) GNUNET_POSTGRES_prepare_(dbh,name,sql,nparams,__FILE__,__LINE__)
133 * Connect to a postgres database
135 * @param cfg configuration
136 * @param section configuration section to use to get Postgres configuration options
137 * @return the postgres handle
140 GNUNET_POSTGRES_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
141 const char *section);
145 * Delete the row identified by the given rowid (qid
148 * @param dbh database handle
149 * @param stmt name of the prepared statement
150 * @param rowid which row to delete
151 * @return GNUNET_OK on success
154 GNUNET_POSTGRES_delete_by_rowid (PGconn *dbh,
159 #if 0 /* keep Emacsens' auto-indent happy */
168 /** @} */ /* end of group */