#include <qapplication.h>
#include <qsqldriver.h>
#include <qsqldatabase.h>
#include <qsqlquery.h>
#include <qsqlcursor.h>
#include <qfile.h>
#define DRIVER "QMYSQL3" /* see the Qt SQL documentation for a list of available drivers */
#define DATABASE "Sequences" /* the name of your database */
#define USER "user" /* user name with appropriate rights */
#define PASSWORD "password" /* password for USER */
#define HOST "the-server" /* host on which the database is running */
int main( int argc, char ** argv )
{
db->setDatabaseName( DATABASE );
db->setUserName( USER );
db->setPassword( PASSWORD );
db->setHostName( HOST );
QString field
= argv
[1];
//"SM_Indx"; QString path
= argv
[4];
// "/home/me/workarea/sequences/SI-003"; QString strSize
= argv
[5];
// 51497638 int size = strSize.toInt();
if (!importBinaryStateData(field, oldId, newId, path, size))
return 0;
else
return 1;
}
bool
{
qDebug("importBinaryStateData()");
bool success = true;
if (size > 0)
{
QFile file (path
+ "/" + "States_" + oldId
+ "_" + field
+ ".bin");
if (file.open(IO_ReadOnly))
{
if (data.size() == size)
{
if (db->open())
{
QString query
= "UPDATE States SET " + field
+ " = ? WHERE State_ID = " + newId;
if (!q.prepare(query))
{
qDebug("prepare() failed!");
}
q.bindValue(0, data);
if (!q.exec())
{
qDebug("importBinaryActionData(): %s", q.lastError().text().ascii());
success = false;
}
db->close();
}
else
{
qDebug("importBinaryActionData(): Database not open by calling procedure.");
success = false;
}
}
else
{
qDebug("importBinaryActionData(): Could not read %s", file.name().ascii());
success = false;
}
file.close();
}
else
{
qDebug("importBinaryActionData(): Could not open %s", file.name().ascii());
success = false;
}
}
return success;
}
#include <qapplication.h>
#include <qsqldriver.h>
#include <qsqldatabase.h>
#include <qsqlquery.h>
#include <qsqlcursor.h>
#include <qfile.h>
#define DRIVER "QMYSQL3" /* see the Qt SQL documentation for a list of available drivers */
#define DATABASE "Sequences" /* the name of your database */
#define USER "user" /* user name with appropriate rights */
#define PASSWORD "password" /* password for USER */
#define HOST "the-server" /* host on which the database is running */
QSqlDatabase* db;
bool importBinaryStateData( QString, QString, QString, QString, int );
int main( int argc, char ** argv )
{
QApplication a( argc, argv, FALSE );
db = QSqlDatabase::addDatabase( DRIVER );
db->setDatabaseName( DATABASE );
db->setUserName( USER );
db->setPassword( PASSWORD );
db->setHostName( HOST );
QString field = argv[1]; //"SM_Indx";
QString oldId = argv[2]; //"1";
QString newId = argv[3]; //"25";
QString path = argv[4]; // "/home/me/workarea/sequences/SI-003";
QString strSize = argv[5]; // 51497638
int size = strSize.toInt();
if (!importBinaryStateData(field, oldId, newId, path, size))
return 0;
else
return 1;
}
bool
importBinaryStateData( QString field, QString oldId, QString newId, QString path, int size )
{
qDebug("importBinaryStateData()");
bool success = true;
if (size > 0)
{
QFile file (path + "/" + "States_" + oldId + "_" + field + ".bin");
if (file.open(IO_ReadOnly))
{
QByteArray data = file.readAll();
if (data.size() == size)
{
if (db->open())
{
QSqlQuery q;
QString query = "UPDATE States SET " + field + " = ? WHERE State_ID = " + newId;
if (!q.prepare(query))
{
qDebug("prepare() failed!");
}
q.bindValue(0, data);
if (!q.exec())
{
qDebug("importBinaryActionData(): %s", q.lastError().text().ascii());
success = false;
}
db->close();
}
else
{
qDebug("importBinaryActionData(): Database not open by calling procedure.");
success = false;
}
}
else
{
qDebug("importBinaryActionData(): Could not read %s", file.name().ascii());
success = false;
}
file.close();
}
else
{
qDebug("importBinaryActionData(): Could not open %s", file.name().ascii());
success = false;
}
}
return success;
}
To copy to clipboard, switch view to plain text mode
Bookmarks