shuiyouren / sqlitepersistentobjects

Automatically exported from code.google.com/p/sqlitepersistentobjects
0 stars 0 forks source link

Incorrect query results with using "LIKE" as one of the SQL criteria string #54

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

Use countByCriteria or findByCriteria with criteria such as:
"WHERE field_name LIKE '%something%'."

What is the expected output? What do you see instead?
It gives the incorrect query result based on the pattern, in some
situations it only works for a full text criteria (the wildcard doesn't work).

What version of the product are you using? 
Latest version of sqlitepersistentobjects in the trunk in iPhone OS 2.2

Previous version is not like this. The previous version that I had tried
and it works is on revision 79, and I don't know afterwards.

Original issue reported on code.google.com by mnemonic...@gmail.com on 19 Mar 2009 at 4:11

GoogleCodeExporter commented 8 years ago
Yes, LIKE stetament doen't work at all. Only equal works correctly with strings 
(field_name = 'someValue').
Latest version from Source tab.

Original comment by parampam...@gmail.com on 5 Aug 2009 at 1:45

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
By now the LIKE statement theoretically works. But to use wildcards in 
findByCriteria 
you have to escape them with percent signs.

So "WHERE field_name LIKE '%something%'" would become "WHERE field_name LIKE 
'%%something%%'".

If you are using a stringWithFormat for the criteria, you have to escape them 
again, 
so a complete call of findByCriteria would look like this:

NSString *searchText = @"john";
NSArray *results = [PersistentPerson findByCriteria:[NSString 
stringWithFormat:@"WHERE name LIKE '%%%%%@%%%%'", searchText]];

Original comment by canbuffi@gmail.com on 1 Feb 2010 at 7:53

GoogleCodeExporter commented 8 years ago
I don't understand why it needs double escaping.

Original comment by mnemonic...@gmail.com on 1 Feb 2010 at 7:59

GoogleCodeExporter commented 8 years ago
Just use that double escaping without any questions!

Original comment by parampam...@gmail.com on 1 Feb 2010 at 8:09