<tfoot id='wQ3r2'></tfoot>

      <bdo id='wQ3r2'></bdo><ul id='wQ3r2'></ul>

    <legend id='wQ3r2'><style id='wQ3r2'><dir id='wQ3r2'><q id='wQ3r2'></q></dir></style></legend>

  1. <small id='wQ3r2'></small><noframes id='wQ3r2'>

    <i id='wQ3r2'><tr id='wQ3r2'><dt id='wQ3r2'><q id='wQ3r2'><span id='wQ3r2'><b id='wQ3r2'><form id='wQ3r2'><ins id='wQ3r2'></ins><ul id='wQ3r2'></ul><sub id='wQ3r2'></sub></form><legend id='wQ3r2'></legend><bdo id='wQ3r2'><pre id='wQ3r2'><center id='wQ3r2'></center></pre></bdo></b><th id='wQ3r2'></th></span></q></dt></tr></i><div id='wQ3r2'><tfoot id='wQ3r2'></tfoot><dl id='wQ3r2'><fieldset id='wQ3r2'></fieldset></dl></div>

      SQLite3 和多个进程

      SQLite3 and multiple processes(SQLite3 和多个进程)

        <legend id='TtC8e'><style id='TtC8e'><dir id='TtC8e'><q id='TtC8e'></q></dir></style></legend>

        • <bdo id='TtC8e'></bdo><ul id='TtC8e'></ul>
        • <tfoot id='TtC8e'></tfoot>

            <small id='TtC8e'></small><noframes id='TtC8e'>

            <i id='TtC8e'><tr id='TtC8e'><dt id='TtC8e'><q id='TtC8e'><span id='TtC8e'><b id='TtC8e'><form id='TtC8e'><ins id='TtC8e'></ins><ul id='TtC8e'></ul><sub id='TtC8e'></sub></form><legend id='TtC8e'></legend><bdo id='TtC8e'><pre id='TtC8e'><center id='TtC8e'></center></pre></bdo></b><th id='TtC8e'></th></span></q></dt></tr></i><div id='TtC8e'><tfoot id='TtC8e'></tfoot><dl id='TtC8e'><fieldset id='TtC8e'></fieldset></dl></div>

              <tbody id='TtC8e'></tbody>
              1. 本文介绍了SQLite3 和多个进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                当多个进程访问一个 SQLite 数据库文件时,如何确保正确性?

                How should one ensure correctness when multiple processes access one single SQLite database file?

                推荐答案

                首先,避免并发访问 sqlite 数据库文件.并发性是 sqlite 的弱点之一,如果您有一个高度并发的应用程序,请考虑使用其他数据库引擎.

                First, avoid concurrent access to sqlite database files. Concurrency is one of sqlite's weak points and if you have a highly concurrent application, consider using another database engine.

                如果您无法避免并发或丢弃 sqlite,请将您的 write 事务包装在 BEGIN IMMEDIATE; ... END; 中.sqlite 中的默认事务模式是 DEFERRED 这意味着只有在第一次实际写入尝试时才获取锁.使用 IMMEDIATE 事务,会立即获取锁,或者立即获取 SQLITE_BUSY.当有人持有对数据库的锁定时,其他锁定尝试将导致 SQLITE_BUSY.

                If you cannot avoid concurrency or drop sqlite, wrap your write transactions in BEGIN IMMEDIATE; ... END;. The default transaction mode in sqlite is DEFERRED which means that a lock is acquired only on first actual write attempt. With IMMEDIATE transactions, the lock is acquired immediately, or you get SQLITE_BUSY immediately. When someone holds a lock to the database, other locking attempts will result in SQLITE_BUSY.

                处理 SQLITE_BUSY 是您必须自己决定的事情.对于许多应用程序,等待一两秒钟然后重试工作正常,在 n 次尝试失败后放弃.有 sqlite3 API 帮助程序可以使这变得简单,例如sqlite3_busy_handler()sqlite3_busy_timeout() 但也可以手动完成.

                Dealing with SQLITE_BUSY is something you have to decide for yourself. For many applications, waiting for a second or two and then retrying works quite all right, giving up after n failed attempts. There are sqlite3 API helpers that make this easy, e.g. sqlite3_busy_handler() and sqlite3_busy_timeout() but it can be done manually as well.

                您还可以使用操作系统级别的同步来获取数据库的互斥锁,或者使用操作系统级别的线程间/进程间消息传递在一个线程完成访问数据库时发出信号.

                You could also use OS level synchronization to acquire a mutex lock to the database, or use OS level inter-thread/inter-process messaging to signal when one thread is done accessing the database.

                这篇关于SQLite3 和多个进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                MySQL SELECT most frequent by group(MySQL SELECT 按组最频繁)
                Why Mysql#39;s Group By and Oracle#39;s Group by behaviours are different(为什么 Mysql 的 Group By 和 Oracle 的 Group by 行为不同)
                MySQL cumulative sum grouped by date(按日期分组的 MySQL 累计总和)
                sql group by versus distinct(sql group by 与不同)
                Count number of records returned by group by(统计分组返回的记录数)
                SQL GROUP BY CASE statement with aggregate function(带聚合函数的 SQL GROUP BY CASE 语句)

              2. <tfoot id='EKBFA'></tfoot>
              3. <i id='EKBFA'><tr id='EKBFA'><dt id='EKBFA'><q id='EKBFA'><span id='EKBFA'><b id='EKBFA'><form id='EKBFA'><ins id='EKBFA'></ins><ul id='EKBFA'></ul><sub id='EKBFA'></sub></form><legend id='EKBFA'></legend><bdo id='EKBFA'><pre id='EKBFA'><center id='EKBFA'></center></pre></bdo></b><th id='EKBFA'></th></span></q></dt></tr></i><div id='EKBFA'><tfoot id='EKBFA'></tfoot><dl id='EKBFA'><fieldset id='EKBFA'></fieldset></dl></div>

                <small id='EKBFA'></small><noframes id='EKBFA'>

                  <bdo id='EKBFA'></bdo><ul id='EKBFA'></ul>

                  <legend id='EKBFA'><style id='EKBFA'><dir id='EKBFA'><q id='EKBFA'></q></dir></style></legend>
                        <tbody id='EKBFA'></tbody>