mirror of
https://gitlab.com/eql/lqml.git
synced 2025-12-06 02:30:38 -08:00
example 'meshtastic': make it work on android again (sqlite)
This commit is contained in:
parent
e15e58daaa
commit
f3c80bbce4
13 changed files with 94 additions and 48 deletions
|
|
@ -1,5 +1,7 @@
|
|||
#include "qt.h"
|
||||
#include "ble_meshtastic.h"
|
||||
#include <QSqlQuery>
|
||||
#include <QSqlError>
|
||||
#include <QtDebug>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
|
@ -16,6 +18,8 @@ QT::QT() : QObject() {
|
|||
ble = new BLE_ME;
|
||||
}
|
||||
|
||||
// BLE_ME
|
||||
|
||||
QVariant QT::startDeviceDiscovery(const QVariant& vName) {
|
||||
auto name = vName.toString();
|
||||
if (!name.isNull()) {
|
||||
|
|
@ -43,4 +47,41 @@ QVariant QT::write2(const QVariant& bytes) {
|
|||
return QVariant();
|
||||
}
|
||||
|
||||
// SQLite
|
||||
|
||||
QVariant QT::iniDb(const QVariant& name) {
|
||||
db = QSqlDatabase::addDatabase("QSQLITE");
|
||||
db.setDatabaseName(name.toString());
|
||||
return name;
|
||||
}
|
||||
|
||||
QVariant QT::sqlQuery(const QVariant& vQuery, const QVariant& vValues) {
|
||||
// very simple, we don't need more
|
||||
QVariantList results;
|
||||
QSqlQuery query(db);
|
||||
if (db.open()) {
|
||||
query.prepare(vQuery.toString());
|
||||
const QVariantList values = vValues.value<QVariantList>();
|
||||
for (auto value : values) {
|
||||
query.addBindValue(value);
|
||||
}
|
||||
if (query.exec()) {
|
||||
while (query.next()) {
|
||||
results << query.value(0);
|
||||
}
|
||||
db.close();
|
||||
return results;
|
||||
}
|
||||
db.close();
|
||||
}
|
||||
QString text;
|
||||
if (query.lastError().isValid()) {
|
||||
text = query.lastError().text();
|
||||
} else {
|
||||
text = db.lastError().text();
|
||||
}
|
||||
qDebug() << "SQL error:" << text;
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue