|
@@ -2,6 +2,8 @@
|
|
|
|
|
|
#include <QDateTime>
|
|
|
|
|
|
+#include <QDir>
|
|
|
+
|
|
|
groupdb::groupdb(std::string strdbpath)
|
|
|
{
|
|
|
mstrdbpath = strdbpath;
|
|
@@ -364,11 +366,56 @@ void groupdb::ExecQueryList()
|
|
|
qDebug("Exec query time is : %d ",xTime.elapsed());
|
|
|
}
|
|
|
|
|
|
+int groupdb::GetFilePathDir(QString &strdir)
|
|
|
+{
|
|
|
+ int nrtn = 0;
|
|
|
+ strdir = getenv("HOME");
|
|
|
+
|
|
|
+ strdir = strdir + "/groupdbtmp";
|
|
|
+ QDir xDir;
|
|
|
+
|
|
|
+ if(xDir.exists(strdir) == false)
|
|
|
+ {
|
|
|
+ qDebug("%s is not exist.Create ",strdir.toLatin1().data());
|
|
|
+ if(false == xDir.mkdir(strdir))
|
|
|
+ {
|
|
|
+ nrtn = -1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return nrtn;
|
|
|
+}
|
|
|
+
|
|
|
void groupdb::ExecQueryData()
|
|
|
{
|
|
|
+ QString strdir;
|
|
|
+ if(GetFilePathDir(strdir ) == -1)
|
|
|
+ {
|
|
|
+ qDebug("Directory Fail.");
|
|
|
+ mqd_bUpdateRes = false;
|
|
|
+ mqd_nError = -11;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ QString filename = QString(mqd_strvehid.data()) + "-"
|
|
|
+ +QString::number(mqd_nrecordid)+"-"
|
|
|
+ +QDateTime::currentDateTime().toString("yyyyMMddhhmmsszzz");
|
|
|
+
|
|
|
+ QFile xFile;
|
|
|
+ xFile.setFileName(strdir + "/" + filename);
|
|
|
+ if(!xFile.open(QIODevice::ReadWrite))
|
|
|
+ {
|
|
|
+ qDebug("Open File Fail.");
|
|
|
+ mqd_bUpdateRes = false;
|
|
|
+ mqd_nError = -12;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
QTime xTime;
|
|
|
+ mqd_filename = filename.toStdString();
|
|
|
+ mqd_filesize = 0;
|
|
|
xTime.start();
|
|
|
mqd_Mutexdata.lock();
|
|
|
+ mqd_filesize = 0;
|
|
|
QSqlQuery query(mdatabase);
|
|
|
char strsen[1000];
|
|
|
snprintf(strsen,1000,"select * from groupdata where((groupdata.recordid = %lld) &(groupdata.vehid = \"%s\"))",
|
|
@@ -377,12 +424,16 @@ void groupdb::ExecQueryData()
|
|
|
if(!query.exec(strsen))
|
|
|
{
|
|
|
qDebug()<<query.lastError();
|
|
|
+ mqd_nError = -13;
|
|
|
mqd_bUpdateRes = false;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
while(query.next())
|
|
|
{
|
|
|
+ QByteArray badata =query.value(7).toByteArray();
|
|
|
+ mqd_filesize = mqd_filesize + badata.size();
|
|
|
+ xFile.write(badata);
|
|
|
// int id = query.value(0).toInt();
|
|
|
// qint64 recordid = query.value(1).toLongLong();
|
|
|
// mql_xvectorrecordtime.push_back(recordid);
|
|
@@ -390,13 +441,12 @@ void groupdb::ExecQueryData()
|
|
|
|
|
|
}
|
|
|
|
|
|
- mqd_filename = "temp";
|
|
|
- mqd_filesize = 0;
|
|
|
|
|
|
mqd_bUpdateRes = true;
|
|
|
}
|
|
|
mqd_bUpdate = false;
|
|
|
|
|
|
+ xFile.close();
|
|
|
mqd_Mutexdata.unlock();
|
|
|
qDebug("Exec querydata time is : %d ",xTime.elapsed());
|
|
|
}
|
|
@@ -466,13 +516,20 @@ int groupdb::getfilepath(qint64 nrecordid, std::string strvehid,std::string & st
|
|
|
QTime xTime;
|
|
|
xTime.start();
|
|
|
mqd_waitmutex.lock();
|
|
|
- mqd_wc.wait(&mqd_waitmutex,1000);
|
|
|
+ mqd_wc.wait(&mqd_waitmutex,10000);
|
|
|
mqd_waitmutex.unlock();
|
|
|
qDebug("query time is %d ",xTime.elapsed());
|
|
|
|
|
|
if(mqd_bUpdateRes == false)
|
|
|
{
|
|
|
- nres = -2;
|
|
|
+ if((mqd_nError == -11)||(mqd_nError == -12))
|
|
|
+ {
|
|
|
+ nres = -3;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ nres = -2;
|
|
|
+ }
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -487,3 +544,32 @@ int groupdb::getfilepath(qint64 nrecordid, std::string strvehid,std::string & st
|
|
|
|
|
|
return nres;
|
|
|
}
|
|
|
+
|
|
|
+int groupdb::GetFileData(std::string strfilename, qint64 nPos, qint64 nFilesize, QByteArray &ba)
|
|
|
+{
|
|
|
+ QString strpath;
|
|
|
+ if(GetFilePathDir(strpath)!= 0)
|
|
|
+ {
|
|
|
+ qDebug("Directory not exist.");
|
|
|
+ return -1; //File Directory can't found.
|
|
|
+ }
|
|
|
+ strpath = strpath + "/"+ strfilename.data();
|
|
|
+
|
|
|
+ QFile xFile;
|
|
|
+ xFile.setFileName(strpath);
|
|
|
+ if(!xFile.open(QIODevice::ReadOnly))
|
|
|
+ {
|
|
|
+ qDebug("Open File Fail.");
|
|
|
+ return -2; //File Not Exist
|
|
|
+ }
|
|
|
+ if(xFile.seek(nPos) == false)
|
|
|
+ {
|
|
|
+ qDebug("Seek File Fail. pos is %lld",nPos);
|
|
|
+ xFile.close();
|
|
|
+ return -3;
|
|
|
+ }
|
|
|
+ ba.clear();
|
|
|
+ ba = xFile.read(nFilesize);
|
|
|
+ return ba.size();
|
|
|
+
|
|
|
+}
|