diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2005-06-26 10:38:26 +0000 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2005-06-26 10:38:26 +0000 |
commit | 4987cf3134f116d1881602141ccc5ee7d572b8de (patch) | |
tree | a86f7135fd97098f6d98aeeabe0799e20615d91c /src/pgsql.c | |
parent | d47c213bb55adbe961c54242c642c2d1b7c3ec6c (diff) | |
download | gamma-4987cf3134f116d1881602141ccc5ee7d572b8de.tar.gz gamma-4987cf3134f116d1881602141ccc5ee7d572b8de.tar.bz2 |
Throw gsql-error, instead of misc-error, on failure
Diffstat (limited to 'src/pgsql.c')
-rw-r--r-- | src/pgsql.c | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/src/pgsql.c b/src/pgsql.c index 8c7699b..44b1fa6 100644 --- a/src/pgsql.c +++ b/src/pgsql.c @@ -8,16 +8,15 @@ This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 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> #endif #include <string.h> #include <guile-sql.h> @@ -47,14 +46,18 @@ s_pgsql_connect (char *hostname, int port, char buf[24]; SCM smob; struct sql_connect *conn; 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); conn->data = pgconn; return smob; } @@ -106,16 +109,16 @@ s_pgsql_query(struct sql_connect *conn, char *query) PGconn *pgconn = (PGconn*) conn->data; PGresult *res; SCM cell; 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); switch (stat) { case PGRES_COMMAND_OK: /* Successful completion of a command returning no data */ @@ -124,15 +127,14 @@ s_pgsql_query(struct sql_connect *conn, char *query) case PGRES_TUPLES_OK: /* The query successfully executed */ cell = result_to_list(res); 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; } void |