UniverseUniversity


Home Projects Jobs Clientele Contact

uu


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

A code review in progress



Here is another piece of code that may work after corrections.

Here is the class declaration:
+class uudb
+{
+ public:
+  uudb();
+  ~uudb();
+
+  sptk::CODBCDatabase handle;
+  void exec(const std::string& query);
+};

Here is constructor:

+uudb::uudb()
+{
+    CODBCDatabase handle("DSN=PostgreSQL;UID=sergey;PWD=;DATABASE=uu");
+    try {
+      cout<<"\nOpening database... \n";
+      handle.open();
+    }
+    catch (exception& e) {
+      cout<<"\nError: " <<e.what();
+      cout<<"\nCan't open the database connection.\n";
+    }   
+}

As far as I can see, handle defined in ctor has nothing to do with the class member handle.
This may work properly after the following modifications:

uudb::uudb()  : handle("DSN=PostgreSQL;UID=sergey;PWD=;DATABASE=uu")
{
    try {
      cout<<"\nOpening database... \n";
      handle.open();
    }
    catch (exception& e) {
      cout<<"\nError: " <<e.what();
      cout<<"\nCan't open the database connection.\n";
    }   
}

Another thing, I wouldn't do any IO in ctor or dtor. SPTK is smart enough to open the connection when you try to execute any query connected to this database. It would also automatically close the connection when the uudb object is destructed.
--
Alexey Parshin,
http://www.sptk.net

Authoright © Total Knowledge: 2001-2008