diff options
Diffstat (limited to 'src/mysql.c')
-rw-r--r-- | src/mysql.c | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/src/mysql.c b/src/mysql.c index 5e8e53a..7abbf2e 100644 --- a/src/mysql.c +++ b/src/mysql.c @@ -1,5 +1,5 @@ /* This file is part of guile-sql. - Copyright (C) 2002,2004 Sergey Poznyakoff + Copyright (C) 2002,2004,2005 Sergey Poznyakoff This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -11,10 +11,9 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - You should have received a copy of the GNU General Public - License along with this program; if not, write to the Free - Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301 USA. */ + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifdef HAVE_CONFIG_H # include <config.h> @@ -50,8 +49,11 @@ s_mysql_connect (char *hostname, int port, char *socket_path = NULL; mysql = mysql_init(NULL); - if (!mysql) - return SCM_BOOL_F; + if (!mysql) + scm_throw(gsql_error, + scm_list_2(scm_makfrom0str("mysql_init() failed"), + scm_makfrom0str(""))); + if (hostname[0] == '/') { socket_path = hostname; hostname = "localhost"; @@ -59,8 +61,10 @@ s_mysql_connect (char *hostname, int port, if (!mysql_real_connect(mysql, hostname, user, pass, dbname, port, socket_path, 0)) { + SCM args = scm_list_2(scm_makfrom0str("Cannot connect to the database"), + scm_makfrom0str(mysql_error(mysql))); mysql_close(mysql); - return SCM_BOOL_F; + scm_throw(gsql_error, args); } smob = sql_connect_create("mysql"); @@ -77,9 +81,8 @@ s_mysql_query(struct sql_connect *conn, char *query) SCM cell; if (mysql_query(mysql, query)) - scm_misc_error("s_mysql_query", - "MySQL error: ~S", - SCM_LIST1(scm_makfrom0str(mysql_error(mysql)))); + scm_throw(gsql_error, scm_list_2(scm_makfrom0str("Error executing MySQL query"), + scm_makfrom0str(mysql_error(mysql)))); result = mysql_store_result(mysql); @@ -127,9 +130,9 @@ s_mysql_query(struct sql_connect *conn, char *query) if (mysql_field_count(mysql) == 0) { cell = scm_makenum(mysql_affected_rows(mysql)); } else { /* mysql_store_result() should have returned data */ - scm_misc_error("s_mysql_query", - "MySQL error: ~S", - SCM_LIST1(scm_makfrom0str(mysql_error(mysql)))); + scm_throw(gsql_error, + scm_list_2("Query should have returned data", + scm_makfrom0str(mysql_error(mysql)))); } } return cell; |