/*------------------------------------------------------------------------- * Copyright (c) 1999-2001 Kenneth W. Sodemann (stufflehead@bigfoot.com) *------------------------------------------------------------------------- * error_chks * * Synopsis: * Error checking, and msg displaying routines. * * $Id: error_chks.c,v 1.12 2002/12/11 01:52:20 stuffle Exp $ * * 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 * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * 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 * Free Software Foundation, Inc. * 59 Temple Place, Suite 330 * Boston, MA 02111-1307 USA * *------------------------------------------------------------------------- */ #ifdef HAVE_CONFIG_H # include #endif #include #include #include "db_utils.h" #include "error_chks.h" gboolean sql_result_ok (PGresult *res) { ExecStatusType db_status; db_status = PQresultStatus (res); return (db_status == PGRES_TUPLES_OK || PGRES_COMMAND_OK); } gboolean chk_sql_error (PGresult *res, const char *descr_text) { ExecStatusType db_status; GString *msg; GtkWidget *msg_dlg; db_status = PQresultStatus (res); if (db_status != PGRES_TUPLES_OK && db_status != PGRES_COMMAND_OK) { msg = g_string_new (db_stat_string (db_status)); msg = g_string_append_c (msg, '\n'); msg = g_string_append (msg, descr_text); msg = g_string_append_c (msg, '\n'); msg = g_string_append (msg, PQresultErrorMessage (res)); msg_dlg = gtk_message_dialog_new (NULL, 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, msg->str); gtk_dialog_run (GTK_DIALOG (msg_dlg)); gtk_widget_destroy (msg_dlg); syslog (LOG_ERR, _("Error in SQL Execution: %s"), PQresultErrorMessage (res)); return FALSE; } return TRUE; }