diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2010-03-15 22:07:36 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2010-03-15 22:07:36 +0200 |
commit | 7c6a94930dae634efd8af6db16578d8317153a9a (patch) | |
tree | 2d931e2e4595c88c4f704151dcc2316337d4dfa5 /src/pgsql.c | |
parent | 04b9cd97aa9287668ce41e3db7e273324d3136bc (diff) | |
download | gamma-7c6a94930dae634efd8af6db16578d8317153a9a.tar.gz gamma-7c6a94930dae634efd8af6db16578d8317153a9a.tar.bz2 |
Fix exception generation in (gamma sql)
* src/gsql_conn.c (gsql_error): Rename to gamma_sql_error.
Change Scheme name to sql-error. All callers updated.
* src/guile-sql.h: Likewise.
* src/mysql.c (s_mysql_connect, s_mysql_query): Use
scm_error to generate error exceptions.
* src/pgsql.c (s_pgsql_connect, s_pgsql_query): Likewise.
* src/sql.sci (sql-catch-failure)
(sql-ignore-failure): Update.
* doc/sql.texi: Update.
Diffstat (limited to 'src/pgsql.c')
-rw-r--r-- | src/pgsql.c | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/src/pgsql.c b/src/pgsql.c index 2422551..759795e 100644 --- a/src/pgsql.c +++ b/src/pgsql.c @@ -61,23 +61,26 @@ s_pgsql_connect (SCM parmlist, const char *func_name) gamma_parmlist_parse (parmlist, dcltab, 0, func_name); pgconn = PQsetdbLogin(hostname, port, NULL, NULL, dbname, user, pass); if (PQstatus(pgconn) == CONNECTION_BAD) { - SCM args; + SCM args, pmsg; free(hostname); free(port); free(user); free(pass); - - args = scm_list_2(scm_makfrom0str("Cannot connect to the database"), - scm_makfrom0str(PQerrorMessage(pgconn))); + + pmsg = scm_makfrom0str(PQerrorMessage(pgconn)); + args = scm_list_1(scm_makfrom0str("Cannot connect to the database")); PQfinish(pgconn); - scm_throw(gsql_error, args); + scm_error(gamma_sql_error, func_name, + "~A", + args, + scm_list_2(SCM_BOOL_F, pmsg)); } smob = sql_connect_create("pgsql"); conn = (struct sql_connect *)SCM_CDR(smob); conn->hostname = hostname; conn->port = port ? atoi (port) : 0; @@ -127,14 +130,16 @@ s_pgsql_query(struct sql_connect *conn, const char *query) PGresult *res; SCM cell = SCM_EOL; ExecStatusType stat; res = PQexec(pgconn, query); if (!res) - scm_throw(gsql_error, - scm_list_2(scm_makfrom0str("Error executing PostgreSQL query"), + scm_error(gamma_sql_error, "sql-query", + "~A", + scm_list_1(scm_makfrom0str("Error executing PostgreSQL query")), + scm_list_2(SCM_BOOL_F, scm_makfrom0str(PQerrorMessage(pgconn)))); stat = PQresultStatus(res); switch (stat) { case PGRES_COMMAND_OK: @@ -144,14 +149,17 @@ s_pgsql_query(struct sql_connect *conn, const char *query) case PGRES_TUPLES_OK: /* The query successfully executed */ cell = result_to_list(res); PQclear(res); break; default: - scm_throw(gsql_error, scm_list_2(scm_makfrom0str("PostgreSQL error"), - scm_makfrom0str(PQresStatus(stat)))); + scm_error(gamma_sql_error, "sql-query", + "~A", + scm_list_1(scm_makfrom0str("PostgreSQL error")), + scm_list_2(scm_from_uint(stat), + scm_from_locale_string(PQresStatus(stat)))); } return cell; } static void |