aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2005-06-26 10:38:26 +0000
committerSergey Poznyakoff <gray@gnu.org.ua>2005-06-26 10:38:26 +0000
commit4987cf3134f116d1881602141ccc5ee7d572b8de (patch)
treea86f7135fd97098f6d98aeeabe0799e20615d91c
parentd47c213bb55adbe961c54242c642c2d1b7c3ec6c (diff)
downloadgamma-4987cf3134f116d1881602141ccc5ee7d572b8de.tar.gz
gamma-4987cf3134f116d1881602141ccc5ee7d572b8de.tar.bz2
Throw gsql-error, instead of misc-error, on failure
-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
@@ -2,2 +2,5 @@
+ * 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,
diff --git a/src/app.h b/src/app.h
index b343691..56100c5 100644
--- a/src/app.h
+++ b/src/app.h
@@ -13,6 +13,5 @@
- 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. */
diff --git a/src/gettext.c b/src/gettext.c
index e749485..9dcaf1c 100644
--- a/src/gettext.c
+++ b/src/gettext.c
@@ -13,6 +13,5 @@
- 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. */
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,3 +1,3 @@
/* This file is part of guile-sql.
- Copyright (C) 2002 Sergey Poznyakoff
+ Copyright (C) 2002, 2005 Sergey Poznyakoff
@@ -27,2 +27,5 @@ struct sql_iface sql_iftab[MAX_IFACES];
+SCM_GLOBAL_SYMBOL (gsql_error, "gsql-error");
+
+
long sql_connect_tag;
@@ -122,3 +125,4 @@ SCM_DEFINE (sql_connect, "sql-connect", 5, 1, 0,
int iface;
-
+ struct sql_connect *conn;
+
if (SCM_IMP(IFACE) && SCM_INUMP(IFACE))
@@ -159,9 +163,9 @@ SCM_DEFINE (sql_connect, "sql-connect", 5, 1, 0,
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;
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
@@ -13,6 +13,5 @@
- 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. */
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
@@ -13,6 +13,5 @@
- 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. */
@@ -51,2 +50,3 @@ struct sql_iface {
extern struct sql_iface sql_iftab[];
+extern SCM gsql_error;
diff --git a/src/mysql.c b/src/mysql.c
index 5e8e53a..7abbf2e 100644
--- a/src/mysql.c
+++ b/src/mysql.c
@@ -1,3 +1,3 @@
/* This file is part of guile-sql.
- Copyright (C) 2002,2004 Sergey Poznyakoff
+ Copyright (C) 2002,2004,2005 Sergey Poznyakoff
@@ -13,6 +13,5 @@
- 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. */
@@ -52,4 +51,7 @@ s_mysql_connect (char *hostname, int port,
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] == '/') {
@@ -61,4 +63,6 @@ s_mysql_connect (char *hostname, int port,
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);
}
@@ -79,5 +83,4 @@ s_mysql_query(struct sql_connect *conn, char *query)
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))));
@@ -129,5 +132,5 @@ s_mysql_query(struct sql_connect *conn, char *query)
} 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))));
}
diff --git a/src/pgsql.c b/src/pgsql.c
index 8c7699b..44b1fa6 100644
--- a/src/pgsql.c
+++ b/src/pgsql.c
@@ -13,6 +13,5 @@
- 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. */
@@ -52,4 +51,8 @@ s_pgsql_connect (char *hostname, int 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);
+ }
@@ -111,6 +114,6 @@ s_pgsql_query(struct sql_connect *conn, char *query)
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))));
@@ -129,5 +132,4 @@ s_pgsql_query(struct sql_connect *conn, char *query)
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 to:

Send suggestions and report system problems to the System administrator.