Added database abstractions
[gnucomo.git] / src / include / database.h
index 60f3796..4532bfb 100644 (file)
@@ -76,6 +76,8 @@
 #include <pqxx/result>
 #include "gnucomo_config.h"
 
+#define DEBUG
+
 /*
 ///////////////////////////////////////////////////////////////////////////
 //  NAME           : gnucomo_database
@@ -197,22 +199,34 @@ public:
 
 class database_entity
 {
-   const gnucomo_database  *db;
+   gnucomo_database  *db;
    String    table;
+   String    connected_table;
 
    bool fresh;       // Completely new, no tuple in the database
    bool changed;     // A database update is needed
    bool deleted;     // Tuple is to be deleted from the database
 
+protected:
+
+   std::map<String,String> fields;
+
 public:
 
-  database_entity(const gnucomo_database &gdb, const String tbl)
-  {
-     db = &gdb;
-     table = tbl;
+   database_entity(gnucomo_database &gdb, const String tbl)
+   {
+      db = &gdb;
+      table = tbl;
+
+      fresh = true;
+      changed = false;
+      deleted = false;
+   }
+
+   // contruct a new database entity from the result of another one
+   database_entity(database_entity *from, int row);
+
+   int find_one(String key);
+   int find_many(String tab, String where);
 
-     fresh = true;
-     changed = false;
-     deleted = false;
-  }
 };