#ifndef __ATTRIB_DLG_DB_H #define __ATTRIB_DLG_DB_H /*------------------------------------------------------------------------- * Copyright (c) 1999-2004 Kenneth W. Sodemann (stuffle@mac.com) *------------------------------------------------------------------------- * attrib_dlg_db * * Synopsis: * Routines used to interface the database from the attributes * dialog. * * $Id: attrib_dlg_db.h,v 1.11 2004/11/25 23:44:07 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 * *------------------------------------------------------------------------- */ #include #include /*------------------------------------------------------------------------- * General Information: * o The functions in this module generally fall into two different * classes: generic "get" functions, and attribute specific functions. * * o The generic "get" functions take a pointer to the result set and * the tuple number to return the data for. It is expected that the * result set would have been generated by one of the attribute * specific "read" functions. * * o The attribute specific functions include: * o "create" functions used to create new instances of the * attributes in the database * o "read" functions to read the attribute data * o "delete" functions to delete specific instances of the * attributes * o "set" functions to set specific properties of specific * instances of the attributes * * o If a function returns a pointer to the result set (PGresult *), it * is the user's responsibility to call PQclear (res) when * the results of the query are no longer needed. *------------------------------------------------------------------------ */ /*------------------------------------------------------------------------- * Function: read_xxx_data * * Synopsis: * Read the attribute type data from the database. * * Inputs: * no_inactive (boolean) : TRUE if inactive attributes should be * suppressed in the output * conn (PGconn *) : A pointer to the database connection. * * Outputs: * Loads up static local data for output be other methods. * * Return Value: * Returns a pointer to the result set. * *------------------------------------------------------------------------- */ PGresult *read_sevr_data (PGconn *conn, gboolean no_inactive); PGresult *read_stat_data (PGconn *conn, gboolean no_inactive); PGresult *read_type_data (PGconn *conn, gboolean no_inactive); /*------------------------------------------------------------------------- * Function: delete_xxxx * * Synopsis: * Delete the attribute. * * Inputs: * conn : pointer to the database connection * pk_num : the PK number of the item to delete * * Outputs: * None. * * Return Value: * Returns TRUE if the operation succeeded, FALSE otherwise. *------------------------------------------------------------------------- */ gboolean delete_severity (PGconn *conn, gint pk_num); gboolean delete_status (PGconn *conn, gint pk_num); gboolean delete_type (PGconn *conn, gint pk_num); /*------------------------------------------------------------------------- * Function: create_xxxx * * Synopsis: * Create the given attribute in the database * * Inputs: * conn : pointer to the database connection * name : name for the attribute * descr : descr for the attribute * sevr : severity_num for default severity (problem_type attribute * only) * closed : flag indicating if status is to be considered "closed" * (status attribute only) * * Outputs: * pk_num : returns the primary key of the newly created attribute * * Return Value: * Returns TRUE if the operation succeeded, FALSE otherwise. *------------------------------------------------------------------------- */ gboolean create_severity (PGconn *conn, const gchar *name, const gchar *descr, gint *pk_num); gboolean create_status (PGconn *conn, const gchar *name, const gchar *descr, gboolean closed, gint *pk_num); gboolean create_type (PGconn *conn, const gchar *name, const gchar *descr, gint sevr, gint *pk_num); /*------------------------------------------------------------------------- * Function: set_xxxx_yyyy * * Synopsis: * Updates attributes in the database (which one should be obvious * from name of function...) * * Inputs: * conn : pointer to the database connection * pk_num : primary key of the attribute to update * value : the value * * Outputs: * None. * * Return Value: * Returns TRUE if the operation succeeded, FALSE otherwise. *------------------------------------------------------------------------- */ gboolean set_severity_active (PGconn *conn, gint pk_num, gboolean value); gboolean set_severity_order (PGconn *conn, gint pk_num, gint value); gboolean set_severity_name (PGconn *conn, gint pk_num, const gchar *value); gboolean set_severity_descr (PGconn *conn, gint pk_num, const gchar *value); gboolean set_status_active (PGconn *conn, gint pk_num, gboolean value); gboolean set_status_closed (PGconn *conn, gint pk_num, gboolean value); gboolean set_status_order (PGconn *conn, gint pk_num, gint value); gboolean set_status_name (PGconn *conn, gint pk_num, const gchar *value); gboolean set_status_descr (PGconn *conn, gint pk_num, const gchar *value); gboolean set_type_active (PGconn *conn, gint pk_num, gboolean value); gboolean set_type_sevr (PGconn *conn, gint pk_num, gint value); gboolean set_type_order (PGconn *conn, gint pk_num, gint value); gboolean set_type_name (PGconn *conn, gint pk_num, const gchar *value); gboolean set_type_descr (PGconn *conn, gint pk_num, const gchar *value); /*------------------------------------------------------------------------- * Function: get_severity_pk * * Synopsis: * Given a severity name, lookup the primary key. * * Inputs: * conn : pointer to the database connection * sevr_name: the severity name * * Outputs: * None. * * Return Value: * The pk of the severity with name sevr_name, or -1 if none. * *------------------------------------------------------------------------- */ gint get_severity_pk (PGconn *conn, const gchar *sevr_name); /*------------------------------------------------------------------------- * Function: get_pk_num * * Synopsis: * Get the pk number for the nth record of the given result set. * * Inputs: * res : pointer to the result set. * n (int) : Index to the tuple to get (first tuple is 0). * * Outputs: * None. * * Return Value: * The pk number of the nth tuple. * *------------------------------------------------------------------------- */ gint get_pk_num (PGresult *res, gint n); /*------------------------------------------------------------------------- * Function: get_name * * Synopsis: * Get the name for the nth tuple of the given result set. * * Inputs: * res : the result set. * n (int) : Index to the tuple to get (first tuple is 0). * * Outputs: * None. * * Return Value: * The name for the nth tuple, or an empty string if there is * no nth tuple. * *------------------------------------------------------------------------- */ const char *get_name (PGresult *res, gint n); /*------------------------------------------------------------------------- * Function: get_rank * * Synopsis: * Get the rank for the given tuple. * * Inputs: * res : pointer to the result set. * n (int) : Index to the tuple to get (first tuple is 0). * * Outputs: * None. * * Return Value: * The rank for the nth tuple, or an empty string if there is * no nth tuple. * *------------------------------------------------------------------------- */ const char *get_rank (PGresult *res, gint n); /*------------------------------------------------------------------------- * Function: get_active_yn * * Synopsis: * Get the active flag for the given tuple. * * Inputs: * res : pointer to the result set. * n (int) : Index to the tuple to get (first tuple is 0). * * Outputs: * None. * * Return Value: * "Yes" if the severity is active, no if it is not, or an empty * string if there is no nth tuple. * *------------------------------------------------------------------------- */ gboolean get_active (PGresult *res, gint n); const char *get_active_yn (PGresult *res, gint n); /*------------------------------------------------------------------------- * Function: get_descr * * Synopsis: * Get the descrption for the given tuple. * * Inputs: * res : pointer to the result set. * n (int) : Index to the tuple to get (first tuple is 0). * * Outputs: * None. * * Return Value: * The descr for the nth tuple, or an empty string if there is * no nth tuple. * *------------------------------------------------------------------------- */ const char *get_descr (PGresult *res, gint n); /*------------------------------------------------------------------------- * Function: get_type_def_sevr * * Synopsis: * Get the name of the default severity for the given tuple. * This is only valid for results coming from a read of the * "type" data. * * Inputs: * res : pointer to the result set. * n (int) : Index to the tuple to get (first tuple is 0). * * Outputs: * None. * * Return Value: * The default severity for the nth tuple, or an empty string if * there is no nth tuple. * *------------------------------------------------------------------------- */ const char *get_def_sevr (PGresult *res, gint n); gboolean get_closed_status (PGresult *res, gint n); #endif