Use the SQL function currval() to obtain the identification number
authorarjen <arjen>
Wed, 19 Feb 2003 12:07:55 +0000 (12:07 +0000)
committerarjen <arjen>
Wed, 19 Feb 2003 12:07:55 +0000 (12:07 +0000)
of the most recently created notification.

src/lib/database.cpp

index 4377025..22f2883 100644 (file)
@@ -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
 **
 
 /*****************************
    $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 <AXE/date.h>
 
@@ -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;
 }