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?


Qt Code:
  1. /* max bit upload to one page cms zip #define MAXUPLOADFOLDER 2563243 2.44 MB mysql long blob */
  2. class PushQueryZip : public QThread, public Base_Modul
  3. {
  4. Q_OBJECT
  5. public:
  6. void SetupQuery( QSqlDatabase db , uint idmg , const QString filego)
  7. {
  8. LoopNummer = 0;
  9. loopi = true;
  10. dbconnection = db;
  11. having = false;
  12. writteln = filego;
  13. pagenummer = idmg;
  14.  
  15. }
  16. void run() {
  17.  
  18. QByteArray inside;
  19. QFile f(writteln);
  20. bool accessf = f.open(QIODevice::ReadOnly);
  21.  
  22. if (!accessf) {
  23. emit ErrorMsgZip(tr("Unable to open zip."));
  24. exit();
  25. }
  26.  
  27. inside = f.readAll();
  28. f.close();
  29. f.remove();
  30. const QString blobzip = inside.toBase64()+"|end_stream|";
  31. sqlmake = QString("REPLACE INTO PAGEFILE VALUES (%1, 'zip', 'attach' ,'%2',%3)")
  32. .arg(pagenummer)
  33. .arg(blobzip)
  34. .arg(QTime_Null());
  35.  
  36. QSqlQuery query("",dbconnection);
  37. bool success = query.exec(sqlmake);
  38. if (!success) {
  39. emit ErrorMsgZip(tr("Unable to connect and exec query..."));
  40. exit();
  41. }
  42. emit OkJobEnd(pagenummer);
  43. exit();
  44. }
  45.  
  46. signals:
  47. void ErrorMsgZip(QString);
  48. void OkJobEnd(uint);
  49. private:
  50. QSqlDatabase dbconnection;
  51. QString sqlmake;
  52. QString writteln; /* file to go zip ensure dir exist */
  53. QString inside;
  54. int LoopNummer;
  55. uint pagenummer;
  56. bool loopi;
  57. bool having;
  58. };
To copy to clipboard, switch view to plain text mode