1

I have a query like:

SELECT id,name,province,enabled 
FROM customers 
WHERE enabled = 1 AND (name LIKE "%to%" OR  province LIKE "%to%");

Using the same database on MAC or IPAD gives me different results.

On Mac it works as supposed and returns 11 records, but on an iPad returns 55 records ¿? (And strangely some of them have the field enabled = 0) really strange.

iPad app is done in Objective C with Xcode6

I suppose sqlite3 is not exactly the same version on both devices, and doesn't interpret in the same way the parenthesis priority.

3
  • 1
    I strongly suspect that there is an actual difference in your code between the two versions. Commented Oct 8, 2014 at 17:33
  • 1
    What you have described is impossible. Please show the code that executes the query. Commented Oct 8, 2014 at 18:35
  • SQLite is extraordinarily stable and predictable from one platform to the next -- far better than iOS, Windows, et al. It would have been quite unusual to find an actual difference in behavior. Commented Oct 8, 2014 at 20:42

2 Answers 2

1

I suspect that the iOS rendition has a problem in the SQL, perhaps missing the parentheses. For example, the following SQL may include results where enabled is not equal to 1:

SELECT id,name,province,enabled 
FROM customers 
WHERE enabled = 1 AND name LIKE "%to%" OR  province LIKE "%to%";

Make sure to include the parentheses as shown in the original question.

Sign up to request clarification or add additional context in comments.

2 Comments

I know. The SQL has the parenthesis, in fact, I tested it copy-passting the query from the XCode log. And that's why is so strange, same query different results on different devices with the same db.
@MiQUEL Yep, I hear you. But I contend there there must be some subtle difference that is eluding your analysis. But without code sample, we cannot help you. Without a reproducible example of the problem, we cannot help you. Try to create the smallest possible MCVE that reproduces the problem. But I would wager that the prioritization of parentheses in iOS SQLite engine is almost certainly not the problem. While I'm sure you feel that you've controlled for every other possible variable, there's got to be something else at play here.
0

Found it.

The story, when the app loads, It empties the database, and fill all data from an xml that it downloads.

After that, it updates some records like "enabled" field with an update statement like this.

update customers set enabled = 1 where date(some_date_field)>date('1980-12-01');

And here is the problem it should be:

update customers set enabled = 1 where some_date_field>date('1980-12-01');

stackoverflow similar problem solution

so, in this scenario was correct to thought that both databeses where identical but in reality are not equal, thats why I was seeing diferent results.

And not being able to get the db from the ipad (not jailbroken anymore) made me the confusion, this and the Documents Directory , that changes every time you run the app in the simulator is not really helping either :(

Thanks everyone for the interest.

1 Comment

Glad you found it! FYI, you can still download the documents folder from device via Xcode: In the Xcode "Window" menu, choose "Devices"; then choose your device and choose your app; then click on the "gear" icon and you can download the "container" to your Mac.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.