diff options
author | pixel <pixel> | 2007-06-14 14:12:20 +0000 |
---|---|---|
committer | pixel <pixel> | 2007-06-14 14:12:20 +0000 |
commit | 452e0e4e41e98df8fcf11e07fa8a0725c43142b4 (patch) | |
tree | c1258ed034d012224d3cebb67f52ce0b5c48432d /lib/SQL.cc | |
parent | 3f1e5e1c235d7ba4afa1908313901360c7e7658b (diff) |
Consolidating usage of SQL ressources.
Diffstat (limited to 'lib/SQL.cc')
-rw-r--r-- | lib/SQL.cc | 26 |
1 files changed, 14 insertions, 12 deletions
@@ -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 |