summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpixel <pixel>2007-06-14 14:12:20 +0000
committerpixel <pixel>2007-06-14 14:12:20 +0000
commit452e0e4e41e98df8fcf11e07fa8a0725c43142b4 (patch)
treec1258ed034d012224d3cebb67f52ce0b5c48432d
parent3f1e5e1c235d7ba4afa1908313901360c7e7658b (diff)
Consolidating usage of SQL ressources.
-rw-r--r--include/SQL.h4
-rw-r--r--lib/SQL.cc26
2 files changed, 16 insertions, 14 deletions
diff --git a/include/SQL.h b/include/SQL.h
index ff1cd7d..786d28f 100644
--- a/include/SQL.h
+++ b/include/SQL.h
@@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-/* $Id: SQL.h,v 1.11 2007-05-30 11:57:08 pixel Exp $ */
+/* $Id: SQL.h,v 1.12 2007-06-14 14:12:20 pixel Exp $ */
#ifndef __SQL_H__
#define __SQL_H__
@@ -42,7 +42,7 @@ class SQLConnection : public Base {
int errno();
String error();
private:
- MYSQL con;
+ MYSQL * con;
MYSQL_RES * res;
int nr, nf, na, ii;
MYSQL_FIELD * fields;
diff --git a/lib/SQL.cc b/lib/SQL.cc
index 484d2e3..5f86380 100644
--- a/lib/SQL.cc
+++ b/lib/SQL.cc
@@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-/* $Id: SQL.cc,v 1.13 2007-05-30 14:02:28 pixel Exp $ */
+/* $Id: SQL.cc,v 1.14 2007-06-14 14:12:20 pixel Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -33,7 +33,7 @@
SQLConnection::SQLConnection(const String & host, const String & user, const String & passwd,
const String & db, int port, const String & socket,
unsigned long cflags) throw (GeneralException) : res(0) {
- mysql_init(&con);
+ con = mysql_init(0);
const char * phost = ((ugly_string) host).p;
const char * puser = ((ugly_string) user).p;
@@ -44,13 +44,13 @@ SQLConnection::SQLConnection(const String & host, const String & user, const Str
phost = *phost ? phost : 0;
psocket = *psocket ? psocket : 0;
- if (!mysql_real_connect(&con, phost, puser, ppasswd, pdb, port, psocket, cflags)) {
+ if (!mysql_real_connect(con, phost, puser, ppasswd, pdb, port, psocket, cflags)) {
throw GeneralException("Could not connect to MySQL host " + host);
}
}
SQLConnection::~SQLConnection() {
- mysql_close(&con);
+ mysql_close(con);
}
int SQLConnection::query(const String & q) {
@@ -62,18 +62,18 @@ int SQLConnection::query(const String & q) {
res = 0;
- if ((r = mysql_real_query(&con, ((ugly_string)q).p, q.strlen()))) {
+ if ((r = mysql_real_query(con, ((ugly_string)q).p, q.strlen()))) {
return r;
}
- res = mysql_store_result(&con);
+ res = mysql_store_result(con);
if (res) {
nr = mysql_num_rows(res);
nf = mysql_num_fields(res);
fields = mysql_fetch_fields(res);
- na = mysql_affected_rows(&con);
- ii = mysql_insert_id(&con);
+ na = mysql_affected_rows(con);
+ ii = mysql_insert_id(con);
} else {
nr = 0;
nf = 0;
@@ -100,8 +100,10 @@ AssocArray SQLConnection::fetchrow() {
row = mysql_fetch_row(res);
- for (i = 0; i < nf; i++) {
- r[fields[i].name] = row[i];
+ if (row) {
+ for (i = 0; i < nf; i++) {
+ r[fields[i].name] = row[i];
+ }
}
return r;
@@ -116,11 +118,11 @@ int SQLConnection::insertid() {
}
int SQLConnection::errno() {
- return mysql_errno(&con);
+ return mysql_errno(con);
}
String SQLConnection::error() {
- return mysql_error(&con);
+ return mysql_error(con);
}
#endif