[solved] - qsqlquery; bindvalue a select query
-
hi,
i have the following scenario:
@ QSqlQuery query;
query.prepare("INSERT INTO person (id, forename, surname) "
"VALUES (:id, :forename, :surname)");
query.bindValue(":id", 1001);
query.bindValue(":forename", "Bart");
query.bindValue(":surname", "Simpson");
query.exec();@everything is fine and working.
now i have two tables, person and actor, the date already exists in actor and I would like to populate person with some data from actor (maybe doesn't make sense what i would like to do, but just on account of this example):
@ QSqlQuery query;
query.prepare("INSERT INTO person (id, forename, surname) "
"VALUES (:id, :forename, :surname)");
query.bindValue(":id", "select id from actor where actorName= (' " + ui->lineEditActorName->text()+" ')");
....
query.exec();@- is it possible to use bindvalue with queries?
nothing found in QSqlQuery class ref - is the syntax used here ...... = (' " + ui->lineEditActorName->text()+" ')"); correct?
i would like to say that actorName is ... whatever is written on the lineEdit
thanks for your inputs.
- is it possible to use bindvalue with queries?
-
Hi,
If that was possible, it would be too messy. Just create your SELECT query in a separate function that will return or assign the value you want (or just execute this query first and assign the result to a variable) and then bind that value in your INSERT query.
-
thanks, solved with the solution you gave.