[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
A code review in progress
- To: uu@total-knowledge.com
- Subject: A code review in progress
- From: "Alexey Parshin" <alexeyp@gmail.com>
- Date: Sat, 17 Mar 2007 22:44:37 +1100
- Delivered-to: mailing list uu@total-knowledge.com
- Dkim-signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:mime-version:content-type; b=dpBPTlXLvS6e47o9Ad+UsGvJ5G+UZsSfAdjYRgMU+GUK62ry6gKl3PZOh/1Fw1MQ/5Pj5EUug/cg4vnr/Uk166s59e0Z6g8N+Q7VUIz5e7CJWr5TMEL5y+Rq0amYIKOt9i+ehFmWr4wkVJC5jERZc07t4XO0QWqvaYL30fYlGEo=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:mime-version:content-type; b=OI8am4988itdfMz5I54nHDoBI5Nev/kkAc2kKGRibxsDpeQJ3q9DeE80b2PiPhdkDOjmtGg8nL9FA4dBTSbaLa0Ec7LmL5HfrTHtGpq04URnJDAUyKOt/lcst6l9HqbxVw+frviWAa/o/wmeJ3f791ptYVeH4Q7u/pElWLrfVVM=
- Mailing-list: contact uu-help@total-knowledge.com; run by ezmlm
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