|
|
Home » Community » Newbie corner » Separate Database Access code
|
Re: Separate Database Access code [message #38832 is a reply to message #38830] |
Mon, 21 January 2013 15:57 |
lectus
Messages: 329 Registered: September 2006 Location: Brazil
|
Senior Member |
|
|
Hi!
Add Quote: | Sqlite3Session lDB;
| as a member of libDB and after you open the database add: :
class libDB {
typedef libDB CLASSNAME;
public:
Sqlite3Session lDB;
libDB();
~libDB();
void InitDB();
};
void libDB::InitDB()
{
LOG("Open DB");
if(!lDB.Open(ConfigFile("libDB.db"))) {
Exclamation(t_("Cannot create or open libDB database file\n"));
return;
}
LOG("SqlSchema");
SqlSchema sch(SQLITE3);
SQL = lDB;
.
.
.
It fixes the problem. Actually the fix was just "SQL = lDB". I recommend putting lDB as a member of libDB just so your library has a better design.
[Updated on: Mon, 21 January 2013 15:59] Report message to a moderator
|
|
|
|
|
Re: Separate Database Access code [message #38838 is a reply to message #38830] |
Tue, 22 January 2013 21:46 |
|
jibe
Messages: 294 Registered: February 2007 Location: France
|
Experienced Member |
|
|
Hi,
Yes, you are right. It will work using one of your solutions. But:
1 - Re-affacting the value of SQL is dangerous. Developing an application, you will have to re-affect the right value before any use of SQL, as you will not be sure if it has been used by the library. Not very clean and bugs could be numerous !
2 - Making a DLL is a better solution. But as I want this library to be multi-platform, it will not be very easy. A simple U++ library that you add in a project is a lot easier to do !
The U++ documentation says :
Quote: | Most applications need to work with just single database backend, therefore repeating SqlSession parameter in all Sql declarations would be tedious.
To this end U++ supports concept of "main database" which is represented by SQL variable. SQL is of Sql type. When any other Sql variable is created with default constructor (no session parameter provided), it uses the same session as the one the SQL is bound to. To assign session to global SQL, use operator=:
|
If I understand well :
- It is possible to work with several databases,
- To work with another database than the "main database" (the one in my library is a secondary one), I must create sql variables with session parameter provided.
It's just what I'm trying to do... with no succes !
|
|
|
|
|
Goto Forum:
Current Time: Thu Apr 18 13:46:31 CEST 2024
Total time taken to generate the page: 0.01573 seconds
|
|
|