From: Norbert Moutarde Date: Tue, 29 Apr 2014 07:19:28 +0000 (+0200) Subject: no SQL command is hardcoded X-Git-Url: https://git.nothing2do.fr/?a=commitdiff_plain;h=2bb74b850d2ecc6db0e877b664b4fb10d8ab614c;p=diary-mobile.git no SQL command is hardcoded --- diff --git a/mainwindow.cpp b/mainwindow.cpp index e1a315b..798774b 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -280,6 +280,12 @@ void MainWindow::firstrun(){ conf->setValue(QString("selectbuttons"), QVariant("select keyword,label,action from ui order by keyword;")); conf->setValue(QString("selectraw"), QVariant("select date,texte from raw;")); conf->setValue(QString("menuback"), QVariant("-menuback")); + conf->setValue(QString("choosebuttons"), QVariant("select id,label from ui where keyword like ? order by id;")); + conf->setValue(QString("addbuttons"), QVariant("insert into ui (label, keyword, action) values (:label, :keyword, :action)")); + conf->setValue(QString("getbuttons"), QVariant("select label,action from ui where keyword like ? order by label;")); + conf->setValue(QString("editbuttons"), QVariant("select id,keyword,label,action from ui where id=?;")); + conf->setValue(QString("updatebuttons"), QVariant("update ui set keyword=?, label=?, action=? where id=?;")); + conf->setValue(QString("deletebuttons"), QVariant("delete from ui where id=?")); } QString &MainWindow::get(int row, int column){ q->seek(row); @@ -338,7 +344,7 @@ void MainWindow::addButtonDB(){ //QMutexLocker locker(&addblock); QList cmd; bool ok=0; - cmd.append("insert into ui (label, keyword, action) values (:label, :keyword, :action)"); + cmd.append(conf->value(QString("addbuttons")).toString()); QString cur=way.last(); QString a, b, c=QInputDialog::getText(this, QString("label"), QString("Entrez son label"),QLineEdit::Normal, QString(""), &ok); if ((c=="")||(ok==0))return; @@ -362,7 +368,7 @@ void MainWindow::getButtons(const QString &b){ if(updatelocker.tryLock(60000))updatelocker.unlock(); else{qDebug()<<"updatelocker is locked more than 1mn";} QString c="%"+a+"%"; - QList tmp({"select label,action from ui where keyword like ? order by id;", c}); + QList tmp({conf->value(QString("getbuttons")).toString(), c}); label->setText(a); exec(tmp); int labCol = 0;//r.indexOf("label"); @@ -386,23 +392,23 @@ void MainWindow::chooseButtonDB(){ void MainWindow::chooseButtonDB(const QString & a){ flush(); QString b="%"+a+"%"; - qDebug()<<"exec()="<({"select id,label from ui where keyword like ? order by id;", b})); + qDebug()<<"exec()="<({conf->value(QString("choosebuttons")).toString(), b})); while (q->next()) { const QString action="edit "+q->value(0).toString(); addWidget(action, new CLabel(q->value(1).toString(), conf->value(QString("button")).toString())); } } void MainWindow::editButtonDB(const QString & a){ - exec(QList({"select id,keyword,label,action from ui where id=?;", a})); + exec(QList({conf->value(QString("editbuttons")).toString(), a})); q->next(); const QString keyword=QInputDialog::getText(this, "keyword", "new keyword", QLineEdit::Normal, q->value(1).toString()); const QString label=QInputDialog::getText(this, "label", "new label", QLineEdit::Normal, q->value(2).toString()); const QString action=QInputDialog::getText(this, "action", "new action", QLineEdit::Normal, q->value(3).toString()); if((keyword=="")||(label=="")||(action=="")){ - exec(QList({"delete from ui where id=?", a})); + exec(QList({conf->value(QString("deletebuttons")).toString(), a})); return; } - exec(QList({"update ui set keyword=?, label=?, action=? where id=?;", keyword, label, action, a})); + exec(QList({conf->value(QString("updatebuttons")).toString(), keyword, label, action, a})); } void MainWindow::downloadUi(){