Hello,
just one thing, can we use the "like" word in a setFilter method? Like this:
Qt Code:
To copy to clipboard, switch view to plain text mode
I tried but it seems that it doesn't work.
Thanks,
Palma
Hello,
just one thing, can we use the "like" word in a setFilter method? Like this:
Qt Code:
To copy to clipboard, switch view to plain text mode
I tried but it seems that it doesn't work.
Thanks,
Palma
Hello,
can we use the "like" word in a setFilter method to filter table records based on the first letters a user put in a QLineEdit? Like this:
Qt Code:
sentenceModel->select();To copy to clipboard, switch view to plain text mode
I tried but it seems that it doesn't work, neither putting "=" instead of "like". I can only filter by one column of integer type.
Any help would be appreciated.
Thanks,
Palma
Use quotes instead of double quotes and, please, don't post the same question more than onece.
ok, i will not put the same question twice.
It still doesn't work. My code :
Qt Code:
To copy to clipboard, switch view to plain text mode
It's probably because your LIKE clause isn't working as you expect it to. What kind of database are you connecting to? What's the content of the idtext argument and the text field in the database? Read up on LIKE in the database documentation.
Qt doesn't care what you pass to setFilter(). It just uses it to generate a select statement. If you feed it garbage it'll just pass the garbage to the database which will complain about it (and lastError() will return an error).
I'm using a SQLite database, the content of idtext is "primeira" for example and the text field is of varchar(100) type
Can you filter that table using LIKE when you issue the query from the sqlite console?
The following code:
will cause a select looking like this to be generated:Qt Code:
To copy to clipboard, switch view to plain text mode
SELECT [...] FROM [...] WHERE text like 'primeira%'
This will only select the rows where text is exactly 'primeira'. If you want to select all rows containing 'primeira' you can try:
Qt Code:
To copy to clipboard, switch view to plain text mode
Selecting only rows starting with 'primeira' by using text LIKE 'primeira%' doesn't seem to work. This might be a SQLite bug, or it may be how SQLite works. Check the doc.
Yes jacek, i can filter that table using LIKE when i issue the query from the sqlite console.
mm78, i tried with
Qt Code:
To copy to clipboard, switch view to plain text mode
but it's the same thing, no record appear in the tableview associated with the sentenceModel. In the sqlite console the filter using "like" works with
select * from sentence where text like '%primeira%';
or with
select * from sentence where text like 'primeira%';
displaying one record as i expected.
Ok, then set a breakpoint at the end of QSqlRelationalQuery::selectStatement() and see what the generated query looks like - it might be bad. Did you check if lastError() returns an error or not?
nagpalma (10th July 2007)
thanks a lot mm78 , i checked if lastError() returns an error and it returned that the text field was ambiguous, i change the name and it worked. I think it's because text is a reserved word ( a datatype in sqlite).
Palma
Bookmarks