IOS SQLite database is locked

Source: Internet
Author: User

SQLite locksEntireDatabase
During a write operation (I. e. when a write is happening on any table, no other write, to any table anywhere can happen at the same time ). some databases provide concurrent writes via table-level locks, or sometimes row-level locks. to contrast this to SQLite's
Implementation, a table-Level Lock basically means that when you're writing data to a given table, no other thread can write to any record in that table, at the same time (however, writes to other tables can occur simultaneously, in some circumstances ). similarly,
Row-level locks take it even further, and allow only the necessary rows involved to be locked, allowing concurrent writes to the same table to happen from multiple threads. the idea here is to minimize the amount of data you need to lock for a write operation,
Which effectively increases the amount of concurrent writes possibleAcrossThe
Database, and depending on your implementation/how you use your database, this can significantly increase throughput.

Now, back to your question...

The fact that SQLite is threadsafe doesn't mean that multiple threads can concurrently write to it-it means that it has a way of handling access from multiple threads-which is to () allow timeouts/retries, and (B) to return a useful error (SQLite: Busy)
When a lock is currently held on the database. That is,ThreadsafeMeans
Nothing more than, "multiple threads can access this data in a way that won't result in data upload uption due to simultaneous access ."

Basically, somewhere in the code, one thread is trying to do its update, before another thread has released its lock on the database. this is a common hurdle with SQLite, because the authors/documentation will tell you that SQLite can handle concurrency like
A champ. the reality is that what SQLite considers "concurrency support" amounts to trying to be very fast, so that locks on the database are only held for a very short time, and therefore locks on the database are released before timeouts are hit. in a lot
Of cases, this works just fine and never gets in your way. However, having very short-lived locks is not the same as actually allowing concurrent writes from multiple threads.

Think of it like the way that IOS does multitasking-really what it's doing is putting other apps on pause, and coming back to them. this has the effect that (a) battery life is much better due to lower CPU utilization, and (B) You don't have to start an app
From scratch every time you launch it. this is great, but the actual word "multitasking" as used in IOS doesn't technically mean the same thing as "multitasking" in other environments (even Mac OS X ).

SQLite is the same way. Do they have "concurrency" support? Well sort of, but the way they define the word "concurrency" isn't the way the rest of the DB world defines "concurrency ".

No one is really wrong, but in cases like these, it adds to implementation confusion.

==> Later I found the cause of the problem on my side, which must be caused by SQL close. I thought back to the specific problem function, and then looked for SQLite -- open and close, it is found that one is 5 and the other is 4. bingo.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.