summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org.ua>2005-06-26 10:38:26 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2005-06-26 10:38:26 (GMT)
commit4987cf3134f116d1881602141ccc5ee7d572b8de (patch) (side-by-side diff)
treea86f7135fd97098f6d98aeeabe0799e20615d91c
parentd47c213bb55adbe961c54242c642c2d1b7c3ec6c (diff)
downloadgamma-4987cf3134f116d1881602141ccc5ee7d572b8de.tar.gz
gamma-4987cf3134f116d1881602141ccc5ee7d572b8de.tar.bz2
Throw gsql-error, instead of misc-error, on failure
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--ChangeLog3
-rw-r--r--src/app.h7
-rw-r--r--src/gettext.c7
-rw-r--r--src/gsql_conn.c22
-rw-r--r--src/gsql_lib.c7
-rw-r--r--src/guile-sql.h8
-rw-r--r--src/mysql.c31
-rw-r--r--src/pgsql.c28
8 files changed, 61 insertions, 52 deletions
diff --git a/ChangeLog b/ChangeLog
index b18f019..1f1c162 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
2005-06-26 Sergey Poznyakoff <gray@Noldor.runasimi.org>
+ * src/app.h, src/gettext.c, src/gsql_conn.c, src/gsql_lib.c,
+ src/guile-sql.h, src/mysql.c, src/pgsql.c: Throw gsql-error,
+ instead of misc-error, on failure.
* COPYING, configure.ac, examples/whoisd.scm, m4/guile.m4,
scripts/guile-doc-snarf, scripts/guile-doc-snarf.awk, src/app.h,
src/gettext.c, src/gettext.h, src/gettext.sci, src/gsql_conn.c,
diff --git a/src/app.h b/src/app.h
index b343691..56100c5 100644
--- a/src/app.h
+++ b/src/app.h
@@ -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 USE_SQL_MYSQL
extern struct sql_iface mysql_iface;
diff --git a/src/gettext.c b/src/gettext.c
index e749485..9dcaf1c 100644
--- a/src/gettext.c
+++ b/src/gettext.c
@@ -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>
diff --git a/src/gsql_conn.c b/src/gsql_conn.c
index 77fc60e..4a48de7 100644
--- a/src/gsql_conn.c
+++ b/src/gsql_conn.c
@@ -1,5 +1,5 @@
/* This file is part of guile-sql.
- Copyright (C) 2002 Sergey Poznyakoff
+ Copyright (C) 2002, 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
@@ -25,6 +25,9 @@
int num_iface;
struct sql_iface sql_iftab[MAX_IFACES];
+SCM_GLOBAL_SYMBOL (gsql_error, "gsql-error");
+
+
long sql_connect_tag;
/* SMOB functions: */
@@ -120,7 +123,8 @@ SCM_DEFINE (sql_connect, "sql-connect", 5, 1, 0,
char *user;
char *pass;
int iface;
-
+ struct sql_connect *conn;
+
if (SCM_IMP(IFACE) && SCM_INUMP(IFACE))
iface = SCM_INUM(IFACE);
else if (SCM_STRINGP(IFACE))
@@ -157,13 +161,13 @@ SCM_DEFINE (sql_connect, "sql-connect", 5, 1, 0,
smob = sql_iftab[iface].connect(hostname, port,
dbname, user, pass,
FUNC_NAME);
- if (smob != SCM_BOOL_F) {
- struct sql_connect *conn = (struct sql_connect *)SCM_CDR(smob);
- conn->hostname = strdup(hostname);
- conn->port = port;
- conn->username = strdup(user);
- conn->database = strdup(dbname);
- }
+
+ conn = (struct sql_connect *)SCM_CDR(smob);
+ conn->hostname = strdup(hostname);
+ conn->port = port;
+ conn->username = strdup(user);
+ conn->database = strdup(dbname);
+
return smob;
}
#undef FUNC_NAME
diff --git a/src/gsql_lib.c b/src/gsql_lib.c
index 5f25195..c988b2e 100644
--- a/src/gsql_lib.c
+++ b/src/gsql_lib.c
@@ -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>
diff --git a/src/guile-sql.h b/src/guile-sql.h
index 3de3f26..5203123 100644
--- a/src/guile-sql.h
+++ b/src/guile-sql.h
@@ -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. */
#include <sys/socket.h>
#include <netinet/in.h>
@@ -49,6 +48,7 @@ struct sql_iface {
};
extern struct sql_iface sql_iftab[];
+extern SCM gsql_error;
SCM sql_connect_create (char *name);
SCM scm_makenum (unsigned long val);
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;
diff --git a/src/pgsql.c b/src/pgsql.c
index 8c7699b..44b1fa6 100644
--- a/src/pgsql.c
+++ b/src/pgsql.c
@@ -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,12 @@ s_pgsql_connect (char *hostname, int port,
snprintf(buf, sizeof buf, "%d", port);
pgconn = PQsetdbLogin(hostname, buf, NULL, NULL, dbname, user, pass);
- if (PQstatus(pgconn) == CONNECTION_BAD)
- return SCM_BOOL_F;
+ if (PQstatus(pgconn) == CONNECTION_BAD) {
+ SCM args = scm_list_2(scm_makfrom0str("Cannot connect to the database"),
+ scm_makfrom0str(PQerrorMessage(pgconn)));
+ PQfinish(pgconn);
+ scm_throw(gsql_error, args);
+ }
smob = sql_connect_create("pgsql");
conn = (struct sql_connect *)SCM_CDR(smob);
@@ -109,10 +112,10 @@ s_pgsql_query(struct sql_connect *conn, char *query)
ExecStatusType stat;
res = PQexec(pgconn, query);
- if (!res)
- scm_misc_error("s_mgsql_query",
- "pgSQL error: ~S",
- SCM_LIST1(scm_makfrom0str(PQerrorMessage(pgconn))));
+ if (!res)
+ scm_throw(gsql_error,
+ scm_list_2(scm_makfrom0str("Error executing PostgreSQL query"),
+ scm_makfrom0str(PQerrorMessage(pgconn))));
stat = PQresultStatus(res);
@@ -127,9 +130,8 @@ s_pgsql_query(struct sql_connect *conn, char *query)
PQclear(res);
break;
default:
- scm_misc_error("s_mgsql_query",
- "pgSQL error: ~S",
- SCM_LIST1(scm_makfrom0str(PQresStatus(stat))));
+ scm_throw(gsql_error, scm_list_2(scm_makfrom0str("PostgreSQL error"),
+ scm_makfrom0str(PQresStatus(stat))));
}
return cell;

Return to:

Send suggestions and report system problems to the System administrator.