]> git.nothing2do.fr Git - diary-mobile.git/commitdiff
no SQL command is hardcoded
authorNorbert Moutarde <norbert.moutarde@nothing2do.eu>
Tue, 29 Apr 2014 07:19:28 +0000 (09:19 +0200)
committerNorbert Moutarde <norbert.moutarde@nothing2do.eu>
Tue, 29 Apr 2014 07:19:28 +0000 (09:19 +0200)
mainwindow.cpp

index e1a315b9fc9a47d45df888e42a6f8a81c4187a58..798774b30eb98ae9411bbdb282465abd84580c67 100644 (file)
@@ -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<QString> 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<QString> tmp({"select label,action from ui where keyword like ? order by id;", c});
+    QList<QString> 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()="<<exec(QList<QString>({"select id,label from ui where keyword like ? order by id;", b}));
+    qDebug()<<"exec()="<<exec(QList<QString>({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<QString>({"select id,keyword,label,action from ui where id=?;", a}));
+    exec(QList<QString>({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<QString>({"delete from ui where id=?", a}));
+        exec(QList<QString>({conf->value(QString("deletebuttons")).toString(), a}));
         return;
         }
-    exec(QList<QString>({"update ui set keyword=?, label=?, action=? where id=?;", keyword, label, action, a}));
+    exec(QList<QString>({conf->value(QString("updatebuttons")).toString(), keyword, label, action, a}));
 
 }
 void MainWindow::downloadUi(){