MCPcopy Create free account
hub / github.com/KangLin/RabbitRemoteControl / Save

Method Save

Src/Database/Database.cpp:756–814  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

754}
755
756bool CDatabaseFile::Save(const QString &szFile)
757{
758 bool bRet = true;
759 if(szFile.isEmpty()) return false;
760 QFile f(szFile);
761 if(!f.open(QFile::ReadOnly | QFile::Text)) {
762 SetError("Failed to open file: " + szFile
763 + "; Error: " + f.errorString());
764 return false;
765 }
766 QByteArray content = f.readAll();
767 f.close();
768 QFileInfo fi(szFile);
769 QSqlQuery query(GetDatabase());
770 bRet = query.prepare(
771 "SELECT content FROM " + m_szTableName + " "
772 " WHERE file=:file"
773 );
774 if(!bRet) {
775 SetError("Failed to prepare: " + query.executedQuery()
776 + "; Error: " + query.lastError().text());
777 qCritical(log) << GetError();
778 return false;
779 }
780 query.bindValue(":file", fi.fileName());
781 bRet = query.exec();
782 if(!bRet){
783 SetError("Failed to exec: " + query.executedQuery()
784 + "; Error: " + query.lastError().text());
785 qCritical(log) << GetError();
786 return false;
787 }
788 if(query.next()) {
789 query.prepare(
790 "UPDATE " + m_szTableName + " "
791 "SET content = :content "
792 "WHERE file = :file"
793 );
794 query.bindValue(":file", fi.fileName());
795 query.bindValue(":content", content);
796 } else {
797 query.prepare(
798 "INSERT INTO " + m_szTableName + " "
799 "(file, content) "
800 "VALUES (:file, :content)"
801 );
802 query.bindValue(":file", fi.fileName());
803 query.bindValue(":content", content);
804 }
805 bRet = query.exec();
806 if (!bRet) {
807 SetError("Failed to save file to:" + m_szTableName
808 + "; Error: " + query.lastError().text()
809 + "; Sql: " + query.executedQuery());
810 qCritical(log) << GetError();
811 return false;
812 }
813 return bRet;

Callers

nothing calls this directly

Calls 4

errorStringMethod · 0.80
isEmptyMethod · 0.45
openMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected