aboutsummaryrefslogtreecommitdiff
path: root/src/postgres/postgres.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/postgres/postgres.c')
-rw-r--r--src/postgres/postgres.c61
1 files changed, 44 insertions, 17 deletions
diff --git a/src/postgres/postgres.c b/src/postgres/postgres.c
index c03e312a5..856031d75 100644
--- a/src/postgres/postgres.c
+++ b/src/postgres/postgres.c
@@ -38,12 +38,16 @@
38 * @param args arguments given to the command 38 * @param args arguments given to the command
39 * @param filename name of the source file where the command was run 39 * @param filename name of the source file where the command was run
40 * @param line line number in the source file 40 * @param line line number in the source file
41 * @return GNUNET_OK if the result is acceptable 41 * @return #GNUNET_OK if the result is acceptable
42 */ 42 */
43int 43int
44GNUNET_POSTGRES_check_result_ (PGconn * dbh, PGresult * ret, 44GNUNET_POSTGRES_check_result_ (PGconn *dbh,
45 int expected_status, const char *command, 45 PGresult *ret,
46 const char *args, const char *filename, int line) 46 int expected_status,
47 const char *command,
48 const char *args,
49 const char *filename,
50 int line)
47{ 51{
48 if (ret == NULL) 52 if (ret == NULL)
49 { 53 {
@@ -72,10 +76,12 @@ GNUNET_POSTGRES_check_result_ (PGconn * dbh, PGresult * ret,
72 * @param sql statement to run 76 * @param sql statement to run
73 * @param filename filename for error reporting 77 * @param filename filename for error reporting
74 * @param line code line for error reporting 78 * @param line code line for error reporting
75 * @return GNUNET_OK on success 79 * @return #GNUNET_OK on success
76 */ 80 */
77int 81int
78GNUNET_POSTGRES_exec_ (PGconn * dbh, const char *sql, const char *filename, 82GNUNET_POSTGRES_exec_ (PGconn * dbh,
83 const char *sql,
84 const char *filename,
79 int line) 85 int line)
80{ 86{
81 PGresult *ret; 87 PGresult *ret;
@@ -99,18 +105,30 @@ GNUNET_POSTGRES_exec_ (PGconn * dbh, const char *sql, const char *filename,
99 * @param nparams number of parameters in sql 105 * @param nparams number of parameters in sql
100 * @param filename filename for error reporting 106 * @param filename filename for error reporting
101 * @param line code line for error reporting 107 * @param line code line for error reporting
102 * @return GNUNET_OK on success 108 * @return #GNUNET_OK on success
103 */ 109 */
104int 110int
105GNUNET_POSTGRES_prepare_ (PGconn * dbh, const char *name, const char *sql, 111GNUNET_POSTGRES_prepare_ (PGconn *dbh,
106 int nparams, const char *filename, int line) 112 const char *name,
113 const char *sql,
114 int nparams,
115 const char *filename,
116 int line)
107{ 117{
108 PGresult *ret; 118 PGresult *ret;
109 119
110 ret = PQprepare (dbh, name, sql, nparams, NULL); 120 ret = PQprepare (dbh,
121 name,
122 sql,
123 nparams, NULL);
111 if (GNUNET_OK != 124 if (GNUNET_OK !=
112 GNUNET_POSTGRES_check_result_ (dbh, ret, PGRES_COMMAND_OK, "PQprepare", 125 GNUNET_POSTGRES_check_result_ (dbh,
113 sql, filename, line)) 126 ret,
127 PGRES_COMMAND_OK,
128 "PQprepare",
129 sql,
130 filename,
131 line))
114 return GNUNET_SYSERR; 132 return GNUNET_SYSERR;
115 PQclear (ret); 133 PQclear (ret);
116 return GNUNET_OK; 134 return GNUNET_OK;
@@ -161,10 +179,12 @@ GNUNET_POSTGRES_connect (const struct GNUNET_CONFIGURATION_Handle * cfg,
161 * @param dbh database handle 179 * @param dbh database handle
162 * @param stmt name of the prepared statement 180 * @param stmt name of the prepared statement
163 * @param rowid which row to delete 181 * @param rowid which row to delete
164 * @return GNUNET_OK on success 182 * @return #GNUNET_OK on success
165 */ 183 */
166int 184int
167GNUNET_POSTGRES_delete_by_rowid (PGconn * dbh, const char *stmt, uint32_t rowid) 185GNUNET_POSTGRES_delete_by_rowid (PGconn * dbh,
186 const char *stmt,
187 uint32_t rowid)
168{ 188{
169 uint32_t brow = htonl (rowid); 189 uint32_t brow = htonl (rowid);
170 const char *paramValues[] = { (const char *) &brow }; 190 const char *paramValues[] = { (const char *) &brow };
@@ -173,10 +193,17 @@ GNUNET_POSTGRES_delete_by_rowid (PGconn * dbh, const char *stmt, uint32_t rowid)
173 PGresult *ret; 193 PGresult *ret;
174 194
175 ret = 195 ret =
176 PQexecPrepared (dbh, stmt, 1, paramValues, paramLengths, paramFormats, 1); 196 PQexecPrepared (dbh, stmt, 1,
197 paramValues,
198 paramLengths,
199 paramFormats,
200 1);
177 if (GNUNET_OK != 201 if (GNUNET_OK !=
178 GNUNET_POSTGRES_check_result_ (dbh, ret, PGRES_COMMAND_OK, 202 GNUNET_POSTGRES_check_result_ (dbh, ret,
179 "PQexecPrepared", "delrow", __FILE__, 203 PGRES_COMMAND_OK,
204 "PQexecPrepared",
205 "delrow",
206 __FILE__,
180 __LINE__)) 207 __LINE__))
181 { 208 {
182 return GNUNET_SYSERR; 209 return GNUNET_SYSERR;