Revision 40cf6a8c
Von Sebastian Diel vor mehr als 6 Jahren hinzugefügt
- ID 40cf6a8c712767178893a61ab44f3db3d2c9c5ef
- Vorgänger 48379924
EntityManager.pro | ||
---|---|---|
CONFIG += c++14
|
||
tests.depends = src
|
||
samples.depends = tests
|
||
|
samples/example/main.cpp | ||
---|---|---|
EntityInstanceFactory::registerClass<Contact>();
|
||
EntityInstanceFactory::registerClass<Address>();
|
||
CuteEntityManager::EntityManager *e = new
|
||
|
||
|
||
// CuteEntityManager::EntityManager("QSQLITECIPHER",
|
||
// QDir::currentPath() + "/db.sqlite", "", "", "test", 0, true);
|
||
|
||
CuteEntityManager::EntityManager("QSQLITE",
|
||
QDir::currentPath() + "/db.sqlite", "", "", "", 0, true);
|
||
|
||
|
||
// CuteEntityManager::EntityManager("QSQLITE",
|
||
// ":memory:", "", "", "", "", true, "foreign_keys = ON");
|
||
// SqliteBackupProcessor *sqliteproc = new SqliteBackupProcessor(e->getDb(),
|
src/database.cpp | ||
---|---|---|
}
|
||
|
||
void Database::init() {
|
||
// qDebug()<<"db init pre: "<< this->database;
|
||
this->database.open();
|
||
// qDebug()<<"db init post: "<< this->database;
|
||
this->supportTransactions = this->database.driver()->hasFeature(
|
||
QSqlDriver::Transactions);
|
||
}
|
||
... | ... | |
if (this->logger && this->logErrors) {
|
||
this->logger->lastError(query, this->logQueries);
|
||
} else {
|
||
qDebug() << query.executedQuery();
|
||
// qDebug() << query.executedQuery();
|
||
}
|
||
}
|
||
|
src/database.h | ||
---|---|---|
|
||
#ifndef DATABASE_H
|
||
#define DATABASE_H
|
||
//#include "../../../../QtCipherSqlitePlugin/QtCipherSqlitePlugin/sqlitecipher/sqlite3/sqlite3.h"
|
||
//#include "../../../../QtCipherSqlitePlugin/QtCipherSqlitePlugin/sqlitecipher/sqlite3/sqlite3ext.h"
|
||
#include <QtSql/QSqlDatabase>
|
||
#include <QtSql/QSqlDriver>
|
||
#include <QtSql/QSqlQuery>
|
||
... | ... | |
static Schema *getSchema(DatabaseType db,
|
||
QSharedPointer<Database> database);
|
||
Logger *getLogger() const;
|
||
QSqlDatabase getQSqlDatabase() {return database;}
|
||
private:
|
||
QSqlDatabase database;
|
||
QString connectionName;
|
src/entityinspector.cpp | ||
---|---|---|
|
||
bool EntityInspector::checkRegisteredEntities() {
|
||
QStringList classes = EntityInstanceFactory::getRegisteredClasses();
|
||
classes.sort();
|
||
QString msg = QDateTime::currentDateTime().toString(Qt::ISODate) +
|
||
" - Start checking entities\n";
|
||
this->logger->logMsg(msg, MsgType::INFO);
|
||
... | ... | |
void EntityInspector::checkMetaProperties(QHash<QString, QMetaProperty>
|
||
&metaProperties, bool &ok, QHash<QString, Relation> &relations) {
|
||
QString msg = "";
|
||
for (auto i = metaProperties.constBegin(); i != metaProperties.constEnd();
|
||
++i) {
|
||
|
||
#ifdef DIFFABLEOUTPUT
|
||
QMap<QString, QMetaProperty> metaPropertiesMap;
|
||
for (auto i = metaProperties.constBegin(); i != metaProperties.constEnd();
|
||
++i) {
|
||
metaPropertiesMap[i.key()] = i.value();
|
||
}
|
||
for (auto i = metaPropertiesMap.constBegin(); i != metaPropertiesMap.constEnd(); i++) {
|
||
#else
|
||
for (auto i = metaProperties.constBegin(); i != metaProperties.constEnd();
|
||
++i) {
|
||
#endif
|
||
QString typeName = QString(i.value().typeName());
|
||
if (!i.value().isWritable()) {
|
||
ok = false;
|
||
... | ... | |
auto relations = entity->getRelations();
|
||
QString msg = "";
|
||
this->checkMetaProperties(metaProperties, ok, relations);
|
||
for (auto i = relations.constBegin(); i != relations.constEnd(); ++i) {
|
||
#ifdef DIFFABLEOUTPUT
|
||
QMap<QString, Relation> relationsMap;
|
||
for (auto i = relations.constBegin(); i != relations.constEnd(); i++) {
|
||
relationsMap[i.key()] = i.value();
|
||
}
|
||
for (auto i = relationsMap.constBegin(); i != relationsMap.constEnd(); ++i) {
|
||
#else
|
||
for (auto i = relations.constBegin(); i != relations.constEnd(); ++i) {
|
||
#endif
|
||
|
||
this->checkRelationTypos(i.key(), i.value(), ok);
|
||
if (!metaProperties.contains(i.key())) {
|
||
msg += "For relation " + i.key() + " no property exists!";
|
src/entityinspector.h | ||
---|---|---|
*/
|
||
#ifndef ENTITYINSPECTOR_H
|
||
#define ENTITYINSPECTOR_H
|
||
#define DIFFABLEOUTPUT
|
||
#include <QString>
|
||
#include <QHash>
|
||
#include "entity.h"
|
src/entitymanager.cpp | ||
---|---|---|
EntityManager::EntityManager(QSqlDatabase database, bool logQueries,
|
||
const bool inspectEntities,
|
||
MsgType logActions) : QObject() {
|
||
// Q_IMPORT_PLUGIN(SqliteCipherDriverPlugin)
|
||
this->db = QSharedPointer<Database>(new Database(database, true, logQueries, logActions));
|
||
this->init(inspectEntities, logActions);
|
||
}
|
||
... | ... | |
databasename, username,
|
||
password,
|
||
port.toInt(), true, logQueries, databaseOptions, logActions));
|
||
|
||
this->init(inspectEntities, logActions);
|
||
}
|
||
|
||
... | ... | |
QList<Entity *> &mergedObjects, const bool persistRelations,
|
||
const bool ignoreHasChanged, const bool validate,
|
||
const bool relationsIgnoreHasChanged) {
|
||
static bool out = false;
|
||
if (entity.data()->metaObject()->className() == QByteArray("TestPupilGreatGrandChild")) {
|
||
qDebug()<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
|
||
out = true;
|
||
}
|
||
bool merged = mergedObjects.contains(entity.data());
|
||
std::sort(mergedObjects.begin(), mergedObjects.end(), lessThanEntity);
|
||
if (entity && !merged && (ignoreHasChanged || this->hasChanged(entity))) {
|
||
if (entity->getProperty(entity->getPrimaryKey()).toLongLong() > -1) {
|
||
return this->mergeObject(entity, mergedObjects, persistRelations, validate,
|
||
... | ... | |
bool EntityManager::mergeObject(QSharedPointer<Entity> &entity,
|
||
QList<Entity *> &mergedObjects, bool withRelations, const bool validate,
|
||
const bool relationsIgnoreHasChanged) {
|
||
static bool out = false;
|
||
if (entity.data()->metaObject()->className() == QByteArray("TestPupilGreatGrandChild")) {
|
||
qDebug()<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
|
||
out = true;
|
||
}
|
||
bool ok = true;
|
||
std::sort(mergedObjects.begin(), mergedObjects.end(), lessThanEntity);
|
||
if (entity && !mergedObjects.contains(entity.data())) {
|
||
mergedObjects.append(entity.data());
|
||
ok = false;
|
||
... | ... | |
this->savePrePersistedRelations(entity, mergedObjects,
|
||
relationsIgnoreHasChanged);
|
||
}
|
||
qDebug()<<"mergeObject startTransaction";
|
||
this->db->startTransaction();
|
||
QList<QSqlQuery> q = this->schema->getQueryBuilder()->merge(
|
||
entity);
|
||
... | ... | |
this->savePrePersistedRelations(entity, mergedObjects,
|
||
relationsIgnoreHasChanged);
|
||
}
|
||
qDebug()<<"createObject startTransaction";
|
||
this->db->startTransaction();
|
||
QList<QSqlQuery> q = this->schema->getQueryBuilder()->create(
|
||
entity);
|
||
... | ... | |
|
||
bool EntityManager::startup(QString version, QStringList toInitialize,
|
||
bool createIndices) {
|
||
|
||
// #ifdef DIFFABLEOUTPUT
|
||
qSetGlobalQHashSeed(0);
|
||
// #endif
|
||
|
||
QSharedPointer<Entity> dbm = QSharedPointer<DatabaseMigration>
|
||
(new DatabaseMigration());
|
||
QHash<QString, QVariant> map = QHash<QString, QVariant>();
|
||
... | ... | |
}
|
||
}
|
||
|
||
bool EntityManager::lessThanEntity( Entity* &a, Entity* &b) {
|
||
if (a->metaObject()->className() == b->metaObject()->className()) {
|
||
return a->getId() < b->getId();
|
||
} else {
|
||
return a->metaObject()->className() < b->metaObject()->className();
|
||
}
|
||
}
|
||
|
||
void EntityManager::savePrePersistedRelations(const QSharedPointer<Entity>
|
||
&mainEntityToBeSaved, QList<Entity *> &mergedObjects, bool ignoreHasChanged) {
|
||
static bool out = false;
|
||
if (mainEntityToBeSaved.data()->metaObject()->className() == QByteArray("TestPupilGreatGrandChild")) {
|
||
qDebug()<<"~~~~~~~~~~~~~savePrePersistedRelations~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
|
||
out = true;
|
||
}
|
||
if (out) {
|
||
std::sort(mergedObjects.begin(), mergedObjects.end(), lessThanEntity);
|
||
}
|
||
if (out) qDebug()<<"savePrePersistedRelations: "<<mainEntityToBeSaved->metaObject()->className()<<", mO: "<<mergedObjects.count();
|
||
auto relations = EntityHelper::getRelationProperties(mainEntityToBeSaved.data());
|
||
auto relationIterator = relations.constBegin();
|
||
while (relationIterator != relations.constEnd()) {
|
||
if(out) qDebug()<<"relationProperties: "<<relations.count();
|
||
QMap<Relation, QMetaProperty> relationsMap;
|
||
|
||
for (auto i = relations.begin(); i != relations.end(); i++ ) {
|
||
relationsMap.insert(i.key(), i.value());
|
||
}
|
||
|
||
|
||
auto relationIterator = relationsMap.constBegin();
|
||
while (relationIterator != relationsMap.constEnd()) {
|
||
const Relation relation = relationIterator.key();
|
||
const QMetaProperty relationProperty = relationIterator.value();
|
||
if (out) qDebug()<<"Relation.key: "<<relation.getPropertyName()<<", value: "<<relationIterator.value().typeName();
|
||
auto varFromRelationsValue = relationProperty.read(mainEntityToBeSaved.data());
|
||
if (out) qDebug()<< "varFromRelationsValueNull? "<<varFromRelationsValue.isNull() <<", "<<varFromRelationsValue;
|
||
if(!varFromRelationsValue.isNull() && varFromRelationsValue.data()) {
|
||
if(out) qDebug()<< "relationType is "<<int(relation.getType());
|
||
if (relation.getType() == RelationType::MANY_TO_ONE) {
|
||
if (out) qDebug()<<"MANY_TO_ONE";
|
||
auto relationEntity = EntityInstanceFactory::castQVariant(varFromRelationsValue);
|
||
if (relationEntity && this->shouldBeSaved(relationEntity, relation)) {
|
||
if (out) qDebug()<< "relationEntity->metaObject()->className(): "<<relationEntity->metaObject()->className();
|
||
if (out) qDebug()<< "into recursion:";
|
||
// into recursion:
|
||
this->saveObject(relationEntity, mergedObjects, true, ignoreHasChanged);
|
||
|
||
bool r;
|
||
r= this->saveObject(relationEntity, mergedObjects, true, ignoreHasChanged);
|
||
if (out) qDebug()<< "saveObjectm21: "<<r<<" ("<<relationEntity->metaObject()->className()<<")";
|
||
// Is this mapped by the opposite party?
|
||
auto foreignKeyProp = EntityHelper::mappedProperty(relation, relationEntity);
|
||
if (foreignKeyProp.isValid()) {
|
||
// fixes ticket #629
|
||
auto relations = relationEntity->getRelations();
|
||
auto i = relations.constBegin();
|
||
while(i != relations.constEnd()) {
|
||
QMap<QString, Relation> relationsMap;
|
||
for (auto i = relations.begin(); i != relations.end(); i++ ) {
|
||
relationsMap.insert(i.key(), i.value());
|
||
}
|
||
if (out) qDebug() << "foreignKeyProp.isValid()m21, "<<relations.count()<<" relations";
|
||
auto i = relationsMap.constBegin();
|
||
while(i != relationsMap.constEnd()) {
|
||
QString foreignKeyPropString = QString(foreignKeyProp.name());
|
||
if (out) qDebug()<< "is "<<foreignKeyPropString<<" mapping this?";
|
||
if(i.value().getMappedBy() == foreignKeyPropString) {
|
||
if (out) qDebug()<< "yes";
|
||
EntityHelper::addEntityToListProperty(relationEntity, mainEntityToBeSaved, foreignKeyProp);
|
||
break;
|
||
}
|
||
} else if (out) qDebug()<< "no";
|
||
++i;
|
||
}
|
||
}
|
||
}
|
||
} else if (relation.getType() == RelationType::ONE_TO_ONE
|
||
&& relation.getMappedBy().isEmpty()) {
|
||
if (out) qDebug()<<"ONE_TO_ONE";
|
||
auto e = EntityInstanceFactory::castQVariant(varFromRelationsValue);
|
||
if(e) {
|
||
this->saveObject(e, mergedObjects, true, ignoreHasChanged);
|
||
if (out) qDebug()<<"saving "<<e->metaObject()->className();
|
||
bool r;
|
||
r = this->saveObject(e, mergedObjects, true, ignoreHasChanged);
|
||
if (out) qDebug()<<"saving "<<e->metaObject()->className()<<" resulted in "<<r;
|
||
auto prop = EntityHelper::mappedProperty(relation, e);
|
||
if (out) qDebug()<<"prop: "<<prop.name()<<"/"<<prop.typeName();
|
||
EntityHelper::setProperty(e, mainEntityToBeSaved, prop);
|
||
}
|
||
}
|
||
... | ... | |
}
|
||
|
||
void EntityManager::savePostPersistedRelations(const QSharedPointer<Entity>
|
||
&entity, QList<Entity *> &mergedObjects, bool ignoreHasChanged, bool newItem) {
|
||
&entity, QList<Entity *> &mergedObjects, bool ignoreHasChanged, bool newItem
|
||
, bool forceOut) {
|
||
static bool out = false;
|
||
if (entity.data()->metaObject()->className() == QByteArray("TestPupilGreatGrandChild")) {
|
||
qDebug()<<"~~~~~~~~~~~~~~savePostPersistedRelations~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
|
||
out = true;
|
||
}
|
||
if (forceOut) {
|
||
qDebug()<< "~~~~~~~~~~~~~~~~~~~~savePostPersistedRelations FORCEOUT~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
|
||
out = true;
|
||
}
|
||
if (out) qDebug()<<"savePostPersistedRelations: "<<entity->metaObject()->className()<<", mO: "<<mergedObjects.count()<<", new: "<<newItem;
|
||
auto relations = EntityHelper::getRelationProperties(entity.data());
|
||
if (out) qDebug()<<"relationProperties: "<<relations.count();
|
||
for (auto i = relations.constBegin(); i != relations.constEnd(); ++i) {
|
||
if (out) qDebug()<<"Relation.key: "<<i.key().getPropertyName()<<", value: "<<i.value().typeName();
|
||
const Relation r = i.key();
|
||
auto var = i.value().read(entity.data());
|
||
if (r.getType() == RelationType::MANY_TO_MANY) {
|
||
if (out) qDebug()<<"MANY_TO_MANY";
|
||
this->persistManyToMany(entity, r, var, mergedObjects, ignoreHasChanged,
|
||
newItem);
|
||
} else if (r.getType() == RelationType::ONE_TO_MANY && var.canConvert<QList<QVariant>>()) {
|
||
if (out) qDebug()<<"ONE_TO_MANY";
|
||
QList<QSharedPointer<Entity>> list = EntityInstanceFactory::castQVariantList(
|
||
var);
|
||
if (!list.isEmpty()) {
|
||
if (out) qDebug()<<"is NOT Empty12m";
|
||
auto foreignKeyProp = EntityHelper::mappedProperty(r, list.at(0));
|
||
if (out) qDebug()<<"foreignKeyProp12m: "<<foreignKeyProp.name()<<"/"<<foreignKeyProp.typeName();
|
||
for (int var = 0; var < list.size(); ++var) {
|
||
auto e = list.at(var);
|
||
if (out) qDebug()<<"e->metaObject()->className()12m: "<<e->metaObject()->className();
|
||
if (e && this->shouldBeSaved(e, r)) {
|
||
if (out) qDebug()<<"shouldBeSaved";
|
||
EntityHelper::setProperty(e, entity, foreignKeyProp);
|
||
this->saveObject(e, mergedObjects, true, ignoreHasChanged);
|
||
bool r;
|
||
r = this->saveObject(e, mergedObjects, true, ignoreHasChanged);
|
||
if (out) qDebug()<<"saveObject12m: "<<r<<" ("<<e->metaObject()->className()<<")";
|
||
}
|
||
}
|
||
}
|
||
} else if (r.getType() == RelationType::ONE_TO_ONE
|
||
&& !r.getMappedBy().isEmpty()) {
|
||
if (out) qDebug()<<"ONE_TO_ONE";
|
||
auto e = EntityInstanceFactory::castQVariant(var);
|
||
if(e) {
|
||
auto foreignKeyProp = EntityHelper::mappedProperty(r, e);
|
||
if (out) qDebug()<<"foreignKeyProp121: "<<foreignKeyProp.name()<<"/"<<foreignKeyProp.typeName();
|
||
if (out) qDebug()<<"e->metaObject()->className()121: "<<e->metaObject()->className();
|
||
EntityHelper::setProperty(e, entity, foreignKeyProp);
|
||
this->saveObject(e, mergedObjects, true, ignoreHasChanged);
|
||
bool r;
|
||
r = this->saveObject(e, mergedObjects, true, ignoreHasChanged);
|
||
if (out) qDebug()<<"saveObject121: "<<r<<" ("<<e->metaObject()->className()<<")";
|
||
}
|
||
}
|
||
}
|
src/entitymanager.h | ||
---|---|---|
|
||
#ifndef ENTITYMANAGER_H
|
||
#define ENTITYMANAGER_H
|
||
#define DIFFABLEOUTPUT
|
||
#include <QtSql/QSqlDatabase>
|
||
#include <QtSql/QSqlRecord>
|
||
#include <QtSql/QSqlField>
|
||
... | ... | |
return newList;
|
||
}
|
||
|
||
protected:
|
||
static bool lessThanEntity(Entity *&a, Entity *&b);
|
||
protected:
|
||
bool saveObject(QSharedPointer<Entity> &entity, QList<Entity *> &mergedObjects,
|
||
const bool persistRelations = true,
|
||
const bool ignoreHasChanged = false, const bool validate = true,
|
||
... | ... | |
*/
|
||
void savePostPersistedRelations(const QSharedPointer<Entity> &entity,
|
||
QList<Entity *> &mergedObjects, bool ignoreHasChanged = false,
|
||
bool newItem = false);
|
||
bool newItem = false, bool forceOut = false);
|
||
|
||
QList<QSharedPointer<Entity>> saveRelationEntities(const
|
||
QList<QSharedPointer<Entity>> &list, const Relation &r,
|
src/logger.cpp | ||
---|---|---|
if (logQuery || q.lastError().isValid()) {
|
||
const QString errorMsg = this->generateLogMsg(q.lastError());
|
||
if (logQuery || !errorMsg.isEmpty()) {
|
||
QString msg = "{" + QString("\"time\":\"") +
|
||
QDateTime::currentDateTime().toString(Qt::ISODate) + QString("\"") + errorMsg;
|
||
// QString msg = "{" + QString("\"time\":\"") +
|
||
// QDateTime::currentDateTime().toString(Qt::ISODate) + QString("\"") + errorMsg;
|
||
QString timeStamp;
|
||
#ifndef DIFFABLEOUTPUT
|
||
timeStamp = QString("\"time\":\"") +
|
||
QDateTime::currentDateTime().toString(Qt::ISODate) + QString("\"");
|
||
#endif
|
||
QString msg = "{" + timeStamp + errorMsg;
|
||
|
||
msg += this->generateLogMsg(q) + "}";
|
||
this->logMsg(msg, errorMsg.isEmpty() ? MsgType::DEBUG : MsgType::WARNING);
|
||
}
|
src/logger.h | ||
---|---|---|
*/
|
||
#ifndef LOGGER_H
|
||
#define LOGGER_H
|
||
|
||
#define DIFFABLEOUTPUT
|
||
#include <QString>
|
||
#include <QFile>
|
||
#include <QSqlError>
|
||
... | ... | |
class Logger {
|
||
#ifdef QT_DEBUG
|
||
#define DEFAULTMSGTYPE MsgType::DEBUG
|
||
//#define DIFFABLEOUTPUT
|
||
#else
|
||
#define DEFAULTMSGTYPE MsgType::CRITICAL
|
||
#endif
|
||
|
||
|
||
public:
|
||
Logger(QString path = "", MsgType min = DEFAULTMSGTYPE);
|
||
~Logger();
|
src/relation.cpp | ||
---|---|---|
}
|
||
|
||
|
||
|
src/relation.h | ||
---|---|---|
QList<CascadeType> getCascadeType() const;
|
||
void setCascadeType(const QList<CascadeType> &value);
|
||
|
||
// bool operator<(const CuteEntityManager::Relation b);
|
||
// bool operator<(const CuteEntityManager::Relation* b);
|
||
// bool operator<(const CuteEntityManager::Relation& b);
|
||
|
||
|
||
inline bool operator<(const CuteEntityManager::Relation b) const
|
||
{
|
||
return this->propertyName < b.propertyName;
|
||
}
|
||
|
||
// inline bool operator<(const CuteEntityManager::Relation* b) const
|
||
// {
|
||
// return this->propertyName < b->propertyName;
|
||
// }
|
||
|
||
// inline bool operator<(const CuteEntityManager::Relation &b) const
|
||
// {
|
||
// return this->propertyName < b.propertyName;
|
||
// }
|
||
|
||
// inline bool operator <(const Relation& a, const Relation& b);
|
||
// inline bool operator <(const CuteEntityManager::Relation &a, const CuteEntityManager::Relation &b)
|
||
// {
|
||
// return a.propertyName < b.propertyName;
|
||
// }
|
||
|
||
|
||
protected:
|
||
QString propertyName;
|
||
QString mappedBy;
|
src/sqlitebackupprocessor.cpp | ||
---|---|---|
* You should have received a copy of the GNU Lesser General Public License
|
||
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||
*/
|
||
//#include "../../../../../../QtCipherSqlitePlugin/QtCipherSqlitePlugin/sqlitecipher/sqlite3/sqlite3ext.h"
|
||
//#include "../../../../../../QtCipherSqlitePlugin/QtCipherSqlitePlugin/sqlitecipher/sqlite3/sqlite3.h"
|
||
//#include "../../../../../../QtCipherSqlitePlugin/QtCipherSqlitePlugin/sqlitecipher/sqlite3/sqlite3userauth.h"
|
||
//#include "../../../../../../QtCipherSqlitePlugin/QtCipherSqlitePlugin/sqlitecipher/sqlite3/rijndael.h"
|
||
//#include "../../../../../../QtCipherSqlitePlugin/QtCipherSqlitePlugin/sqlitecipher/sqlite3/sha2.h"
|
||
//#include "../../../../../../QtCipherSqlitePlugin/QtCipherSqlitePlugin/sqlitecipher/sqlitecipher_p.h"
|
||
//#include "../../../../../../QtCipherSqlitePlugin/QtCipherSqlitePlugin/sqlitecipher/sqlitecipher_global.h"
|
||
//#include "../../../../../../QtCipherSqlitePlugin/QtCipherSqlitePlugin/sqlitecipher/sqlitechipher_global.h"
|
||
//#include "../../../../../../QtCipherSqlitePlugin/QtCipherSqlitePlugin/sqlitecipher/sqlcachedresult_p.h"
|
||
|
||
#include "sqlitebackupprocessor.h"
|
||
#include <sqlite3.h>
|
||
#include <QFileInfoList>
|
||
... | ... | |
*/
|
||
bool SqliteBackupProcessor::sqliteDBMemFile(bool save, QString fileName) {
|
||
bool state = false;
|
||
// qDebug()<<"111";
|
||
QVariant v = this->database->getDatabase().driver()->handle();
|
||
if ( v.isValid() && qstrcmp(v.typeName(), "sqlite3*") == 0 ) {
|
||
// qDebug()<<"222";
|
||
// v.data() returns a pointer to the handle
|
||
sqlite3 *handle = *static_cast<sqlite3 **>(v.data());
|
||
if ( handle != 0 ) { // check that it is not NULL
|
||
// qDebug()<<"333";
|
||
sqlite3 *pInMemory = handle;
|
||
QByteArray array = QString(this->destination + "/" + fileName).toLocal8Bit();
|
||
const char *zFilename = array.data();
|
||
// const char *zFilename = array.data();
|
||
const char *zFilename = array;
|
||
int rc; /* Function return code */
|
||
sqlite3 *pFile; /* Database connection opened on zFilename */
|
||
/* Open the database file identified by zFilename. Exit early if this fails
|
||
** for any reason. */
|
||
rc = sqlite3_open( zFilename, &pFile );
|
||
// pFile->setPassword("test");
|
||
// sqlite3_key(pFile, "test", strlen("test"));
|
||
// qDebug()<<"keyrc: "<<keyrc;
|
||
|
||
if ( rc == SQLITE_OK ) {
|
||
// qDebug()<<"444";
|
||
sqlite3_backup *pBackup; /* Backup object used to copy data */
|
||
sqlite3 *pTo; /* Database to copy to (pFile or pInMemory) */
|
||
sqlite3 *pFrom; /* Database to copy from (pFile or pInMemory) */
|
||
... | ... | |
** and return the result of this function. */
|
||
(void)sqlite3_close(pFile);
|
||
if ( rc == SQLITE_OK ) {
|
||
// qDebug()<<"666";
|
||
state = true;
|
||
}
|
||
}
|
src/sqlitebackupprocessor.h | ||
---|---|---|
#ifndef SQLITEBACKUPPROCESSOR_H
|
||
#define SQLITEBACKUPPROCESSOR_H
|
||
|
||
#define SQLITE_HAS_CODEC
|
||
|
||
#include <QObject>
|
||
#include <QtSql/QSqlDriver>
|
||
#include <QString>
|
src/src.pro | ||
---|---|---|
attributeresolver.cpp
|
||
|
||
windows|android: {
|
||
# DEFINES += SQLITE_HAS_CODEC SQLITE_TEMP_STORE=2
|
||
DEFINES += SQLITE_OMIT_LOAD_EXTENSION SQLITE_OMIT_COMPLETE SQLITE_ENABLE_FTS3 SQLITE_ENABLE_FTS3_PARENTHESIS SQLITE_ENABLE_RTREE
|
||
!contains(CONFIG, largefile):DEFINES += SQLITE_DISABLE_LFS
|
||
INCLUDEPATH += $$[QT_INSTALL_PREFIX]/../Src/qtbase/src/3rdparty/sqlite
|
||
SOURCES += $$[QT_INSTALL_PREFIX]/../Src/qtbase/src/3rdparty/sqlite/sqlite3.c
|
||
|
||
# INCLUDEPATH += C:/Users/SeDi/cpp/QtCipherSqlitePlugin/QtCipherSqlitePlugin/sqlitecipher/sqlite3
|
||
# SOURCES += C:/Users/SeDi/cpp/QtCipherSqlitePlugin/QtCipherSqlitePlugin/sqlitecipher/sqlite3/sqlite3.c
|
||
|
||
|
||
}
|
||
unix:!android: {
|
||
system-sqlite:!contains(LIBS, .*sqlite3.*) {
|
Auch abrufbar als: Unified diff
debugging heritage