Home Projects Jobs Clientele Contact


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

Re: UU code

The database connection is established with CODBCDatabase. This object is derived from CDatabase.

1) Connection existence scope. When the object is created and open() is called that creates the connection. The least necessary thing to create a connection is a connect string. When the database object is destroyed - the connection is terminated.

2) We should never use CODBCDatabase in our code besides creating the connection object. Any code that needs a database object should use CDatabase. That allows us to change a single line of code if we need to switch to totally different database driver. SPTK allows to create a database driver for anything that supports basic database functions. If we don't like Postgres ODBC driver, for instance, we can create CPostgresDatabase class, and replace:

CDatabase* db;

db = new CODBCDatabase("DSN=.....");
db = new CPostgresDatabase(".....");

It would not require any corrections in C++ code besides the difference in SQL syntax.

2007/3/14, sergey@total-knowledge.com <sergey@total-knowledge.com>:
No, I don't understand why would we have to do that.
What I'm trying to do now is saving CODBCDatabase handle in SessionContext.
What's the purpose of CDatabase? Why a handle isn't enough?
Please elaborate.

> Also, it isn't enough to have db handle to work with the database. We (in
> ideal case) should have CDatabase object staying alive through the whole
> session. I'm not sure - where to keep it, but it shoul be connected with
> the
> session data. Does it make sense?
> 2007/3/14, Ilya A. Volynets-Evenbakh <ilya@total-knowledge.com>:
>> No.
>> sergey@total-knowledge.com wrote:
>> >> Servlet has a virtual init() method, that you can override. There you
>> >> can create your pool instance and store it in ServletContext
>> attribute.
>> >>
>> >
>> > In order to do that my libdm' uudb class should extend HttpServlet and
>> be
>> > servlet itself. Is it right way to do it?
>> >
>> >
>> >
>> >> --
>> >> Ilya A. Volynets-Evenbakh
>> >> Total Knowledge. CTO
>> >> http://www.total-knowledge.com
>> >>
>> >>
>> >>
>> >
>> >
>> >
>> --
>> Ilya A. Volynets-Evenbakh
>> Total Knowledge. CTO
>> http://www.total-knowledge.com
> --
> Alexey Parshin,
> http://www.sptk.net

Alexey Parshin,

Authoright © Total Knowledge: 2001-2008