diff options
Diffstat (limited to 'mod_log_sql_pgsql.c')
-rw-r--r-- | mod_log_sql_pgsql.c | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/mod_log_sql_pgsql.c b/mod_log_sql_pgsql.c index 8fb0f9e..7ac4053 100644 --- a/mod_log_sql_pgsql.c +++ b/mod_log_sql_pgsql.c | |||
@@ -8,6 +8,7 @@ | |||
8 | # error Unsupported Apache version | 8 | # error Unsupported Apache version |
9 | #endif | 9 | #endif |
10 | 10 | ||
11 | |||
11 | #ifdef HAVE_CONFIG_H | 12 | #ifdef HAVE_CONFIG_H |
12 | /* Undefine these to prevent conflicts between Apache ap_config_auto.h and | 13 | /* Undefine these to prevent conflicts between Apache ap_config_auto.h and |
13 | * my config.h. Only really needed for Apache < 2.0.48, but it can't hurt. | 14 | * my config.h. Only really needed for Apache < 2.0.48, but it can't hurt. |
@@ -23,6 +24,13 @@ | |||
23 | 24 | ||
24 | #include "mod_log_sql.h" | 25 | #include "mod_log_sql.h" |
25 | 26 | ||
27 | #include "libpq-fe.h" | ||
28 | |||
29 | typedef struct { | ||
30 | PGconn *PG; | ||
31 | char *connectioninfo; | ||
32 | } pg_conn_rec; | ||
33 | |||
26 | /* Connect to the MYSQL database */ | 34 | /* Connect to the MYSQL database */ |
27 | static logsql_opendb_ret log_sql_pgsql_connect(server_rec *s, logsql_dbconnection *db) | 35 | static logsql_opendb_ret log_sql_pgsql_connect(server_rec *s, logsql_dbconnection *db) |
28 | { | 36 | { |
@@ -33,7 +41,7 @@ static logsql_opendb_ret log_sql_pgsql_connect(server_rec *s, logsql_dbconnectio | |||
33 | const char *s_tcpport = apr_table_get(db->parms,"port"); | 41 | const char *s_tcpport = apr_table_get(db->parms,"port"); |
34 | unsigned int tcpport = (s_tcpport)?atoi(s_tcpport):3306; | 42 | unsigned int tcpport = (s_tcpport)?atoi(s_tcpport):3306; |
35 | const char *socketfile = apr_table_get(db->parms,"socketfile"); | 43 | const char *socketfile = apr_table_get(db->parms,"socketfile"); |
36 | MYSQL *dblink = db->handle; | 44 | pg_conn_rec *dblink = db->handle; |
37 | 45 | ||
38 | dblink = mysql_init(dblink); | 46 | dblink = mysql_init(dblink); |
39 | db->handle = (void *)dblink; | 47 | db->handle = (void *)dblink; |
@@ -43,7 +51,7 @@ static logsql_opendb_ret log_sql_pgsql_connect(server_rec *s, logsql_dbconnectio | |||
43 | socketfile = "/var/lib/mysql/mysql.sock"; | 51 | socketfile = "/var/lib/mysql/mysql.sock"; |
44 | } | 52 | } |
45 | 53 | ||
46 | if (mysql_real_connect(dblink, host, user, passwd, database, tcpport, | 54 | if (PQconnectdb(dblink, host, user, passwd, database, tcpport, |
47 | socketfile, 0)) { | 55 | socketfile, 0)) { |
48 | log_error(APLOG_MARK,APLOG_DEBUG,0, s,"HOST: '%s' PORT: '%d' DB: '%s' USER: '%s' SOCKET: '%s'", | 56 | log_error(APLOG_MARK,APLOG_DEBUG,0, s,"HOST: '%s' PORT: '%d' DB: '%s' USER: '%s' SOCKET: '%s'", |
49 | host, tcpport, database, user, socketfile); | 57 | host, tcpport, database, user, socketfile); |
@@ -60,7 +68,7 @@ static logsql_opendb_ret log_sql_pgsql_connect(server_rec *s, logsql_dbconnectio | |||
60 | /* Close the DB link */ | 68 | /* Close the DB link */ |
61 | static void log_sql_pgsql_close(logsql_dbconnection *db) | 69 | static void log_sql_pgsql_close(logsql_dbconnection *db) |
62 | { | 70 | { |
63 | mysql_close((MYSQL *)db->handle); | 71 | PQfinish(((pg_conn_rec *)db->handle)->PG); |
64 | } | 72 | } |
65 | 73 | ||
66 | /* Routine to escape the 'dangerous' characters that would otherwise | 74 | /* Routine to escape the 'dangerous' characters that would otherwise |
@@ -113,7 +121,7 @@ static logsql_query_ret log_sql_pgsql_query(request_rec *r,logsql_dbconnection * | |||
113 | unsigned int real_error = 0; | 121 | unsigned int real_error = 0; |
114 | /*const char *real_error_str = NULL;*/ | 122 | /*const char *real_error_str = NULL;*/ |
115 | 123 | ||
116 | MYSQL *dblink = (MYSQL *)db->handle; | 124 | pg_conn_rec *dblink = db->handle; |
117 | 125 | ||
118 | if (!dblink) { | 126 | if (!dblink) { |
119 | return LOGSQL_QUERY_NOLINK; | 127 | return LOGSQL_QUERY_NOLINK; |
@@ -154,7 +162,7 @@ static logsql_table_ret log_sql_pgsql_create(request_rec *r, logsql_dbconnection | |||
154 | char *create_suffix = NULL; | 162 | char *create_suffix = NULL; |
155 | char *create_sql; | 163 | char *create_sql; |
156 | 164 | ||
157 | MYSQL *dblink = (MYSQL *)db->handle; | 165 | pg_conn_rec *dblink = db->handle; |
158 | 166 | ||
159 | /* if (!global_config.createtables) { | 167 | /* if (!global_config.createtables) { |
160 | return APR_SUCCESS; | 168 | return APR_SUCCESS; |
@@ -230,11 +238,11 @@ static logsql_table_ret log_sql_pgsql_create(request_rec *r, logsql_dbconnection | |||
230 | static char *supported_drivers[] = {"pgsql",NULL}; | 238 | static char *supported_drivers[] = {"pgsql",NULL}; |
231 | static logsql_dbdriver pgsql_driver = { | 239 | static logsql_dbdriver pgsql_driver = { |
232 | supported_drivers, | 240 | supported_drivers, |
233 | log_sql_mysql_connect, /* open DB connection */ | 241 | log_sql_pgsql_connect, /* open DB connection */ |
234 | log_sql_mysql_close, /* close DB connection */ | 242 | log_sql_pgsql_close, /* close DB connection */ |
235 | log_sql_mysql_escape, /* escape query */ | 243 | log_sql_pgsql_escape, /* escape query */ |
236 | log_sql_mysql_query, /* insert query */ | 244 | log_sql_pgsql_query, /* insert query */ |
237 | log_sql_mysql_create /* create table */ | 245 | log_sql_pgsql_create /* create table */ |
238 | }; | 246 | }; |
239 | 247 | ||
240 | LOGSQL_REGISTER(pgsql) { | 248 | LOGSQL_REGISTER(pgsql) { |