SQLite相关

  • SQLite语句
  1. 增加表字段 ALTER TABLE 表名 ADD COLNUM 字段名 字段类型
  2. 删除表字段 ALTER TABLE 表名 DROP COLNUM 字段名
  3. 修改表字段 ALTER TABLE 表名 RENAME COLNUM 旧字段名 TO 新字段名
  • SQLite的线程安全
    http://stackoverflow.com/questions/6675240/is-sqlite-database-instance-thread-safe
    No, it is not thread-safe by default. You shoud use locking-related SQLiteHelper methods to provide thread safety.
    http://stackoverflow.com/questions/11058098/interprocess-sqlite-thread-safety-on-ios
    I’ve never used SQLite, but I’ve spent a decent amount of time reading its docs because I plan on using it in the future (and the docs are interesting). I’d say that thread safety is independent of whether multiple processes can access the same database file at once. SQLite, regardless of what threading mode it is in, will lock the database file, so that multiple processes can read from the database at once but only one can write.
    Thread safety only affects how your process can use SQLite. Without any thread safety, you can only call SQLite functions from one thread. But it should still, say, take an EXCLUSIVE lock before writing, so that other processes can’t corrupt the database file. Thread safety just protects data in your process’s memory from getting corrupted if you use multiple threads. So I don’t think you ever need to worry about what another process (in this case iOS) is doing with an SQLite database.
    Edit: To clarify, any time you write to the database, including a plain INSERT
    /UPDATE
    /DELETE
    , it will automatically take an EXCLUSIVE lock, write to the database, then release the lock. (And it actually takes a SHARED lock, then a RESERVED lock, then a PENDING lock, then an EXCLUSIVE lock before writing.) By default, if the database is already locked (say from another process), then SQLite will return SQLITE_BUSY without waiting. You can call sqlite3_busy_timeout()
    to tell it to wait longer.

  • CoreData的线程安全
    看到知乎上有人说core data是支持多线程的,但需要thread confinement的方式实现,使用了多线程之后可以最大化的防止阻塞主线程。待实验

    原文作者:王蓝胖
    原文地址: https://www.jianshu.com/p/30477e8293c9
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞

发表评论

电子邮件地址不会被公开。 必填项已用*标注