Commit 4c41aee8 authored by Martin Straka's avatar Martin Straka

Merge branch 'real-file-size-in-db' into 'attachment-size'

Modified File Database to Contain Acurate File Sizes

See merge request !139
parents 0841f98e f3d4aa54
......@@ -343,7 +343,7 @@ Component {
console.log("Attachment is ZFO: " + rFileName)
var fileContent = null
if (!fromLocalDb) {
fileContent = files.base64ToRaw(rFileContent)
fileContent = rBinaryContent
} else {
fileContent = files.getFileRawContentFromDb(userName, rFileId)
}
......@@ -355,7 +355,7 @@ Component {
})
} else {
if (!fromLocalDb) {
files.openAttachment(rFileName, rFileContent)
files.openAttachment(rFileName, rBinaryContent)
} else {
files.openAttachmentFromDb(userName, rFileId)
}
......
......@@ -68,12 +68,6 @@ Item {
return filePath.replace(/^.*[\\\/]/, '')
}
/* Return file size string in bytes or kilobytes */
function getFileSizeString(fileSize) {
return (fileSize >= 1024) ? "~" + Math.ceil(fileSize / 1024) + " kB"
: "~" + (fileSize) + " B"
}
/* Check if message has fill an attachment and check total size */
function checkAttachmentSizes() {
attachmentsSizeLabel.color = datovkaPalette.text
......@@ -98,7 +92,7 @@ Item {
return true
}
if (totalAttachmentSizeBytes >= 1024) {
attachmentsSizeLabel.text = qsTr("Total size of attachments is ~%1 KB.").arg(Math.ceil(totalAttachmentSizeBytes/1024))
attachmentsSizeLabel.text = qsTr("Total size of attachments is ~%1 kB.").arg(Math.ceil(totalAttachmentSizeBytes/1024))
} else {
attachmentsSizeLabel.text = qsTr("Total size of attachments is %1 B.").arg(totalAttachmentSizeBytes)
}
......@@ -147,9 +141,7 @@ Item {
dmRecipientIdent.text = isdsEnvelope.dmRecipientIdent
setMandate(isdsEnvelope)
sendMsgAttachmentModel.setFromDb(userName, msgId, true) // true = real file size will calculate from file content
for (var i = 0; i < sendMsgAttachmentModel.rowCount(); i++) {
totalAttachmentSizeBytes += sendMsgAttachmentModel.fileSizeBytesFromRow(i)
}
totalAttachmentSizeBytes = sendMsgAttachmentModel.dataSizeSum()
checkAttachmentSizes()
}
......@@ -162,8 +154,8 @@ Item {
var zfoSize = zfo.getZfoSizeFromDb(userName, msgId)
// Zfo file must exist in the local database so zfoSize must be > 0
if (zfoSize > 0) {
totalAttachmentSizeBytes += zfoSize;
sendMsgAttachmentModel.appendFileFromPath(FileIdType.DB_ZFO_ID, fileName, "", zfoSize)
totalAttachmentSizeBytes = sendMsgAttachmentModel.dataSizeSum()
} else {
mainPanel.visible = false
errorText.text = qsTr("ZFO file of message %1 is not available. Download complete message to get it before forwarding.").arg(msgId)
......@@ -215,9 +207,9 @@ Item {
if (!isInFiletList) {
var fileName = getFileNameFromPath(pathListModel.get(j).path)
var fileSizeBytes = files.getAttachmentSizeInBytes(pathListModel.get(j).path)
totalAttachmentSizeBytes += fileSizeBytes;
sendMsgAttachmentModel.appendFileFromPath(FileIdType.NO_FILE_ID,
fileName, pathListModel.get(j).path, fileSizeBytes)
totalAttachmentSizeBytes = sendMsgAttachmentModel.dataSizeSum()
}
}
pathListModel.clear()
......@@ -583,7 +575,7 @@ Item {
font.pointSize: textFontSizeSmall
}
Text {
text: getFileSizeString(rFileSizeBytes)
text: rFileSizeStr
color: datovkaPalette.mid
font.pointSize: textFontSizeSmall
}
......@@ -611,8 +603,8 @@ Item {
}
MouseArea {
function handleClick() {
totalAttachmentSizeBytes -= sendMsgAttachmentModel.fileSizeBytesFromRow(index)
sendMsgAttachmentModel.removeItem(index)
totalAttachmentSizeBytes = sendMsgAttachmentModel.dataSizeSum()
}
anchors.fill: parent
......
......@@ -35,17 +35,6 @@ const QSet<QString> knowExp = QSet<QString> () <<
"odt" << "pdf" << "png" << "ppt" << "pptx" << "rtf" << "tiff" <<
"txt" << "wav" << "xls" << "xlsx" << "xml" << "zfo";
QString approximateDataSize(int dataSize)
{
QString str;
if (dataSize >= 1024) {
str = QLatin1String("~") + QString::number(dataSize / 1024) + QLatin1String(" kB");
} else {
str = QLatin1String("~") + QString::number(dataSize) + QLatin1String(" B");
}
return str;
}
QString getAttachmentFileIconFromFileExtension(const QString &fileName)
{
QString img("qrc:/fileicons/fileicon_blank.png");
......
......@@ -25,14 +25,6 @@
#include <QString>
/*!
* @brief Get approximate data chunk size from supplied data size.
*
* @param[in] dataSize Actual data size.
* @return Approximate data size including the unit.
*/
QString approximateDataSize(int dataSize);
/*!
* @brief Get attachment icon from attachment file extension.
*
......
......@@ -174,17 +174,15 @@ void Files::openAttachmentFromDb(const QString &userName, int fileId)
Isds::Document document(fDb->getFileFromDb(fileId));
openAttachment(document.fileDescr(), document.base64Content().toUtf8());
openAttachment(document.fileDescr(), document.binaryContent());
}
void Files::openAttachment(const QString &fileName,
const QByteArray &base64Data)
const QByteArray &binaryData)
{
Q_ASSERT(!fileName.isEmpty());
Q_ASSERT(!base64Data.isEmpty());
if (fileName.isEmpty() || base64Data.isEmpty()) {
if (Q_UNLIKELY(fileName.isEmpty() || binaryData.isEmpty())) {
logErrorNL("%s", "File name or its content is empty.");
Q_ASSERT(0);
return;
}
......@@ -195,8 +193,7 @@ void Files::openAttachment(const QString &fileName,
return;
}
QString filePath(writeFile(appTmpDirPath(), fileName,
base64ToRaw(base64Data)));
QString filePath(writeFile(appTmpDirPath(), fileName, binaryData));
if (!filePath.isEmpty()) {
logInfoNL("Creating temporary file '%s'.",
......@@ -419,7 +416,7 @@ void Files::vacuumFileDbs(void)
userName.toUtf8().constData());
return;
}
fDb->vacuumFileDb();
fDb->vacuum();
}
emit statusBarTextChanged(tr("Operation Vacuum has finished"), false);
......@@ -504,11 +501,6 @@ QByteArray Files::rawFileContent(const QString &filePath)
return rawData;
}
QByteArray Files::base64ToRaw(const QByteArray &base64Data)
{
return QByteArray::fromBase64(base64Data);
}
MsgInfo *Files::zfoData(const QVariant &attachModelVariant,
const QByteArray &rawZfoData)
{
......@@ -526,7 +518,7 @@ MsgInfo *Files::zfoData(const QVariant &attachModelVariant,
}
bool Files::setAttachmentModel(FileListModel &attachModel,
const QString &userName, qint64 msgId, bool includeRealFileSize)
const QString &userName, qint64 msgId)
{
debugFuncCall();
......@@ -548,18 +540,8 @@ bool Files::setAttachmentModel(FileListModel &attachModel,
attachModel.clearAll();
if (includeRealFileSize) {
/*
* The real file size is computed from file content and it is
* included in the model. Requires file content from database
* and base64 decode. It is slow method and it is used for
* send message file model only.
*/
fDb->setFileModelFromDbWithFileContent(attachModel, msgId);
} else {
/* Set file model without file content and real file size. */
fDb->setFileModelFromDb(attachModel, msgId);
}
/* Set file model without file content and real file size. */
fDb->setFileModelFromDb(attachModel, msgId);
return true;
}
......@@ -595,18 +577,17 @@ void Files::sendAttachmentEmailZfo(const QVariant &attachModelVariant,
for (int row = 0; row < attachModel->rowCount(); ++row) {
QModelIndex idx(attachModel->index(row));
/*
* On Android the attachment must be saved and the explicitly
* add into the email message.
* On Android the attachment must be saved and then explicitly
* added into the email message.
*/
QByteArray base64Data(attachModel->data(idx,
FileListModel::ROLE_FILE_DATA).toByteArray());
QByteArray binaryData(
attachModel->data(idx, FileListModel::ROLE_BINARY_DATA).toByteArray());
QString attachName(attachModel->data(idx,
FileListModel::ROLE_FILE_NAME).toString());
QString filePath(writeFile(targetPath, attachName,
base64ToRaw(base64Data)));
QString filePath(writeFile(targetPath, attachName, binaryData));
fileList.append(filePath);
addAttachmentToEmailMessage(emailMessage, attachName,
base64Data, boundary);
binaryData.toBase64(), boundary);
}
finishEmailMessage(emailMessage, boundary);
......@@ -712,8 +693,8 @@ void Files::saveAttachmentsToDiskZfo(const QVariant &attachModelVariant,
QModelIndex idx(attachModel->index(row));
destPath = writeFile(targetPath, attachModel->data(idx,
FileListModel::ROLE_FILE_NAME).toString(),
base64ToRaw(attachModel->data(idx,
FileListModel::ROLE_FILE_DATA).toByteArray()));
attachModel->data(idx,
FileListModel::ROLE_BINARY_DATA).toByteArray());
}
attachmentSavingNotification(destPath);
......@@ -900,8 +881,7 @@ bool Files::parseAndShowXmlData(enum MsgInfo::ZfoType type, QString *idStr,
foreach (const Isds::Document &document, message.documents()) {
attachModel->appendFileEntry(
FileListModel::Entry(-1, document.fileDescr(),
approximateDataSize(document.binaryContent().size()),
document.base64Content(), document.binaryContent().size(),
document.binaryContent(), document.binaryContent().size(),
QString()));
}
}
......
......@@ -128,11 +128,11 @@ public:
* @brief Open attachment in default application.
*
* @param[in] fileName File name.
* @param[in] base64Data File content base64.
* @param[in] binaryData Raw file content.
*/
Q_INVOKABLE static
void openAttachment(const QString &fileName,
const QByteArray &base64Data);
const QByteArray &binaryData);
/*!
* @brief Open attachment from path in default application.
......@@ -205,15 +205,6 @@ public:
Q_INVOKABLE static
QByteArray rawFileContent(const QString &filePath);
/*!
* @brief Decodes base64-encoded content.
*
* @param[in] base64Data Base64-encoded data.
* @return Raw data.
*/
Q_INVOKABLE static
QByteArray base64ToRaw(const QByteArray &base64Data);
/*!
* @brief Parse content of ZFO file.
*
......@@ -238,12 +229,11 @@ public:
* @param[out] attachModel Attachment model to be set.
* @param[in] userName Identifies the account.
* @param[in] msgId Message identifier.
* @param[in] includeRealFileSize True if real file size will include in the model.
* @return True if success.
*/
static
bool setAttachmentModel(FileListModel &attachModel,
const QString &userName, qint64 msgId, bool includeRealFileSize);
const QString &userName, qint64 msgId);
/*!
* @brief Send attachment from ZFO with email application.
......
......@@ -23,28 +23,26 @@
#include <QQmlEngine> /* qmlRegisterType */
#include <QSqlRecord>
#include <QStringBuilder>
#include "src/files.h" /* TODO -- Do something with it. */
#include "src/models/filemodel.h"
FileListModel::Entry::Entry(const Entry &fme)
: m_fileId(fme.m_fileId),
m_fileName(fme.m_fileName),
m_fileSizeStr(fme.m_fileSizeStr),
m_fileContent(fme.m_fileContent),
m_fileSizeBytes(fme.m_fileSizeBytes),
m_filePath(fme.m_filePath)
FileListModel::Entry::Entry(const Entry &other)
: m_fileId(other.m_fileId),
m_fileName(other.m_fileName),
m_data(other.m_data),
m_fileSize(other.m_fileSize),
m_filePath(other.m_filePath)
{
}
FileListModel::Entry::Entry(const int fileId, const QString &fileName,
const QString &fileSizeStr, const QString &fileContent,
qint64 fileSizeBytes, const QString &filePath)
const QByteArray &data, qint64 fileSize, const QString &filePath)
: m_fileId(fileId),
m_fileName(fileName),
m_fileSizeStr(fileSizeStr),
m_fileContent(fileContent),
m_fileSizeBytes(fileSizeBytes),
m_data(data),
m_fileSize(fileSize),
m_filePath(filePath)
{
}
......@@ -54,7 +52,7 @@ int FileListModel::Entry::fileId(void) const
return m_fileId;
}
QString FileListModel::Entry::fileName(void) const
const QString &FileListModel::Entry::fileName(void) const
{
return m_fileName;
}
......@@ -64,37 +62,52 @@ void FileListModel::Entry::setFileName(const QString &fileName)
m_fileName = fileName;
}
QString FileListModel::Entry::fileSizeStr(void) const
/*!
* @brief Creates human readable size description string.
*
* @param[in] dataSize Size in bytes.
* @return String containing units.
*/
static
QString approximateDataSize(qint64 dataSize)
{
return m_fileSizeStr;
if (dataSize >= 1024) {
return QStringLiteral("~") % QString::number(dataSize / 1024) % QStringLiteral(" kB");
} else {
return QStringLiteral("~") % QString::number(dataSize) % QStringLiteral(" B");
}
}
void FileListModel::Entry::setFileSizeStr(const QString &fileSizeStr)
QString FileListModel::Entry::fileSizeStr(void) const
{
m_fileSizeStr = fileSizeStr;
if (m_fileSize >= 0) {
return approximateDataSize(m_fileSize);
} else {
return QString();
}
}
QString FileListModel::Entry::fileContent(void) const
const QByteArray &FileListModel::Entry::binaryContent(void) const
{
return m_fileContent;
return m_data;
}
void FileListModel::Entry::setFileContent(const QString &fileContent)
void FileListModel::Entry::setBinaryContent(const QByteArray &data)
{
m_fileContent = fileContent;
m_data = data;
}
qint64 FileListModel::Entry::fileSizeBytes(void) const
qint64 FileListModel::Entry::fileSize(void) const
{
return m_fileSizeBytes;
return m_fileSize;
}
void FileListModel::Entry::setFileSizeBytes(qint64 fileSizeBytes)
void FileListModel::Entry::setFileSize(qint64 fileSize)
{
m_fileSizeBytes = fileSizeBytes;
m_fileSize = fileSize;
}
QString FileListModel::Entry::filePath(void) const
const QString &FileListModel::Entry::filePath(void) const
{
return m_filePath;
}
......@@ -134,7 +147,7 @@ QHash<int, QByteArray> FileListModel::roleNames(void) const
roles[ROLE_FILE_ID] = "rFileId";
roles[ROLE_FILE_NAME] = "rFileName";
roles[ROLE_FILE_SIZE_STR] = "rFileSizeStr";
roles[ROLE_FILE_DATA] = "rFileContent";
roles[ROLE_BINARY_DATA] = "rBinaryContent";
roles[ROLE_FILE_SIZE_BYTES] = "rFileSizeBytes";
roles[ROLE_FILE_PATH] = "rFilePath";
}
......@@ -159,11 +172,11 @@ QVariant FileListModel::data(const QModelIndex &index, int role) const
case ROLE_FILE_SIZE_STR:
return file.fileSizeStr();
break;
case ROLE_FILE_DATA:
return file.fileContent();
case ROLE_BINARY_DATA:
return file.binaryContent();
break;
case ROLE_FILE_SIZE_BYTES:
return file.fileSizeBytes();
return file.fileSize();
break;
case ROLE_FILE_PATH:
return file.filePath();
......@@ -187,22 +200,23 @@ QList<FileListModel::Entry> FileListModel::allEntries(void) const
return entries;
}
QString FileListModel::filePathFromRow(int row)
QString FileListModel::filePathFromRow(int row) const
{
if ((row < 0) || (row >= m_files.size())) {
if (Q_UNLIKELY((row < 0) || (row >= m_files.size()))) {
Q_ASSERT(0);
return QString();
}
return m_files[row].filePath();
}
qint64 FileListModel::fileSizeBytesFromRow(int row)
qint64 FileListModel::dataSizeSum(void) const
{
if ((row < 0) || (row >= m_files.size())) {
return 0;
qint64 sum = 0;
foreach (const Entry &entry, m_files) {
sum += entry.fileSize();
}
return m_files[row].fileSizeBytes();
return sum;
}
Qt::ItemFlags FileListModel::flags(const QModelIndex &index) const
......@@ -223,30 +237,8 @@ void FileListModel::setQuery(QSqlQuery &query)
query.first();
while (query.isActive() && query.isValid()) {
m_files.append(Entry(query.value(0).toInt(),
query.value(1).toString(), query.value(2).toString(),
QString(), 0, QString()));
query.next();
}
endResetModel();
}
void FileListModel::setQueryWithFileContent(QSqlQuery &query)
{
if (query.record().count() != 3) {
return;
}
beginResetModel();
m_files.clear();
query.first();
while (query.isActive() && query.isValid()) {
m_files.append(Entry(query.value(0).toInt(),
query.value(1).toString(), QString(), QString(),
QByteArray::fromBase64(query.value(2).toByteArray()).size(),
QString()));
query.value(1).toString(), QByteArray(),
query.value(2).toLongLong(), QString()));
query.next();
}
......@@ -264,8 +256,8 @@ void FileListModel::appendFileFromPath(int fileId, const QString &fileName,
const QString &filePath, qint64 fileSizeBytes)
{
beginInsertRows(QModelIndex(), rowCount(), rowCount());
m_files.append(FileListModel::Entry(fileId, fileName, QString(),
QString(), fileSizeBytes, filePath));
m_files.append(FileListModel::Entry(fileId, fileName, QByteArray(),
fileSizeBytes, filePath));
endInsertRows();
}
......@@ -285,8 +277,7 @@ FileListModel *FileListModel::fromVariant(const QVariant &modelVariant)
return qobject_cast<FileListModel *>(obj);
}
bool FileListModel::setFromDb(const QString &userName, const QString &msgIdStr,
bool includeRealFileSize)
bool FileListModel::setFromDb(const QString &userName, const QString &msgIdStr)
{
bool ok = false;
qint64 msgId = msgIdStr.toLongLong(&ok);
......@@ -294,8 +285,7 @@ bool FileListModel::setFromDb(const QString &userName, const QString &msgIdStr,
return false;
}
return Files::setAttachmentModel(*this, userName, msgId,
includeRealFileSize);
return Files::setAttachmentModel(*this, userName, msgId);
}
void FileListModel::removeItem(int row)
......
......@@ -32,29 +32,27 @@ class FileListModel : public QAbstractListModel {
public:
class Entry {
public:
Entry(const Entry &fme);
Entry(const Entry &other);
Entry(const int fileId, const QString &fileName,
const QString &fileSizeStr, const QString &fileContent,
qint64 fileSizeBytes, const QString &filePath);
const QByteArray &data, qint64 fileSize,
const QString &filePath);
int fileId(void) const;
QString fileName(void) const;
const QString &fileName(void) const;
void setFileName(const QString &fileName);
QString fileSizeStr(void) const;
void setFileSizeStr(const QString &fileSizeStr);
QString fileContent(void) const;
void setFileContent(const QString &fileContent);
qint64 fileSizeBytes(void) const;
void setFileSizeBytes(qint64 fileSizeBytes);
QString filePath(void) const;
const QByteArray &binaryContent(void) const;
void setBinaryContent(const QByteArray &data);
qint64 fileSize(void) const;
void setFileSize(qint64 fileSize);
const QString &filePath(void) const;
void setFilePath(const QString &filePath);
private:
int m_fileId; /*!< File database identifier. */
QString m_fileName; /*!< File name. */
QString m_fileSizeStr; /*!< Approximate file size string for qml. */
QString m_fileContent; /*!< File content. */
qint64 m_fileSizeBytes; /*!< Real file size in bytes. */
QByteArray m_data; /*!< Binary file content. */
qint64 m_fileSize; /*!< Binary size. */
QString m_filePath; /*!< File path. */
};
......@@ -65,7 +63,7 @@ public:
ROLE_FILE_ID = Qt::UserRole,
ROLE_FILE_NAME,
ROLE_FILE_SIZE_STR,
ROLE_FILE_DATA,
ROLE_BINARY_DATA,
ROLE_FILE_SIZE_BYTES,
ROLE_FILE_PATH
};
......@@ -134,16 +132,15 @@ public:
* @return File path string.
*/
Q_INVOKABLE
QString filePathFromRow(int row);
QString filePathFromRow(int row) const;
/*!
* @brief Return real file size in bytes from attachment model.
* @brief Compute the sum of sizes of all data.
*
* @param[in] row Row specifying the item.
* @return Real file size in bytes.
*/
Q_INVOKABLE
qint64 fileSizeBytesFromRow(int row);
qint64 dataSizeSum(void) const;
/*!
* @brief Returns item flags for given index.
......@@ -161,17 +158,6 @@ public:
*/
void setQuery(QSqlQuery &query);
/*!
* @brief Set the content of the model according to the supplied query.
*
* @note Real file size for model is computed from file content and it
* is included in the model. This method is slow and it is used
* in the send message file model only.
*
* @param[in,out] query SQL query result.
*/
void setQueryWithFileContent(QSqlQuery &query);
/*!
* @brief Appends entry line to model.
*
......@@ -219,12 +205,10 @@ public:
*
* @param[in] userName User name identifying account.
* @param[in] msgIdStr String containing message identifier.
* @param[in] includeRealFileSize True if real file size will include into model.
* @return True on success.
*/
Q_INVOKABLE
bool setFromDb(const QString &userName, const QString &msgIdStr,
bool includeRealFileSize);
bool setFromDb(const QString &userName, const QString &msgIdStr);
/*!
* @brief Remove file from attachment model.
......
......@@ -318,7 +318,7 @@ namespace FlsTbl {
{"dmFormat", DB_TEXT},
{"dmFileMetaType", DB_TEXT},
{"dmEncodedContent", DB_TEXT},
{"_dmFileSize", DB_TEXT},
{"_dmFileSize", DB_INTEGER},
{"_dmDownloadDate", DB_DATETIME},
{"_icon", DB_TEXT}
/*
......@@ -348,7 +348,7 @@ namespace FlsTbl {
{"dmFormat", {DB_TEXT, ""}},
{"dmFileMetaType", {DB_TEXT, ""}},
{"dmEncodedContent", {DB_TEXT, ""}},
{"_dmFileSize", {DB_TEXT, ""}},
{"_dmFileSize", {DB_INTEGER, ""}},
{"_dmDownloadDate", {DB_DATETIME, ""}},
{"_icon", {DB_TEXT, ""}}
};
......
......@@ -147,25 +147,6 @@ void FileDb::setFileModelFromDb(FileListModel &model, const qint64 dmId) const
}
}
void FileDb::setFileModelFromDbWithFileContent(FileListModel &model,
const qint64 dmId) const
{
QSqlQuery query(m_db);
QString queryStr = "SELECT id, dmFileDescr, dmEncodedContent "
"FROM files WHERE dmID = :dmID";
if (!query.prepare(queryStr)) {
logErrorNL("Cannot prepare SQL query: %s",
query.lastError().text().toUtf8().constData());
return;
}
query.bindValue(":dmID", dmId);
if (query.exec() && query.isActive()) {
model.setQueryWithFileContent(query);
}
}
Isds::Document FileDb::getFileFromDb(int fileId) const
{
QSqlQuery query(m_db);
......@@ -296,8 +277,7 @@ bool FileDb::insertUpdateFileIntoDb(qint64 dmId, const Isds::Document &document)
query.bindValue(":dmFileMetaType",
Isds::m_fileMetaType2Variant(document.fileMetaType()));
query.bindValue(":dmEncodedContent", document.base64Content());
query.bindValue(":_dmFileSize",
approximateDataSize(document.binaryContent().size()));
query.bindValue(":_dmFileSize", document.binaryContent().size());
query.bindValue(":_dmDownloadDate",
QDate::currentDate().toString(DATE_DB_FORMAT));
query.bindValue(":_icon",
......@@ -324,18 +304,6 @@ bool FileDb::openDb(const QString &fileName, bool storeToDisk)
return SQLiteDb::openDb(fileName, flags);
}
bool FileDb::vacuumFileDb(void)
{
QSqlQuery query(m_db);
/* Vacuum can take a long time. */
if (query.exec("VACUUM")) {
return true;
}
return false;
}
QList<qint64> FileDb::searchAttachmentName(const QString &phrase) const
{
QSqlQuery query(m_db);
......@@ -377,3 +345,198 @@ QList<class SQLiteTbl *> FileDb::listOfTables(void) const
tables.append(&flsTbl);
return tables;
}
/*!
* @brief Check whether file size is held in an integer-type column.
*
* @param[in] db Database object.
* @return 1 if file size is an INTEGER type
* @return 0 if file size is not an integer type (probably TEXT)
* @return -1 on any error
*/
static
int fileSizeColIsInt(QSqlDatabase &db)
{
QSqlQuery query(db);
QString queryStr("PRAGMA table_info(files)");
if (!query.prepare(queryStr)) {
logErrorNL("Cannot prepare SQL query: %s",
query.lastError().text().toUtf8().constData());
return -1;
}
if (query.exec() && query.isActive()) {
query.first();
while (query.isValid()) {
const int colNum = query.value(0).toInt();
if (colNum == 9) {
const QString colName(query.value(1).toString());
if (colName == QStringLiteral("_dmFileSize")) {
const QString colType(query.value(2).toString());
if (Q_UNLIKELY(colType.isEmpty())) {
return -1;
}
return (colType == QStringLiteral("INTEGER")) ? 1 : 0;
} else {
/* The column with the index 9 is not _dmFileSize. */
return -1;
}
}
query.next();
}
}