mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-09-13 20:23:04 +02:00
Test
This commit is contained in:
parent
6652401d07
commit
8be1e207b8
@ -207,6 +207,7 @@ TARGET = qelectrotech
|
|||||||
|
|
||||||
# Ajustement des bibliotheques utilisees lors de l'edition des liens
|
# Ajustement des bibliotheques utilisees lors de l'edition des liens
|
||||||
unix:QMAKE_LIBS_THREAD -= -lpthread
|
unix:QMAKE_LIBS_THREAD -= -lpthread
|
||||||
|
unix|win32: LIBS += -lsqlite3
|
||||||
|
|
||||||
# Enable C++11
|
# Enable C++11
|
||||||
QMAKE_CXXFLAGS += -std=c++11
|
QMAKE_CXXFLAGS += -std=c++11
|
||||||
|
@ -24,6 +24,8 @@
|
|||||||
#include "diagramposition.h"
|
#include "diagramposition.h"
|
||||||
|
|
||||||
#include <QSqlError>
|
#include <QSqlError>
|
||||||
|
#include <QSqlDriver>
|
||||||
|
#include <sqlite3.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief projectDataBase::projectDataBase
|
* @brief projectDataBase::projectDataBase
|
||||||
@ -38,13 +40,6 @@ projectDataBase::projectDataBase(QETProject *project, QObject *parent) :
|
|||||||
createDataBase();
|
createDataBase();
|
||||||
}
|
}
|
||||||
|
|
||||||
projectDataBase::projectDataBase(QETProject *project, const QString &connection_name, const QString &path, QObject *parent) :
|
|
||||||
QObject(parent),
|
|
||||||
m_project(project)
|
|
||||||
{
|
|
||||||
createDataBase(connection_name, path);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief projectDataBase::~projectDataBase
|
* @brief projectDataBase::~projectDataBase
|
||||||
* Destructor
|
* Destructor
|
||||||
@ -91,20 +86,9 @@ QSqlQuery projectDataBase::newQuery(const QString &query) {
|
|||||||
* Create the data base
|
* Create the data base
|
||||||
* @return : true if the data base was successfully created.
|
* @return : true if the data base was successfully created.
|
||||||
*/
|
*/
|
||||||
bool projectDataBase::createDataBase(const QString &connection_name, const QString &name)
|
bool projectDataBase::createDataBase()
|
||||||
{
|
{
|
||||||
|
m_data_base = QSqlDatabase::addDatabase("QSQLITE", "qet_project_db_" + m_project->uuid().toString());
|
||||||
QString connect_name = connection_name;
|
|
||||||
if (connect_name.isEmpty()) {
|
|
||||||
connect_name = "qet_project_db_" + m_project->uuid().toString();
|
|
||||||
}
|
|
||||||
if (m_data_base.connectionNames().contains(connect_name)) {
|
|
||||||
m_data_base = QSqlDatabase::database(connect_name);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
m_data_base = QSqlDatabase::addDatabase("QSQLITE", connect_name);
|
|
||||||
m_data_base.setDatabaseName(name);
|
|
||||||
if(!m_data_base.open()) {
|
if(!m_data_base.open()) {
|
||||||
m_data_base.close();
|
m_data_base.close();
|
||||||
return false;
|
return false;
|
||||||
@ -177,7 +161,6 @@ bool projectDataBase::createDataBase(const QString &connection_name, const QStri
|
|||||||
|
|
||||||
createElementNomenclatureView();
|
createElementNomenclatureView();
|
||||||
createSummaryView();
|
createSummaryView();
|
||||||
}
|
|
||||||
|
|
||||||
updateDB();
|
updateDB();
|
||||||
return true;
|
return true;
|
||||||
@ -432,8 +415,38 @@ void projectDataBase::exportDb(projectDataBase *db, QWidget *parent, const QStri
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Database is filled at creation, work is done.
|
|
||||||
QString connection_name("export_project_db_" + db->project()->uuid().toString());
|
QString connection_name("export_project_db_" + db->project()->uuid().toString());
|
||||||
projectDataBase file_db(db->project(), connection_name, path_);
|
|
||||||
|
if (true) //Enter in a scope only to nicely use QSqlDatabase::removeDatabase just after the end of the scope
|
||||||
|
{
|
||||||
|
auto file_db = QSqlDatabase::addDatabase("QSQLITE", connection_name);
|
||||||
|
file_db.setDatabaseName(path_);
|
||||||
|
if (!file_db.open()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto memory_db_handle = sqliteHandle(&db->m_data_base);
|
||||||
|
auto file_db_handle = sqliteHandle(&file_db);
|
||||||
|
|
||||||
|
auto sqlite_backup = sqlite3_backup_init(file_db_handle, "main", memory_db_handle, "main");
|
||||||
|
if (sqlite_backup)
|
||||||
|
{
|
||||||
|
sqlite3_backup_step(sqlite_backup, -1);
|
||||||
|
sqlite3_backup_finish(sqlite_backup);
|
||||||
|
}
|
||||||
|
file_db.close();
|
||||||
|
}
|
||||||
QSqlDatabase::removeDatabase(connection_name);
|
QSqlDatabase::removeDatabase(connection_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sqlite3 *projectDataBase::sqliteHandle(QSqlDatabase *db)
|
||||||
|
{
|
||||||
|
sqlite3 *handle = nullptr;
|
||||||
|
|
||||||
|
QVariant v = db->driver()->handle();
|
||||||
|
if (v.isValid() && qstrcmp(v.typeName(), "sqlite3*") == 0) {
|
||||||
|
handle = *static_cast<sqlite3 **>(v.data());
|
||||||
|
}
|
||||||
|
|
||||||
|
return handle;
|
||||||
|
}
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
|
|
||||||
class Element;
|
class Element;
|
||||||
class QETProject;
|
class QETProject;
|
||||||
|
class sqlite3;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The projectDataBase class
|
* @brief The projectDataBase class
|
||||||
@ -40,9 +41,6 @@ class projectDataBase : public QObject
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
projectDataBase(QETProject *project, QObject *parent = nullptr);
|
projectDataBase(QETProject *project, QObject *parent = nullptr);
|
||||||
private:
|
|
||||||
projectDataBase(QETProject *project, const QString &connection_name, const QString &path, QObject *parent = nullptr);
|
|
||||||
public:
|
|
||||||
virtual ~projectDataBase() override;
|
virtual ~projectDataBase() override;
|
||||||
|
|
||||||
void updateDB();
|
void updateDB();
|
||||||
@ -53,7 +51,7 @@ class projectDataBase : public QObject
|
|||||||
void dataBaseUpdated();
|
void dataBaseUpdated();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool createDataBase(const QString &connection_name= QString(), const QString &name = QString());
|
bool createDataBase();
|
||||||
void createElementNomenclatureView();
|
void createElementNomenclatureView();
|
||||||
void createSummaryView();
|
void createSummaryView();
|
||||||
void populateDiagramTable();
|
void populateDiagramTable();
|
||||||
@ -61,6 +59,7 @@ class projectDataBase : public QObject
|
|||||||
void populateElementInfoTable();
|
void populateElementInfoTable();
|
||||||
void populateDiagramInfoTable();
|
void populateDiagramInfoTable();
|
||||||
static QHash<QString, QString> elementInfoToString(Element *elmt);
|
static QHash<QString, QString> elementInfoToString(Element *elmt);
|
||||||
|
static sqlite3 *sqliteHandle(QSqlDatabase *db);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QPointer<QETProject> m_project;
|
QPointer<QETProject> m_project;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user