diff options
-rw-r--r-- | include/SQL.h | 4 | ||||
-rw-r--r-- | lib/SQL.cc | 26 |
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; @@ -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 |