车顶放饮料是什么意思| 2月26日什么星座| 三点水加四读什么| 秦皇岛有什么特产| 产检是什么意思| 一什么马| 但微颔之的之是什么意思| 平均红细胞体积偏高是什么意思| 13数字代表什么意思| 高烧拉肚子是什么原因| 景象什么意思| 普洱在云南什么位置| 吃大米配什么菜| 戒指中指代表什么意思| 玫瑰花和什么一起泡水喝好| 为什么会得骨癌| 肾不好是什么原因引起的| 2.25是什么星座| 中国的国球是什么| 亥时属什么生肖| 一什么黄豆| 甲状腺结节是什么意思| 什么流砥柱| 53年属什么| 什么泡水喝可降血压| 咳嗽嗓子有痰吃什么药| 化疗后白细胞低吃什么补得快| 考药师证需要什么条件| 忽然心口疼是什么原因| 印度信仰什么教| 用盐水洗脸有什么好处和坏处| 牙疼吃什么药最好最有效| 空调什么牌子的好| 蔬菜都有什么| 经常干咳是什么原因| 欧诗漫适合什么年龄| 维生素d低是什么原因| 最大的恐龙是什么恐龙| 横批是什么意思| 信必可是什么药| 皓五行属什么| 孕妇胃痛可以吃什么药| 相得益彰什么意思| 吃什么能阻止性早熟| 果位是什么意思| 金碧辉煌是什么生肖| 傻白甜的意思是什么| 扁桃体发炎喉咙痛吃什么药| 尿酸高早餐吃什么| 过敏嘴唇肿是什么原因| 260是什么意思| 洋葱与什么食物相克| 吃什么白头发变黑| 高丽棒子是什么意思| 孕妇喝可乐对胎儿有什么影响| 梦见小猫崽是什么意思| 人丹是什么| 孕妇抽筋是什么原因引起的| 冰菜是什么菜| 干咳无痰吃什么药好| 脂肪肝轻度是什么意思| 痰多是什么原因造成的| 女人性冷淡用什么药| 女人喝红酒有什么好处| 三月份是什么星座的| 小孩记忆力差需要补充什么营养| 家门是什么意思| 右边肋骨疼是什么原因| 彩排是什么意思| 生蒜头吃了有什么好处和坏处| 美国为什么不打朝鲜| 股骨长是什么意思| 5月31日什么星座| 球是什么意思| 营养不良吃什么药| 狮子座女和什么星座最配| 蝎子喜欢吃什么| package什么意思| 头痒用什么洗头可以止痒| 为什么一生气就胃疼| 大致正常心电图是什么意思| 女性胃炎有什么症状| 颌下淋巴结肿大挂什么科| 青筋明显是什么原因| 鱼条念什么| 女人更年期吃什么药调理最好| 怀孕胸部会有什么反应| 镪水池是什么| 卖是什么意思| 天下乌鸦一般黑是什么意思| 浅表性胃炎伴糜烂吃什么药效果好| 脑供血不足用什么药效果最好| 藕断丝连是什么意思| 长期腹泻是什么病| 什么水果降火| 什么睡姿有助于丰胸| 十余载是什么意思| 山竹是什么季节的水果| 政委是什么军衔| 黄皮果什么时候成熟| 月亮是什么星| 黄雀是什么鸟| 8.5是什么星座| 团长是什么军衔| 成吉思汗姓什么| 黄体不足吃什么药| 无动于衷是什么意思| 检查肝功能挂什么科| 痛风可以吃什么鱼| cafe是什么意思| 豆腐炖什么好吃| 吃什么食物对眼睛好| 2009年属什么生肖| 功能性消化不良吃什么药| 双五行属什么| 皮肤白斑是什么原因| 保胎吃什么食物好| 湿疹是什么病| 午餐肉是什么肉| 雪燕是什么东西| 为什么手脚冰凉还出汗| 午餐肉炒什么菜好吃| 反乌托邦是什么意思| 二月二是什么节| 陪伴是最长情的告白下一句是什么| 止咳平喘什么药最有效| 脑血栓不能吃什么| edsheeran为什么叫黄老板| 登对是什么意思| 痉挛是什么症状| 梨状肌综合症吃什么药| 徒木立信是什么意思| 七月初七是什么生肖| 头皮起疙瘩是什么原因| 肾精亏虚吃什么中成药| 恃宠而骄什么意思| fci是什么意思| 祸起萧墙是什么意思| 狗打针打什么部位| 甲钴胺有什么作用| 什么是便血| 小米是什么米| 为什么感冒吃冰棒反而好了| 什么是性早熟| jdv是什么牌子| 脊柱侧弯有什么症状| 心梗是什么原因造成的| 地奥心血康软胶囊主治什么病| 有炎症吃什么药| #NAME?| 河蚌吃什么食物| 燕窝是什么东西做的| 妨父母痣是什么意思| 宝宝缺锌有什么表现和症状| 反复发烧挂什么科| 长智齿意味着什么| 公积金缴存基数是什么意思| 口甲读什么| 脚后跟痛什么原因| 对峙是什么意思| 丝瓜什么时候种植最好| 胃酸吃什么药效果最好| 风寒感冒吃什么药效果好| 钡餐是什么| 前列腺肥大是什么意思| 什么药治便秘效果最好最快| 博士和博士后有什么区别| 宝宝半夜咳嗽是什么原因| 蓝莓有什么功效与作用| 偶像是什么意思| 画风是什么意思| 什么是护理| 三个水念什么| 人体左边肋骨下疼是什么原因| 关节疼挂什么科| 手指尖疼是什么原因| 子宫憩室是什么| 过敏性皮炎吃什么药好| 印度洋为什么叫印度洋| 回族信仰什么教| 张学友和张家辉什么关系| 吃什么拉什么| 想留不能留才最寂寞是什么歌| 肛门坠胀吃什么消炎药| 肾阳虚吃什么药好| 女性私处痒是什么原因引起的| 什么人容易得眩晕症| 星字属于五行属什么| 吃降压药有什么副作用| 胸腺肿瘤是什么病| 石斛有什么功效和作用| 美什么美什么| 睾丸是什么| 矿物质是什么| 属猴男和什么属相最配| 早上打碎碗是什么兆头| 黑海为什么叫黑海| 肠系膜多发淋巴结是什么意思| 孩子吃什么容易长高| TOYOTA是什么车| 脱节是什么意思| 还行吧是什么意思| 特务是什么| 马女和什么属相最配| 黄连泡水喝有什么功效| 嘴角烂了涂什么药| 高反吃什么药| 尿葡萄糖阴性什么意思| 蓝色加黄色等于什么颜色| cp是什么意思| 来大姨妈喝红糖水有什么作用| 做月子吃什么菜| 老年人适合喝什么牛奶| 什么克金| 天台是什么意思| 40min是什么意思| 什么是护理学| 医士是什么职称| 水至清则无鱼什么意思| 感冒吃什么水果好得快| ecco什么牌子| 什么鸟没有翅膀| 做穿刺是什么意思| 千古一帝指什么生肖| 血糖高喝什么牛奶好| 红斑是什么皮肤病| 红萝卜什么时候种| 脑卒中是什么意思| 脱毛膏的原理是什么| 阴囊两侧瘙痒是什么原因| 盆腔镜检查是查什么的| 月柱代表什么| 大连有什么特产| 孩子过敏性咳嗽吃什么药好| 什么食物是养肝的| 扶苏是什么意思| 前方起飞是什么意思| 钙化淋巴结是什么意思| 金牛座和什么座最配| 气短是什么感觉| 鳙鱼是什么鱼| 布病是什么| 始终如一是什么意思| 血热是什么意思| 膝关节退行性改变是什么意思| 91年属什么生肖| 外甥是什么关系| 怀孕早期需要注意什么| 79年属什么的| 五花八门是什么生肖| 右侧胸口疼是什么原因| 九月23日是什么星座| 朋友越来越少暗示什么| 葡萄膜炎是什么原因引起的| 什么时间艾灸效果最好| 凌晨两点半是什么时辰| 种马什么意思| 血糖高的人能吃什么水果| 鸭屎香为什么叫鸭屎香| 散片是什么意思| 垂体泌乳素高是什么原因| 为什么月亮是红色的| 小知了叫什么| 妇科臭氧治疗是什么| 百度
Small. Fast. Reliable.
Choose any three.

SQLite C Interface

Online Backup API.

sqlite3_backup *sqlite3_backup_init(
  sqlite3 *pDest,                        /* Destination database handle */
  const char *zDestName,                 /* Destination database name */
  sqlite3 *pSource,                      /* Source database handle */
  const char *zSourceName                /* Source database name */
);
int sqlite3_backup_step(sqlite3_backup *p, int nPage);
int sqlite3_backup_finish(sqlite3_backup *p);
int sqlite3_backup_remaining(sqlite3_backup *p);
int sqlite3_backup_pagecount(sqlite3_backup *p);

The backup API copies the content of one database into another. It is useful either for creating backups of databases or for copying in-memory databases to or from persistent files.

See Also: Using the SQLite Online Backup API

SQLite holds a write transaction open on the destination database file for the duration of the backup operation. The source database is read-locked only while it is being read; it is not locked continuously for the entire backup operation. Thus, the backup may be performed on a live source database without preventing other database connections from reading or writing to the source database while the backup is underway.

To perform a backup operation:

  1. sqlite3_backup_init() is called once to initialize the backup,
  2. sqlite3_backup_step() is called one or more times to transfer the data between the two databases, and finally
  3. sqlite3_backup_finish() is called to release all resources associated with the backup operation.
There should be exactly one call to sqlite3_backup_finish() for each successful call to sqlite3_backup_init().

sqlite3_backup_init()

The D and N arguments to sqlite3_backup_init(D,N,S,M) are the database connection associated with the destination database and the database name, respectively. The database name is "main" for the main database, "temp" for the temporary database, or the name specified after the AS keyword in an ATTACH statement for an attached database. The S and M arguments passed to sqlite3_backup_init(D,N,S,M) identify the database connection and database name of the source database, respectively. The source and destination database connections (parameters S and D) must be different or else sqlite3_backup_init(D,N,S,M) will fail with an error.

A call to sqlite3_backup_init() will fail, returning NULL, if there is already a read or read-write transaction open on the destination database.

If an error occurs within sqlite3_backup_init(D,N,S,M), then NULL is returned and an error code and error message are stored in the destination database connection D. The error code and message for the failed call to sqlite3_backup_init() can be retrieved using the sqlite3_errcode(), sqlite3_errmsg(), and/or sqlite3_errmsg16() functions. A successful call to sqlite3_backup_init() returns a pointer to an sqlite3_backup object. The sqlite3_backup object may be used with the sqlite3_backup_step() and sqlite3_backup_finish() functions to perform the specified backup operation.

sqlite3_backup_step()

Function sqlite3_backup_step(B,N) will copy up to N pages between the source and destination databases specified by sqlite3_backup object B. If N is negative, all remaining source pages are copied. If sqlite3_backup_step(B,N) successfully copies N pages and there are still more pages to be copied, then the function returns SQLITE_OK. If sqlite3_backup_step(B,N) successfully finishes copying all pages from source to destination, then it returns SQLITE_DONE. If an error occurs while running sqlite3_backup_step(B,N), then an error code is returned. As well as SQLITE_OK and SQLITE_DONE, a call to sqlite3_backup_step() may return SQLITE_READONLY, SQLITE_NOMEM, SQLITE_BUSY, SQLITE_LOCKED, or an SQLITE_IOERR_XXX extended error code.

The sqlite3_backup_step() might return SQLITE_READONLY if

  1. the destination database was opened read-only, or
  2. the destination database is using write-ahead-log journaling and the destination and source page sizes differ, or
  3. the destination database is an in-memory database and the destination and source page sizes differ.

If sqlite3_backup_step() cannot obtain a required file-system lock, then the busy-handler function is invoked (if one is specified). If the busy-handler returns non-zero before the lock is available, then SQLITE_BUSY is returned to the caller. In this case the call to sqlite3_backup_step() can be retried later. If the source database connection is being used to write to the source database when sqlite3_backup_step() is called, then SQLITE_LOCKED is returned immediately. Again, in this case the call to sqlite3_backup_step() can be retried later on. If SQLITE_IOERR_XXX, SQLITE_NOMEM, or SQLITE_READONLY is returned, then there is no point in retrying the call to sqlite3_backup_step(). These errors are considered fatal. The application must accept that the backup operation has failed and pass the backup operation handle to the sqlite3_backup_finish() to release associated resources.

The first call to sqlite3_backup_step() obtains an exclusive lock on the destination file. The exclusive lock is not released until either sqlite3_backup_finish() is called or the backup operation is complete and sqlite3_backup_step() returns SQLITE_DONE. Every call to sqlite3_backup_step() obtains a shared lock on the source database that lasts for the duration of the sqlite3_backup_step() call. Because the source database is not locked between calls to sqlite3_backup_step(), the source database may be modified mid-way through the backup process. If the source database is modified by an external process or via a database connection other than the one being used by the backup operation, then the backup will be automatically restarted by the next call to sqlite3_backup_step(). If the source database is modified by using the same database connection as is used by the backup operation, then the backup database is automatically updated at the same time.

sqlite3_backup_finish()

When sqlite3_backup_step() has returned SQLITE_DONE, or when the application wishes to abandon the backup operation, the application should destroy the sqlite3_backup by passing it to sqlite3_backup_finish(). The sqlite3_backup_finish() interfaces releases all resources associated with the sqlite3_backup object. If sqlite3_backup_step() has not yet returned SQLITE_DONE, then any active write-transaction on the destination database is rolled back. The sqlite3_backup object is invalid and may not be used following a call to sqlite3_backup_finish().

The value returned by sqlite3_backup_finish is SQLITE_OK if no sqlite3_backup_step() errors occurred, regardless of whether or not sqlite3_backup_step() completed. If an out-of-memory condition or IO error occurred during any prior sqlite3_backup_step() call on the same sqlite3_backup object, then sqlite3_backup_finish() returns the corresponding error code.

A return of SQLITE_BUSY or SQLITE_LOCKED from sqlite3_backup_step() is not a permanent error and does not affect the return value of sqlite3_backup_finish().

sqlite3_backup_remaining() and sqlite3_backup_pagecount()

The sqlite3_backup_remaining() routine returns the number of pages still to be backed up at the conclusion of the most recent sqlite3_backup_step(). The sqlite3_backup_pagecount() routine returns the total number of pages in the source database at the conclusion of the most recent sqlite3_backup_step(). The values returned by these functions are only updated by sqlite3_backup_step(). If the source database is modified in a way that changes the size of the source database or the number of pages remaining, those changes are not reflected in the output of sqlite3_backup_pagecount() and sqlite3_backup_remaining() until after the next sqlite3_backup_step().

Concurrent Usage of Database Handles

The source database connection may be used by the application for other purposes while a backup operation is underway or being initialized. If SQLite is compiled and configured to support threadsafe database connections, then the source database connection may be used concurrently from within other threads.

However, the application must guarantee that the destination database connection is not passed to any other API (by any thread) after sqlite3_backup_init() is called and before the corresponding call to sqlite3_backup_finish(). SQLite does not currently check to see if the application incorrectly accesses the destination database connection and so no error code is reported, but the operations may malfunction nevertheless. Use of the destination database connection while a backup is in progress might also cause a mutex deadlock.

If running in shared cache mode, the application must guarantee that the shared cache used by the destination database is not accessed while the backup is running. In practice this means that the application must guarantee that the disk file being backed up to is not accessed by any connection within the process, not just the specific connection that was passed to sqlite3_backup_init().

The sqlite3_backup object itself is partially threadsafe. Multiple threads may safely make multiple concurrent calls to sqlite3_backup_step(). However, the sqlite3_backup_remaining() and sqlite3_backup_pagecount() APIs are not strictly speaking threadsafe. If they are invoked at the same time as another thread is invoking sqlite3_backup_step() it is possible that they return invalid values.

Alternatives To Using The Backup API

Other techniques for safely creating a consistent backup of an SQLite database include:

See also lists of Objects, Constants, and Functions.

百度