137 lines
4.1 KiB
C++
Executable File
137 lines
4.1 KiB
C++
Executable File
/**
|
|
* @RDE_HEADER@
|
|
* Custom db functions (extends tab_db_impl.cpp/.h)
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
*/
|
|
|
|
#include "flm_db_impl_custom.h"
|
|
#include <ngldb/nsqlquery.h>
|
|
#include <ngldb/sql_query_janitor.h>
|
|
#include <QRegularExpression>
|
|
|
|
namespace FileManagement
|
|
{
|
|
// custom procs, body must be implemented by user
|
|
bool DatabaseInterfaceImplCustom::updateStatus(int fileId, const FileStatus &status, int operatorId)
|
|
{
|
|
const QString tableName = getTableName(QStringLiteral("flm_file_content"));
|
|
const QString stmtSelect = QStringLiteral("SELECT name FROM ") + tableName + QStringLiteral(" WHERE id = :id");
|
|
const QString stmtUpdate = QStringLiteral("UPDATE ") + tableName +
|
|
QStringLiteral(" SET file_status_id = :st, name = :name, operator_id = :opId, last_modified = :lastMod") +
|
|
QStringLiteral(" WHERE id = :id;");
|
|
|
|
DEBUG_LOG(m_logger) << "Select statement: " << stmtSelect;
|
|
|
|
DEBUG_LOG(m_logger) << "Update statement: " << stmtUpdate;
|
|
DEBUG_LOG(m_logger) << "File Id = " << fileId;
|
|
DEBUG_LOG(m_logger) << "New status = " << status;
|
|
DEBUG_LOG(m_logger) << "Operator Id = " << operatorId;
|
|
|
|
if (!m_query)
|
|
{
|
|
ERROR_LOG(m_logger) << "m_query not initialized";
|
|
return false;
|
|
}
|
|
|
|
QString fileName;
|
|
|
|
{
|
|
SqlQueryJanitor janitor(m_query);
|
|
|
|
if (!m_query->prepare(stmtSelect))
|
|
{
|
|
ERROR_LOG(m_logger) << "Could not prepare statement: " << stmtSelect;
|
|
return false;
|
|
}
|
|
|
|
m_query->bindValue(QStringLiteral(":id"), fileId);
|
|
|
|
if (!m_query->execAndFetch())
|
|
{
|
|
ERROR_LOG(m_logger) << "Could not execute statement: " << stmtSelect;
|
|
return false;
|
|
}
|
|
|
|
fileName = m_query->value(0).toString();
|
|
} // query scope
|
|
|
|
DEBUG_LOG(m_logger) << "File name before = " << fileName;
|
|
|
|
if (status.underlying() == 1) // Delete
|
|
fileName = QStringLiteral("{")+QString::number(fileId)+QStringLiteral("}_")+fileName;
|
|
if (status.underlying() == 0 && fileName.startsWith(QStringLiteral("{"))) // Restore
|
|
fileName.remove(QRegularExpression(QStringLiteral("^[{](\\d+)[}][_]")));
|
|
|
|
DEBUG_LOG(m_logger) << "File name after = " << fileName;
|
|
|
|
{
|
|
SqlQueryJanitor janitor(m_query);
|
|
|
|
if (!m_query->prepare(stmtUpdate))
|
|
{
|
|
ERROR_LOG(m_logger) << "Could not prepare statement: " << stmtUpdate;
|
|
return false;
|
|
}
|
|
|
|
m_query->bindValue(QStringLiteral(":id"), fileId);
|
|
m_query->bindValue(QStringLiteral(":st"), status.underlying());
|
|
m_query->bindValue(QStringLiteral(":opId"), operatorId);
|
|
m_query->bindValue(QStringLiteral(":lastMod"), QDateTime::currentMSecsSinceEpoch());
|
|
m_query->bindValue(QStringLiteral(":name"), fileName);
|
|
|
|
if (!m_query->exec())
|
|
{
|
|
ERROR_LOG(m_logger) << "Could not execute statement: " << stmtUpdate;
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
} // query scope
|
|
}
|
|
|
|
bool DatabaseInterfaceImplCustom::setUsedBy(int fileId, const bool &usedBy, int usedNo, int operatorId)
|
|
{
|
|
const QString tableName = getTableName(QStringLiteral("flm_file_content"));
|
|
const QString stmtUpdate = QStringLiteral("UPDATE ") + tableName +
|
|
QStringLiteral(" SET is_used_by = :usd, used_by = :useNo, operator_id = :opId, last_modified = :lastMod") +
|
|
QStringLiteral(" WHERE id = :id;");
|
|
|
|
DEBUG_LOG(m_logger) << "Update statement: " << stmtUpdate;
|
|
DEBUG_LOG(m_logger) << "File Id = " << fileId;
|
|
DEBUG_LOG(m_logger) << "Used By = " << usedBy;
|
|
DEBUG_LOG(m_logger) << "Used No = " << usedNo;
|
|
DEBUG_LOG(m_logger) << "Operator Id = " << operatorId;
|
|
|
|
if (!m_query)
|
|
{
|
|
ERROR_LOG(m_logger) << "m_query not initialized";
|
|
return false;
|
|
}
|
|
|
|
SqlQueryJanitor janitor(m_query);
|
|
|
|
if (!m_query->prepare(stmtUpdate))
|
|
{
|
|
ERROR_LOG(m_logger) << "Could not prepare statement: " << stmtUpdate;
|
|
return false;
|
|
}
|
|
|
|
m_query->bindValue(QStringLiteral(":id"), fileId);
|
|
m_query->bindValue(QStringLiteral(":usd"), usedBy);
|
|
m_query->bindValue(QStringLiteral(":useNo"), usedNo);
|
|
m_query->bindValue(QStringLiteral(":opId"), operatorId);
|
|
m_query->bindValue(QStringLiteral(":lastMod"), QDateTime::currentMSecsSinceEpoch());
|
|
|
|
if (!m_query->exec())
|
|
{
|
|
ERROR_LOG(m_logger) << "Could not execute statement: " << stmtUpdate;
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
}
|