quran / quran-ios

QuranEngine is the engine powering the Quran.com iOS app.
Apache License 2.0
460 stars 159 forks source link

Crash for Updating Last page from Last Pages Bookmarks #61

Closed mohamede1945 closed 7 years ago

mohamede1945 commented 7 years ago

After applying https://github.com/quran/quran-ios/pull/60 now there is a crash when the user opens the Quran from one of the last pages.

Steps to reproduce:

  1. Assume you have in the "last pages bookmarks", pages 1 and 2.
  2. Open the Quran from page 1.
  3. Then swipe the page to go to page 2. The app will crash at this point.

I think the crash in function

func update(page: LastPage, toPage newPage: Int) throws -> LastPage
ahmedre commented 7 years ago

i saw this crash before merging #62, but now i can't repro anymore. tried also checking the value of connection.run(update), and it seems to be correct when i run it.

can we close this?

mohamede1945 commented 7 years ago

Yes, it doesn't crash, but it still throws a swift error. The problem is that if there are 2 records in the database with pages (3 and 4) then when the query is to update the record for page 4 to set it to page 3, the SQLite will throw an exception. I will try to fix it.

ahmedre commented 7 years ago

couple of ideas:

  1. delete the page you're about to add first
  2. query for both pages instead of just one, and if count is 2, then call update on the specific one
  3. not sure how to do this with sqlite.swift, but you can manually do an update, and add an on conflict replace (see here)
mohamede1945 commented 7 years ago

I already fixed it here https://github.com/quran/quran-ios/pull/63 I also made the app crashes on debug build if there is a swift error.

ahmedre commented 7 years ago

awesome, jazakAllah khairan!

mohamede1945 commented 7 years ago

You thank you so much! rabena yekremek :)