patrik08
8th June 2007, 00:28
I have large zip file to insert on a DB (mysql)
How i can insert a lock on a way wo the next Thread not insert data on this table?
or can i solve this if i put the zip packer on the same Thread ... as this
If the user create fast 3 or more page?
/* max bit upload to one page cms zip #define MAXUPLOADFOLDER 2563243 2.44 MB mysql long blob */
class PushQueryZip : public QThread, public Base_Modul
{
Q_OBJECT
public:
void SetupQuery( QSqlDatabase db , uint idmg , const QString filego)
{
LoopNummer = 0;
loopi = true;
dbconnection = db;
having = false;
writteln = filego;
pagenummer = idmg;
}
void run() {
QByteArray inside;
QFile f(writteln);
bool accessf = f.open(QIODevice::ReadOnly);
if (!accessf) {
emit ErrorMsgZip(tr("Unable to open zip."));
exit();
}
inside = f.readAll();
f.close();
f.remove();
const QString blobzip = inside.toBase64()+"|end_stream|";
sqlmake = QString("REPLACE INTO PAGEFILE VALUES (%1, 'zip', 'attach' ,'%2',%3)")
.arg(pagenummer)
.arg(blobzip)
.arg(QTime_Null());
QSqlQuery query("",dbconnection);
bool success = query.exec(sqlmake);
if (!success) {
emit ErrorMsgZip(tr("Unable to connect and exec query..."));
exit();
}
emit OkJobEnd(pagenummer);
exit();
}
signals:
void ErrorMsgZip(QString);
void OkJobEnd(uint);
private:
QSqlDatabase dbconnection;
QString sqlmake;
QString writteln; /* file to go zip ensure dir exist */
QString inside;
int LoopNummer;
uint pagenummer;
bool loopi;
bool having;
};
How i can insert a lock on a way wo the next Thread not insert data on this table?
or can i solve this if i put the zip packer on the same Thread ... as this
If the user create fast 3 or more page?
/* max bit upload to one page cms zip #define MAXUPLOADFOLDER 2563243 2.44 MB mysql long blob */
class PushQueryZip : public QThread, public Base_Modul
{
Q_OBJECT
public:
void SetupQuery( QSqlDatabase db , uint idmg , const QString filego)
{
LoopNummer = 0;
loopi = true;
dbconnection = db;
having = false;
writteln = filego;
pagenummer = idmg;
}
void run() {
QByteArray inside;
QFile f(writteln);
bool accessf = f.open(QIODevice::ReadOnly);
if (!accessf) {
emit ErrorMsgZip(tr("Unable to open zip."));
exit();
}
inside = f.readAll();
f.close();
f.remove();
const QString blobzip = inside.toBase64()+"|end_stream|";
sqlmake = QString("REPLACE INTO PAGEFILE VALUES (%1, 'zip', 'attach' ,'%2',%3)")
.arg(pagenummer)
.arg(blobzip)
.arg(QTime_Null());
QSqlQuery query("",dbconnection);
bool success = query.exec(sqlmake);
if (!success) {
emit ErrorMsgZip(tr("Unable to connect and exec query..."));
exit();
}
emit OkJobEnd(pagenummer);
exit();
}
signals:
void ErrorMsgZip(QString);
void OkJobEnd(uint);
private:
QSqlDatabase dbconnection;
QString sqlmake;
QString writteln; /* file to go zip ensure dir exist */
QString inside;
int LoopNummer;
uint pagenummer;
bool loopi;
bool having;
};