diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-03-22 19:01:04 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-03-22 19:01:04 +0000 |
commit | 552bbe0f48ea680af5b862338b7c562e62fdc184 (patch) | |
tree | 2d56507c4cc3564c70ea5b890736e3312ece4225 /src/postgres | |
parent | 4c01d543d10a24b30e279cdb061d9ebe459cdcaf (diff) | |
download | gnunet-552bbe0f48ea680af5b862338b7c562e62fdc184.tar.gz gnunet-552bbe0f48ea680af5b862338b7c562e62fdc184.zip |
-indenting
Diffstat (limited to 'src/postgres')
-rw-r--r-- | src/postgres/postgres.c | 51 |
1 files changed, 23 insertions, 28 deletions
diff --git a/src/postgres/postgres.c b/src/postgres/postgres.c index c6b9a5aa6..40bda2436 100644 --- a/src/postgres/postgres.c +++ b/src/postgres/postgres.c | |||
@@ -35,15 +35,15 @@ | |||
35 | * @param ret return value from database operation to check | 35 | * @param ret return value from database operation to check |
36 | * @param expected_status desired status | 36 | * @param expected_status desired status |
37 | * @param command description of the command that was run | 37 | * @param command description of the command that was run |
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 | */ |
43 | int | 43 | int |
44 | GNUNET_POSTGRES_check_result_ (PGconn *dbh, PGresult * ret, int expected_status, | 44 | GNUNET_POSTGRES_check_result_ (PGconn * dbh, PGresult * ret, |
45 | const char *command, const char *args, const char *filename, | 45 | int expected_status, const char *command, |
46 | int line) | 46 | const char *args, const char *filename, int line) |
47 | { | 47 | { |
48 | if (ret == NULL) | 48 | if (ret == NULL) |
49 | { | 49 | { |
@@ -56,9 +56,8 @@ GNUNET_POSTGRES_check_result_ (PGconn *dbh, PGresult * ret, int expected_status, | |||
56 | if (PQresultStatus (ret) != expected_status) | 56 | if (PQresultStatus (ret) != expected_status) |
57 | { | 57 | { |
58 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 58 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
59 | "postgres", | 59 | "postgres", _("`%s:%s' failed at %s:%d with error: %s"), |
60 | _("`%s:%s' failed at %s:%d with error: %s"), command, args, | 60 | command, args, filename, line, PQerrorMessage (dbh)); |
61 | filename, line, PQerrorMessage (dbh)); | ||
62 | PQclear (ret); | 61 | PQclear (ret); |
63 | return GNUNET_SYSERR; | 62 | return GNUNET_SYSERR; |
64 | } | 63 | } |
@@ -72,19 +71,19 @@ GNUNET_POSTGRES_check_result_ (PGconn *dbh, PGresult * ret, int expected_status, | |||
72 | * @param dbh database handle | 71 | * @param dbh database handle |
73 | * @param sql statement to run | 72 | * @param sql statement to run |
74 | * @param filename filename for error reporting | 73 | * @param filename filename for error reporting |
75 | * @param line code line for error reporting | 74 | * @param line code line for error reporting |
76 | * @return GNUNET_OK on success | 75 | * @return GNUNET_OK on success |
77 | */ | 76 | */ |
78 | int | 77 | int |
79 | GNUNET_POSTGRES_exec_ (PGconn *dbh, const char *sql, | 78 | GNUNET_POSTGRES_exec_ (PGconn * dbh, const char *sql, const char *filename, |
80 | const char *filename, | 79 | int line) |
81 | int line) | ||
82 | { | 80 | { |
83 | PGresult *ret; | 81 | PGresult *ret; |
84 | 82 | ||
85 | ret = PQexec (dbh, sql); | 83 | ret = PQexec (dbh, sql); |
86 | if (GNUNET_OK != | 84 | if (GNUNET_OK != |
87 | GNUNET_POSTGRES_check_result_ (dbh, ret, PGRES_COMMAND_OK, "PQexec", sql, filename, line)) | 85 | GNUNET_POSTGRES_check_result_ (dbh, ret, PGRES_COMMAND_OK, "PQexec", sql, |
86 | filename, line)) | ||
88 | return GNUNET_SYSERR; | 87 | return GNUNET_SYSERR; |
89 | PQclear (ret); | 88 | PQclear (ret); |
90 | return GNUNET_OK; | 89 | return GNUNET_OK; |
@@ -103,14 +102,15 @@ GNUNET_POSTGRES_exec_ (PGconn *dbh, const char *sql, | |||
103 | * @return GNUNET_OK on success | 102 | * @return GNUNET_OK on success |
104 | */ | 103 | */ |
105 | int | 104 | int |
106 | GNUNET_POSTGRES_prepare_ (PGconn *dbh, const char *name, const char *sql, | 105 | GNUNET_POSTGRES_prepare_ (PGconn * dbh, const char *name, const char *sql, |
107 | int nparms, const char *filename, int line) | 106 | int nparms, const char *filename, int line) |
108 | { | 107 | { |
109 | PGresult *ret; | 108 | PGresult *ret; |
110 | 109 | ||
111 | ret = PQprepare (dbh, name, sql, nparms, NULL); | 110 | ret = PQprepare (dbh, name, sql, nparms, NULL); |
112 | if (GNUNET_OK != | 111 | if (GNUNET_OK != |
113 | GNUNET_POSTGRES_check_result_ (dbh, ret, PGRES_COMMAND_OK, "PQprepare", sql, filename, line)) | 112 | GNUNET_POSTGRES_check_result_ (dbh, ret, PGRES_COMMAND_OK, "PQprepare", |
113 | sql, filename, line)) | ||
114 | return GNUNET_SYSERR; | 114 | return GNUNET_SYSERR; |
115 | PQclear (ret); | 115 | PQclear (ret); |
116 | return GNUNET_OK; | 116 | return GNUNET_OK; |
@@ -125,17 +125,15 @@ GNUNET_POSTGRES_prepare_ (PGconn *dbh, const char *name, const char *sql, | |||
125 | * @return the postgres handle | 125 | * @return the postgres handle |
126 | */ | 126 | */ |
127 | PGconn * | 127 | PGconn * |
128 | GNUNET_POSTGRES_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, | 128 | GNUNET_POSTGRES_connect (const struct GNUNET_CONFIGURATION_Handle * cfg, |
129 | const char *section) | 129 | const char *section) |
130 | { | 130 | { |
131 | PGconn *dbh; | 131 | PGconn *dbh; |
132 | char *conninfo; | 132 | char *conninfo; |
133 | 133 | ||
134 | /* Open database and precompile statements */ | 134 | /* Open database and precompile statements */ |
135 | if (GNUNET_OK != | 135 | if (GNUNET_OK != |
136 | GNUNET_CONFIGURATION_get_value_string (cfg, | 136 | GNUNET_CONFIGURATION_get_value_string (cfg, section, "CONFIG", &conninfo)) |
137 | section, "CONFIG", | ||
138 | &conninfo)) | ||
139 | conninfo = NULL; | 137 | conninfo = NULL; |
140 | dbh = PQconnectdb (conninfo == NULL ? "" : conninfo); | 138 | dbh = PQconnectdb (conninfo == NULL ? "" : conninfo); |
141 | GNUNET_free_non_null (conninfo); | 139 | GNUNET_free_non_null (conninfo); |
@@ -166,9 +164,7 @@ GNUNET_POSTGRES_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
166 | * @return GNUNET_OK on success | 164 | * @return GNUNET_OK on success |
167 | */ | 165 | */ |
168 | int | 166 | int |
169 | GNUNET_POSTGRES_delete_by_rowid (PGconn *dbh, | 167 | GNUNET_POSTGRES_delete_by_rowid (PGconn * dbh, const char *stmt, uint32_t rowid) |
170 | const char *stmt, | ||
171 | uint32_t rowid) | ||
172 | { | 168 | { |
173 | uint32_t brow = htonl (rowid); | 169 | uint32_t brow = htonl (rowid); |
174 | const char *paramValues[] = { (const char *) &brow }; | 170 | const char *paramValues[] = { (const char *) &brow }; |
@@ -177,12 +173,11 @@ GNUNET_POSTGRES_delete_by_rowid (PGconn *dbh, | |||
177 | PGresult *ret; | 173 | PGresult *ret; |
178 | 174 | ||
179 | ret = | 175 | ret = |
180 | PQexecPrepared (dbh, stmt, 1, paramValues, paramLengths, | 176 | PQexecPrepared (dbh, stmt, 1, paramValues, paramLengths, paramFormats, 1); |
181 | paramFormats, 1); | ||
182 | if (GNUNET_OK != | 177 | if (GNUNET_OK != |
183 | GNUNET_POSTGRES_check_result_ (dbh, ret, PGRES_COMMAND_OK, "PQexecPrepared", "delrow", | 178 | GNUNET_POSTGRES_check_result_ (dbh, ret, PGRES_COMMAND_OK, |
184 | __FILE__, | 179 | "PQexecPrepared", "delrow", __FILE__, |
185 | __LINE__)) | 180 | __LINE__)) |
186 | { | 181 | { |
187 | return GNUNET_SYSERR; | 182 | return GNUNET_SYSERR; |
188 | } | 183 | } |