summaryrefslogtreecommitdiffstats
path: root/utility/database.c
diff options
context:
space:
mode:
Diffstat (limited to 'utility/database.c')
-rw-r--r--utility/database.c36
1 files changed, 29 insertions, 7 deletions
diff --git a/utility/database.c b/utility/database.c
index c4e4bc9..0d1d4f7 100644
--- a/utility/database.c
+++ b/utility/database.c
@@ -4,7 +4,7 @@
4#include "apr_strings.h" 4#include "apr_strings.h"
5 5
6#include "util.h" 6#include "util.h"
7#include "mysql/mysql.h" 7#include "autoconfig.h"
8 8
9struct config_dbd_t { 9struct config_dbd_t {
10 const apr_dbd_driver_t *driver; 10 const apr_dbd_driver_t *driver;
@@ -30,7 +30,7 @@ apr_status_t database_connect(config_t *cfg)
30 if (rv) { 30 if (rv) {
31 31
32 logging_log(cfg, LOGLEVEL_ERROR, 32 logging_log(cfg, LOGLEVEL_ERROR,
33 "Could not load database driver %s. Error %s", cfg->dbdriver, 33 "DB: Could not load database driver %s. Error %s", cfg->dbdriver,
34 logging_strerror(rv)); 34 logging_strerror(rv));
35 return rv; 35 return rv;
36 } 36 }
@@ -39,7 +39,7 @@ apr_status_t database_connect(config_t *cfg)
39 &(cfg->dbconn->dbd)); 39 &(cfg->dbconn->dbd));
40 if (rv) { 40 if (rv) {
41 logging_log(cfg, LOGLEVEL_ERROR, 41 logging_log(cfg, LOGLEVEL_ERROR,
42 "Could not connect to database. Error %s", logging_strerror(rv)); 42 "DB: Could not connect to database. Error %s", logging_strerror(rv));
43 return rv; 43 return rv;
44 } 44 }
45 45
@@ -89,13 +89,13 @@ static apr_dbd_prepared_t *database_prepare_insert(config_t *cfg, apr_pool_t *p)
89 89
90 sql = apr_pstrcatv(p, vec, i+2, NULL); 90 sql = apr_pstrcatv(p, vec, i+2, NULL);
91 91
92 logging_log(cfg, LOGLEVEL_DEBUG, "Generated SQL: %s", sql); 92 logging_log(cfg, LOGLEVEL_DEBUG, "DB: Generated SQL: %s", sql);
93 93
94 rv = apr_dbd_prepare(cfg->dbconn->driver, cfg->pool, cfg->dbconn->dbd, sql, 94 rv = apr_dbd_prepare(cfg->dbconn->driver, cfg->pool, cfg->dbconn->dbd, sql,
95 "INSERT", &stmt); 95 "INSERT", &stmt);
96 96
97 if (rv) { 97 if (rv) {
98 logging_log(cfg, LOGLEVEL_ERROR, "Unable to Prepare SQL insert: %s", 98 logging_log(cfg, LOGLEVEL_NOISE, "DB: Unable to Prepare SQL insert: %s",
99 apr_dbd_error(cfg->dbconn->driver, cfg->dbconn->dbd, rv)); 99 apr_dbd_error(cfg->dbconn->driver, cfg->dbconn->dbd, rv));
100 return NULL; 100 return NULL;
101 } 101 }
@@ -112,7 +112,6 @@ apr_status_t database_insert(config_t *cfg, apr_pool_t *p, apr_table_t *data)
112 if (!cfg->dbconn->stmt) { 112 if (!cfg->dbconn->stmt) {
113 cfg->dbconn->stmt = database_prepare_insert(cfg, p); 113 cfg->dbconn->stmt = database_prepare_insert(cfg, p);
114 if (!cfg->dbconn->stmt) { 114 if (!cfg->dbconn->stmt) {
115 logging_log(cfg, LOGLEVEL_NOISE, "Unable to prepare SQL statement");
116 return APR_EINVAL; 115 return APR_EINVAL;
117 } 116 }
118 cfg->dbconn->args = apr_palloc(cfg->pool, nfs * sizeof(char *)); 117 cfg->dbconn->args = apr_palloc(cfg->pool, nfs * sizeof(char *));
@@ -123,7 +122,7 @@ apr_status_t database_insert(config_t *cfg, apr_pool_t *p, apr_table_t *data)
123 rv = apr_dbd_pquery(cfg->dbconn->driver, p, cfg->dbconn->dbd, &f, 122 rv = apr_dbd_pquery(cfg->dbconn->driver, p, cfg->dbconn->dbd, &f,
124 cfg->dbconn->stmt, nfs, cfg->dbconn->args); 123 cfg->dbconn->stmt, nfs, cfg->dbconn->args);
125 if (rv) { 124 if (rv) {
126 logging_log(cfg, LOGLEVEL_ERROR, "Unable to Insert SQL: %s", 125 logging_log(cfg, LOGLEVEL_ERROR, "DB: Unable to Insert SQL: %s",
127 apr_dbd_error(cfg->dbconn->driver, cfg->dbconn->dbd, rv)); 126 apr_dbd_error(cfg->dbconn->driver, cfg->dbconn->dbd, rv));
128 return rv; 127 return rv;
129 } 128 }
@@ -131,3 +130,26 @@ apr_status_t database_insert(config_t *cfg, apr_pool_t *p, apr_table_t *data)
131} 130}
132 131
133/** @todo implement transactions */ 132/** @todo implement transactions */
133apr_status_t database_trans_start(config_t *cfg, apr_pool_t *p)
134{
135#if HAVE_APR_DBD_TRANSACTION_MODE_GET
136#else
137 return APR_SUCCESS;
138#endif
139}
140
141apr_status_t database_trans_stop(config_t *cfg, apr_pool_t *p)
142{
143#if HAVE_APR_DBD_TRANSACTION_MODE_GET
144#else
145 return APR_SUCCESS;
146#endif
147}
148
149apr_status_t database_trans_abort(config_t *cfg)
150{
151#if HAVE_APR_DBD_TRANSACTION_MODE_GET
152#else
153 return APR_SUCCESS;
154#endif
155}