Qt Embedded FireBird

Qt, Visual Studio FireBird. , FireBird Embedded Qt . , Qt.

, , .

:

  1. Qt SDK, Visual Studio.
  2. IBase .
  3. ' .
  4. ' .
  5. , .

, , 볺:

Serg 12345. Qt 4.5.2 LGPL.

:

1. Qt SDK

1) (2-3 GB, , 1.5 GB).

2) SDK (QtSDK 4.5.2 ). , , , D: .

3) Environmental Variable QtDIR C: Qt 2009.03 Qt - 2.

2. dz Qt VS 2005 (2008)

1) VS 2005 Command Prompt .

2) QtDIR (C: Qt 2009.03 Qt ", ).

3) configure.exe :

-plugin-sql-ibase

ֳ ,

configure.exe-help

4) :

Which edition of Qt do you want to use?

- Open Source Edition.

y ('y' - to accept this license offer).

5) VCProj Solution. Solution projects.sln C: Qt 2009.03 Qt .

3. Visual Studio Addon for Qt

1) Visual Studio, .

2) Qt-vs-addin-1.0 .2. exe

3) ³ Visual Studio Qt Qt->Qt Options. Add ', , Qt 4.5.2. ' , . , , , (no such Qt version found on this machine ). - Qt, $ (QtDIR), C: Qt 2009.03 Qt . Qt Default Version Qt 4.5.2 .

4) ' . :

: Libraries Win32 static library Qt Library wchar_t as Built-In, Win32 static library Qt , Qt , Project Settings/ + +/Language Treat wchar_t as Built-In Type No (/ Zc: wchar_t-).

Qt .2 :

4. FireBird:

Firebird .

5. dz Plugin IBase

1) $ (QtDIR) src plugins sqldrivers ibase Debug and Release.

, :

2) Embedded Server.

'

' , QIBASE . , , EXE , :

...
if (! pluginLoader_.isLoaded ())
{
pluginLoader_.setFileName (QApplication:: instance () ->applicationDirPath () + QDir:: separator () + QtIBasePluginName_);

if (! pluginLoader_.load ())
{
////Loading SQL Driver failed.;
isInitialized_ = false;
return false;
}
}
QObject * object = pluginLoader_.instance ();
if (object == NULL)
{
//Loading SQL Driver Instance failed.;
pluginLoader_.unload ();
return false;
}
QSqlDriverPlugin * plugin = qobject_cast (object);
if (plugin == NULL)
{
//QSqlDriverPlugin == NULL;
pluginLoader_.unload ();
return false;
}
driver_ = plugin->create ("QIBASE");
if (driver_ == NULL)
{
//Loading QIBASE Driver Instance failed.;
pluginLoader_.unload ();
return false;
}
isInitialized_ = true;
return isInitialized_;
...

, FireBird , ' .

connectionName_ = "Connection_1";

QSqlDatabase database;
//Adding database (DRIVER);
database = QSqlDatabase:: addDatabase (driver_, connectionName_);
//Check Valid database.;
if (! database.isValid ())
{
QString lastError = database.lastError (). Text ();
//Database is not valid
return false;
}
//Set database configurations.;
//FilePath = ": D:  FireBirdAndQt  debug  New.FDB";
//UserName = "Serg";
//Password = 12345;
//ConnectionString_ = "server type = Embedded; auto_commit = True; auto_commit_level = 4096; connection lifetime = 1; DataBase = "% 1  "";
database.setDatabaseName (filePath);
database.setUserName (userName);
database.setPassword (password);
QString connectionString = QString (connectionString_). Arg (filePath);
database.setConnectOptions (connectionString);
bool result = false;

//"Openning database. Driver PTR ==% d", (int) database.driver ();
result = database.open ();
if (! result)
{
QString lastError = database.lastError (). Text ();
lastError_ = (uint) database.lastError (). number ();
}

QSqlDatabase ':

database.setDatabaseName (filePath);
database.setUserName (userName);
database.setPassword (password);
QString connectionString = QString (connectionString_). Arg (filePath);
database.setConnectOptions (connectionString);

, ', . ', set ...(), database '.

FireBird

, :

bool FireBirdDatabase:: Create (const QString & filePath, const QString & userName, const QString & password)
{
if (! isInitialized_)
{
Initialize ();
}
if (QFile:: exists (filePath))
{
return false;
}
databasePath_ = filePath;
QString queryString;
queryString + = "CREATE DATABASE";
queryString + = " '" + filePath + "'";
queryString + = "USER  '" + userName + "'";
queryString + = "PASSWORD  '" + password + "'";
queryString + = "DEFAULT CHARACTER SET UNICODE_FSS";
ISC_STATUS_ARRAY status;
isc_db_handle databaseHandle = NULL;
isc_tr_handle transactionHandle = NULL;
unsigned short g_nFbDialect = SQL_DIALECT_V6;
if (isc_dsql_execute_immediate (status, & databaseHandle, & transactionHandle, 0, queryString.toStdString (). c_str (), g_nFbDialect, NULL))
{
long SQLCODE = isc_sqlcode (status);
return false;
}
isc_commit_transaction (status, & transactionHandle);
if (databaseHandle! = NULL)
{
ISC_STATUS_ARRAY status;
isc_detach_database (status, & databaseHandle);
}
return true;
}

? isc_dsql_execute_immediate (). ³ - - . :

...
QSqlDatabase db = QSqlDatabase:: addDatabase ("QSQLITE");
db.setDatabaseName (": memory:");
if (! db.open ())
{
QMessageBox:: critical (0, qApp->tr ("Cannot open database"),
qApp->tr ("Unable to establish a database connection.  n"
"This example needs SQLite support. Please read"
"The Qt SQL driver documentation for information how"
"To build it.  N  n"
"Click Cancel to exit."), QMessageBox:: Cancel);
return false;
}
...

Qt IBASE . Qt (QtDIR examples sql Connection.h ).

: , FireBird ASCII . (filePath ) Unicode, isc_dsql_execute_immediate .

Select

void DatabaseModel:: SelectJobs (QStringList & jobs)
{
QSqlQuery query = QSqlQuery (fireBirdDatabase_.CreateQuery ());
QString preparedString = "SELECT JOB_NAME FROM TBL_JOBS";
query.prepare (preparedString);
if (! query.exec ())
{
QString err = query.lastError (). Text ();

throw std:: runtime_error ("Error executing Query.");
}
while (query.next ())
{
QSqlRecord record = query.record ();
jobs.append (record.value (0). toString ());

}
}

fireBirdDatabase_.CreateQuery () :

{
return QSqlQuery (QSqlDatabase:: database (connectionName_));
}

?

- , - , , (BLOB).

ID .

{
...
QByteArray description ("Test description");
int salary = 1200;
jobName = "tester";
QSqlQuery query (fireBirdDatabase_.CreateQuery ());
bool result = query.prepare ("EXECUTE PROCEDURE SP_INSERT_JOB (?,?, ?)");
query.addBindValue (jobName);
query.addBindValue (salary);
query.addBindValue (description);
if (! query.exec ())
{
QString err = query.lastError (). Text ();
throw std:: runtime_error ("Error executing Query.");
}
query.next ();
int jobID = query.value (0). toUInt ();
...
}

  1. Firebird database .
  2. FlameRobin (open-source administration tool).
  3. IBExpert (administration tool, free Personal Edition download).
  4. Other Firebird tools .
  5. QtSDK 4.5.2 .

: 07/11/11 @ 02:51
г

:

PostProfit.net
' - , Drupal site-made.ru
, 3
16 , - DOU HR Cafe # 1
4