estanisgeyer
7th February 2008, 18:14
Good day, friends..
I want to exchange some ideas. I have a class to connect to the database Firebird (below). All classes that need access to the database is inherited this class. What is the best way to make connection to the database? Am Ia the connection only at the beginning of the application and closing at the end?
#include "Db.h"
const QString DB::UserNameDB = "SYSDBA";
const QString DB::PasswordDB = "123456";
QString DB::Servidor = "NULL";
QString DB::Database = "NULL";
bool DB::DBConfig = false;
DB::DB(QString driver)
:Driver(driver)
{
}
DB::~DB()
{
}
void DB::OpenDB()
{
ConnDB();
}
void DB::CloseDB()
{
db.close();
}
void DB::ConnDB()
{
if (!db.contains(Driver))
{
db = QSqlDatabase::addDatabase(Driver);
db.setHostName(Servidor);
db.setDatabaseName(Database);
db.setUserName(UserNameDB);
db.setPassword(PasswordDB);
DBConfig = true;
}
db.open();
}
Thanks,
Marcelo E. Geyer
Brazil/RS
I want to exchange some ideas. I have a class to connect to the database Firebird (below). All classes that need access to the database is inherited this class. What is the best way to make connection to the database? Am Ia the connection only at the beginning of the application and closing at the end?
#include "Db.h"
const QString DB::UserNameDB = "SYSDBA";
const QString DB::PasswordDB = "123456";
QString DB::Servidor = "NULL";
QString DB::Database = "NULL";
bool DB::DBConfig = false;
DB::DB(QString driver)
:Driver(driver)
{
}
DB::~DB()
{
}
void DB::OpenDB()
{
ConnDB();
}
void DB::CloseDB()
{
db.close();
}
void DB::ConnDB()
{
if (!db.contains(Driver))
{
db = QSqlDatabase::addDatabase(Driver);
db.setHostName(Servidor);
db.setDatabaseName(Database);
db.setUserName(UserNameDB);
db.setPassword(PasswordDB);
DBConfig = true;
}
db.open();
}
Thanks,
Marcelo E. Geyer
Brazil/RS