mirror of
https://gitlab.com/spaceti-app/integrations/common/server-sdk.git
synced 2026-07-12 12:00:46 +02:00
emitting error when SQL error
This commit is contained in:
parent
eddfc401b0
commit
99089d1b12
@ -128,6 +128,7 @@ QSqlQuery DatabaseManager::processResult(int res, const QSqlQuery &query) const
|
||||
QString msg = QString("Source: Database Manager \nError --------\n%1\nSQL-------\n%2\n--------")
|
||||
.arg(query.lastError().text(), query.lastQuery());
|
||||
qCDebug(sdkdb).noquote() << msg;
|
||||
emit sqlError(query);
|
||||
log(msg);
|
||||
}
|
||||
return query;
|
||||
|
||||
@ -45,7 +45,7 @@ private:
|
||||
void log(const QString &msg) const;
|
||||
|
||||
signals:
|
||||
void error();
|
||||
void sqlError(const QSqlQuery &query);
|
||||
|
||||
private:
|
||||
QString mConnectionName;
|
||||
|
||||
@ -5,7 +5,6 @@
|
||||
#include "serversdk/core.h"
|
||||
// add necessary includes here
|
||||
|
||||
|
||||
class Name : public serversdk::DatabaseTable {
|
||||
Q_OBJECT
|
||||
TABLE_PROPERTY(QString, uuid, set_uuid, QString());
|
||||
@ -26,6 +25,7 @@ private slots:
|
||||
void createDb_test();
|
||||
void createTable_test();
|
||||
void updateTable_test();
|
||||
void fail_updateTable_test();
|
||||
};
|
||||
|
||||
|
||||
@ -124,8 +124,8 @@ void SqliteTest::updateTable_test()
|
||||
name_B.set_name("TestnameB");
|
||||
|
||||
|
||||
utils.insertIntoTable(&name_A, "names");
|
||||
utils.insertIntoTable(&name_B, "names");
|
||||
QVERIFY2(utils.insertIntoTable(&name_A, "names").isActive(), "Successfull insert must return isActive sqlQuery");
|
||||
QVERIFY2(utils.insertIntoTable(&name_B, "names").isActive(), "Successfull insert must return isActive sqlQuery");
|
||||
|
||||
|
||||
// NOW UPDATING TABLE WITH name: NewName
|
||||
@ -148,6 +148,35 @@ void SqliteTest::updateTable_test()
|
||||
QCOMPARE(dbB->jsonData(), name_B.jsonData());
|
||||
}
|
||||
|
||||
/** # Fail Update test
|
||||
*
|
||||
* Test isActive must be FALSE when not possible to update database table
|
||||
*/
|
||||
void SqliteTest::fail_updateTable_test()
|
||||
{
|
||||
// Prepare temporary path for database
|
||||
QTemporaryDir dir;
|
||||
QString dbpath = dir.path() + "/testdb.sqlite";
|
||||
serversdk::DatabaseManager db;
|
||||
db.openSQLite(dbpath);
|
||||
QVERIFY(db.isOpen());
|
||||
|
||||
Name name_A, name_B;
|
||||
|
||||
// CREATE TABLE
|
||||
serversdk::DatabaseUtils utils(&db);
|
||||
QSqlQuery query = utils.createTable(&name_A, "names");
|
||||
|
||||
// INSERT INTO TABLE
|
||||
const QString uuidA = "48f64fab-ba2a-40b5-8fbb-75361099dfb6";
|
||||
name_A.set_uuid(uuidA);
|
||||
name_A.set_id(2);
|
||||
name_A.set_name("TestnameA");
|
||||
|
||||
|
||||
QVERIFY2(!utils.insertIntoTable(&name_A, "nonexistenttable").isActive(), "Successfull insert must return isActive sqlQuery");
|
||||
}
|
||||
|
||||
QTEST_APPLESS_MAIN(SqliteTest)
|
||||
|
||||
#include "tst_sqlite.moc"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user