I am working on a C++ Qt program where I include a mysql database.
I want to do some sql queries and show the output on a tableview. Because I also want to filter the results I wrote this kind of code snippet:
query->prepare("SELECT * FROM contacts WHERE contactsName LIKE '%:name%';");
query->bindValue(":name", mUi->searchContactsLine->text());
query->exec();
mModel->setQuery(*query);
mUi->tableContacts->setModel(mModel);
... where
searchContactsLine
is the inputlinebox to search for a string,
mModel
is my QSqlQueryModel and
tableContacts
is my TableView in qt.
As you can see I want to use pattern matching with the dollar sign. But if I run the program I got no row back.. no matter what I am searching for. In the past I had problems with the inverted commas ('...') while using the bindValue function, but if I delete it from the sql command I get an sql syntax error.
So what do I wrong? Maybe you have an idea of that.