From 4211f7060228d4eab6ec40b50e5a3a6f3cd4b3ca Mon Sep 17 00:00:00 2001 From: arjen Date: Wed, 19 Feb 2003 12:07:55 +0000 Subject: [PATCH] Use the SQL function currval() to obtain the identification number of the most recently created notification. --- src/lib/database.cpp | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/lib/database.cpp b/src/lib/database.cpp index 4377025..22f2883 100644 --- a/src/lib/database.cpp +++ b/src/lib/database.cpp @@ -8,7 +8,7 @@ *********************** ** FILE NAME : database.cpp ** SYSTEM NAME : Gnucomo - Gnu Computer Monitoring -** VERSION NUMBER : $Revision: 1.6 $ +** VERSION NUMBER : $Revision: 1.7 $ ** ** DESCRIPTION : Implementation of the gnucomo database classes ** @@ -26,7 +26,11 @@ /***************************** $Log: database.cpp,v $ - Revision 1.6 2003-02-05 09:33:42 arjen + Revision 1.7 2003-02-19 12:07:55 arjen + Use the SQL function currval() to obtain the identification number + of the most recently created notification. + + Revision 1.6 2003/02/05 09:33:42 arjen gnucomo_database::new_notification() retruns the id number of the newly created notification record. @@ -47,7 +51,7 @@ *****************************/ -static const char *RCSID = "$Id: database.cpp,v 1.6 2003-02-05 09:33:42 arjen Exp $"; +static const char *RCSID = "$Id: database.cpp,v 1.7 2003-02-19 12:07:55 arjen Exp $"; #include @@ -152,17 +156,13 @@ String gnucomo_database::new_notification(String objectid, String issue, String insertion += issueid + "', '" + now.format("%Y-%m-%d %T") + "', 'new', '"; insertion += Field(0, "suggested_priority") + "')"; - qry = "select notificationid from notification where objectid='"; - qry += objectid + "' and type_of_issueid = '"; - qry += issueid + "' order by notificationid"; - Query(insertion); - int tuples = Query(qry); - if (tuples > 0) - { - notif_id = Field(tuples - 1, "notificationid"); + Query("select currval('notification_notificationid_seq')"); + notif_id = Field(0, "currval"); + if (notif_id != "") + { insertion = "insert into action_user (actionid, username, notificationid,"; insertion += " timestamp, statuscode, remarks) values ('1', 'gnucomo', '"; insertion += notif_id + "', '" + now.format("%Y-%m-%d %T") + "', 'new', '"; @@ -175,6 +175,10 @@ String gnucomo_database::new_notification(String objectid, String issue, String std::cerr << "Error inserting notification.\n"; } } + else + { + std::cerr << "DATABASE ERROR: Type of issue " << issue << " not found.\n"; + } return notif_id; } -- 2.11.0