Query ":placeholder" does not work, but "?" does.
-
i am trying to get stuff from my ui into a databse. so first i do a check if the entry already exists.
-
if it exists i'll do an UPDATE SET WHERE clause.
-
If not i'll do an INSERT INTO VALUES clause.
in both of these cases, the last part (WHERE / VALUES) a :placeholder does not work.
so here the 2 cases with both examples and how i tried them. with the one working and the other one not working.
1:
//(with ?)
q.prepare("UPDATE my_table SET column1 = :val1 WHERE column2 = ?");
q.bindValue(":val1", ui->my_line_edit->text());
q.bindValue(1, ui->my_line_edit_2->text());
q.exec();
//WORKS//(with :placeholder)
q.prepare("UPDATE my_table SET column1 = :val1 WHERE column2 = :val2");
q.bindValue(":val1", ui->my_line_edit_1->text());
q.bindValue(":val2", ui->my_line_edit_2->text());
q.exec();
//DOES NOT WORKS2:
//(with ?)
q.prepare("INSERT INTO my_table (column1) VALUES (?)");
q.bindValue(0, ui->my_line_edit->text());
q.exec();
//WORKS//(with :placeholder)
q.prepare("INSERT INTO my_table (column1) VALUES (:val)");
q.bindValue(":val", ui->my_line_edit->text());
q.exec();
//DOES NOT WORKI hope i made the point clear.
-
-
@qtnoob420 said in Query ":placeholder" does not work, but "?" does.:
I hope i got it this time :D
Yes, that's correct.
I think you problem is link to this ticket QTBUG-48471.
It seems that PostgreSQL do not support prepare statements. -
Hi,
Which version of Qt are you using ?
Which database backend ? -
@qtnoob420 said in Query ":placeholder" does not work, but "?" does.:
in both of these cases, the last part (WHERE / VALUES) a :placeholder does not work.
to complete @SGaist questions: did you check
q.prepare()
returned value? If returning false than the query could not be prepared (cf documentation) -
@qtnoob420 said in Query ":placeholder" does not work, but "?" does.:
QT Creator 4.13.1 (Community)
This is your IDE, but why Qt Kit you are using to build your application (cf. Tools/Options/Kits)?
-
@qtnoob420 said in Query ":placeholder" does not work, but "?" does.:
I hope i got it this time :D
Yes, that's correct.
I think you problem is link to this ticket QTBUG-48471.
It seems that PostgreSQL do not support prepare statements. -
@KroMignon as soon as i use my example with the :placeholder i get a syntax error returned from my query. but there is no syntax fault. as i said in my post, i just switched the ":placeholder" with a "?" and the it works fine again.
i suppose there is nothing i can do about it...
-
@qtnoob420 said in Query ":placeholder" does not work, but "?" does.:
i suppose there is nothing i can do about it...
As you can see, it is a limitation of PostgreSQL itself.
if(!q.prepare("UPDATE my_table SET column1 = :val1 WHERE column2 = :val2")) { qDebug() << "Prepare statement error:" << q.lastError().text(); }