From: drh Date: Tue, 20 Mar 2018 13:52:42 +0000 (+0000) Subject: Merge all recent enhancements from trunk. X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3a5fc008088af750443eef0f5de868e8c89a3b68;p=thirdparty%2Fsqlite.git Merge all recent enhancements from trunk. FossilOrigin-Name: b0c2f760a637ee973f4dcc27308eec44950e6d0a9c5ab5c828c1210c1f868efa --- 3a5fc008088af750443eef0f5de868e8c89a3b68 diff --cc manifest index 22fa622242,4bd7953ed9..25807c5b4c --- a/manifest +++ b/manifest @@@ -1,10 -1,10 +1,10 @@@ - C Update\sthis\sbranch\swith\srecent\scheckpoint\srelated\schanges\sfrom\strunk. - D 2018-03-02T17:59:37.964 -C Avoid\sunnecessary\swrite\sto\sthe\ssqlite_sequence\stable\swhen\san\sinsert\nis\sdone\sinto\san\sautoincrement\stable\swith\san\sapplication-specified\srowid\nthat\sis\sless\sthan\sthe\smaximum. -D 2018-03-20T13:44:10.070 ++C Merge\sall\srecent\senhancements\sfrom\strunk. ++D 2018-03-20T13:52:42.504 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea - F Makefile.in a2d2fb8d17c39ab5ec52beb27850b903949080848236923f436156b72a958737 + F Makefile.in 7016fc56c6b9bfe5daac4f34be8be38d8c0b5fab79ccbfb764d3b23bf1c6fff3 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 - F Makefile.msc bf19d3a0eb849bd3b114653b0e455aa5b2799a96f413287a5866013db0e47f30 + F Makefile.msc 8a6727b41a4626a5552016f4b0088b43fb14a32f53db1f47e83a0fefcb63c49a F README.md 1d5342ebda97420f114283e604e5fe99b0da939d63b76d492eabbaae23488276 F VERSION cdf91ac446255ecf3d8f6d8c3ee40d64123235ae5b3cef29d344e61b45ec3759 F aclocal.m4 a5c22d164aff7ed549d53a90fa56d56955281f50 @@@ -404,18 -402,16 +404,18 @@@ F ext/session/sessionfault.test da273f2 F ext/session/sessionfault2.test 04aa0bc9aa70ea43d8de82c4f648db4de1e990b0 F ext/session/sessionstat1.test 41cd97c2e48619a41cdf8ae749e1b25f34719de638689221aa43971be693bf4e F ext/session/sessionwor.test 2f3744236dc8b170a695b7d8ddc8c743c7e79fdc -F ext/session/sqlite3session.c 9edfaaa74977ddecd7bbd94e8f844d9b0f6eec22d1d547e806361670db814c1e -F ext/session/sqlite3session.h 2e1584b030fbd841cefdce15ba984871978d305f586da2d1972f6e1958fa10b1 -F ext/session/test_session.c eb0bd6c1ea791c1d66ee4ef94c16500dad936386 +F ext/session/sqlite3changebatch.c d5553b79e012ee2cb06c0a96bdf9dfe19e66354390ea0036cc46c4953142d517 +F ext/session/sqlite3changebatch.h e72016998c9a22d439ddfd547b69e1ebac810c24 - F ext/session/sqlite3session.c 21810bc8a5571ebd4263053a2e4bc4e534444336a62248d60a08bae43ea62f20 ++F ext/session/sqlite3session.c 1c1164008ad756d4dd7a2cb651647925cd0a88378853b4f225bbc5aa18c042e2 +F ext/session/sqlite3session.h 1eb6bc132e1e23eba7290b8cb85141fa4ef6cb5c8104a6851a4c4e88512996b6 +F ext/session/test_session.c badd5da3cb561564b093745f7d843430d1d76347 F ext/userauth/sqlite3userauth.h 7f3ea8c4686db8e40b0a0e7a8e0b00fac13aa7a3 F ext/userauth/user-auth.txt e6641021a9210364665fe625d067617d03f27b04 F ext/userauth/userauth.c 3410be31283abba70255d71fd24734e017a4497f F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895 x F ltmain.sh 3ff0879076df340d2e23ae905484d8c15d5fdea8 F magic.txt 8273bf49ba3b0c8559cb2774495390c31fd61c60 - F main.mk 2263d738b707d420c24535a85aad10ab35be5d90a14660b325b2bc99e8b91085 -F main.mk 63668484c95454af7fc04a384da27ac556f27368d6d0c345e405e1677c66768f ++F main.mk 451db1a4c9a37a1a3c725a100d4169a0c797451c7aeb512fb07f1d32b78782c9 F mkso.sh fd21c06b063bb16a5d25deea1752c2da6ac3ed83 F mptest/config01.test 3c6adcbc50b991866855f1977ff172eb6d901271 F mptest/config02.test 4415dfe36c48785f751e16e32c20b077c28ae504 @@@ -429,18 -425,18 +429,18 @@@ F sqlite3.1 fc7ad8990fc8409983309bb80de F sqlite3.pc.in 48fed132e7cb71ab676105d2a4dc77127d8c1f3a F src/alter.c cf7a8af45cb0ace672f47a1b29ab24092a9e8cd8d945a9974e3b5d925f548594 F src/analyze.c 6b42e36a5dcc2703a771f2411bd5e99524bd62c7ecde209bb88dfb04c72f046e - F src/attach.c 79cb6b365d79b96b15dd429aa3e4c3b99335039e059baca8df28f1708fbff261 + F src/attach.c f6f212c43dddba79dfcb723fb9470785f3ff55bde8953cd9d2546f3022070a41 F src/auth.c 6277d63837357549fe14e723490d6dc1a38768d71c795c5eb5c0f8a99f918f73 F src/backup.c faf17e60b43233c214aae6a8179d24503a61e83b -F src/bitvec.c 17ea48eff8ba979f1f5b04cc484c7bb2be632f33 +F src/bitvec.c 8433d9e98dd6f2ea3286e0d2fe5d65de1bfc18a706486eb2026b01be066b5806 F src/btmutex.c 0e9ce2d56159b89b9bc8e197e023ee11e39ff8ca -F src/btree.c 18a53540aa35dbdf77f715ea928422a4ed9011dc16ea7b50f803fd1617fcc4f5 -F src/btree.h 0866c0a08255142ea0e754aabd211c843cab32045c978a592a43152405ed0c84 -F src/btreeInt.h 620ab4c7235f43572cf3ac2ac8723cbdf68073be4d29da24897c7b77dda5fd96 -F src/build.c 8b53aacc26944bb7fd9ab5ddeedecb4cc7c4b84df3a420cf6d2b8f772ad421df +F src/btree.c d070d79e81d76e521992a1f2e6b55892da04c35bbe493a07a3904a404e4416cc +F src/btree.h 0cd745755efd1f3df4c70544c54253920ea32fe6b179b97e9daeb786ba0de4ba +F src/btreeInt.h 6c65e6c96f561596f6870c79a64d4706af81613881d7947e3f063e923f14115f - F src/build.c 4584d3b8bf05dc3c6b58a3869d66707adf1a2d0c0dd278cbdf6698a3bfc95cc6 ++F src/build.c adf56922a67ae5cbfe4dd993ae3643b6cc319e3cb6768a8a7052c69e60054527 F src/callback.c fe677cb5f5abb02f7a772a62a98c2f516426081df68856e8f2d5f950929b966a F src/complete.c a3634ab1e687055cd002e11b8f43eb75c17da23e - F src/ctime.c ff1be3eed7bdd75aaca61ca8dc848f7c9f850ef2fb9cb56f2734e922a098f9c0 + F src/ctime.c bd9da3f1ff21b432564a16ef0b154cff03585dc43742842e99c58907c6cb4bef F src/date.c ebe1dc7c8a347117bb02570f1a931c62dd78f4a2b1b516f4837d45b7d6426957 F src/dbpage.c 8db4c97f630e7d83f884ea75caf1ffd0988c160e9d530194d93721c80821e0f6 F src/dbstat.c 7a4ba8518b6369ef3600c49cf9c918ad979acba610b2aebef1b656d649b96720 @@@ -454,10 -450,10 +454,10 @@@ F src/hash.c a12580e143f10301ed5166ea49 F src/hash.h ab34c5c54a9e9de2e790b24349ba5aab3dbb4fd4 F src/hwtime.h 747c1bbe9df21a92e9c50f3bbec1de841dc5e5da F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71 - F src/insert.c 14686083cedc198540b15a79586cdd4be2acf6d5fa97627e355f817ab07e9fee + F src/insert.c b9ff71cc2913d1d57698a1e22bf853261a9a642baf62bdf40ddeb3809adb85b5 F src/legacy.c 134ab3e3fae00a0f67a5187981d6935b24b337bcf0f4b3e5c9fa5763da95bf4e F src/loadext.c f6e4e416a736369f9e80eba609f0acda97148a8b0453784d670c78d3eed2f302 - F src/main.c 64a93806e98950ee872ee0952b43b62bb5f6cb10452b99ae5e5f77502d6b622d -F src/main.c c1e97e4c6fffff1fb1a6f1c48807386819af78657b4ae4acfd6d6d17353b8277 ++F src/main.c e4e95e03b9bfc5ecf14f1b5f547f822cc85e39b95890683e5a148283035a569a F src/malloc.c 07295435093ce354c6d9063ac05a2eeae28bd251d2e63c48b3d67c12c76f7e18 F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645 F src/mem1.c c12a42539b1ba105e3707d0e628ad70e611040d8f5e38cf942cee30c867083de @@@ -476,13 -473,13 +477,13 @@@ F src/os.c 22d31db3ca5a96a408fbf1ceeaae F src/os.h 48388821692e87da174ea198bf96b1b2d9d83be5dfc908f673ee21fafbe0d432 F src/os_common.h b2f4707a603e36811d9b1a13278bffd757857b85 F src/os_setup.h 0dbaea40a7d36bf311613d31342e0b99e2536586 -F src/os_unix.c 928586cbde31890538854f1657463392d63b2d7794f577774573ae53ec283d7b +F src/os_unix.c da5704d0c54eec4b8e02095782c0360af4edfbf7832191f5ff697fddfbb4f9ef F src/os_win.c eb03c6d52f893bcd7fdd4c6006674c13c1b5e49543fec98d605201af2997171c F src/os_win.h 7b073010f1451abe501be30d12f6bc599824944a - F src/pager.c fa0c6d8cc7483bcf5a3c02bc80a5162b81bf948e567113fda8bf548edc187131 -F src/pager.c 3e3b659b6b3f40b5a5efef6b8890ced490c397a81d96feb5266fde1f7362e608 -F src/pager.h 581698f2177e8bd4008fe4760898ce20b6133d1df22139b9101b5155f900df7a -F src/parse.y 140bbc53b5f67f731239f7fc8704a4f1e60cbbc10fb84bf9577322f974725f19 ++F src/pager.c e9b4176a83e86d4113757d2ad4ca82fd3961402e226e08274e3569ce39ae25a2 +F src/pager.h 72e1a29470f2c2ad482ce944f61c7818098a842740d94c2bd167f348da4fdbac - F src/parse.y 678b3afe0d9e79534295d8be4d4f4eebae5d6df2b0c402ac73650b240caedc30 - F src/pcache.c 7ae91a4557a43d77d449accbfdc68846e6516f8e2eda46e8bbe4536fb669b201 ++F src/parse.y 5e4afc0ca16cf5a0b464f49554f49bba03c455b9b973ec57665286f3f5abfbdb + F src/pcache.c 135ef0bc6fb2e3b7178d49ab5c9176254c8a691832c1bceb1156b2fbdd0869bd F src/pcache.h 072f94d29281cffd99e46c1539849f248c4b56ae7684c1f36626797fee375170 F src/pcache1.c 716975564c15eb6679e97f734cec1bfd6c16ac3d4010f05f1f8e509fc7d19880 F src/pragma.c bea56df3ae0637768c0da4fbbb8f2492f780980d95000034a105ff291bf7ca69 @@@ -492,17 -489,17 +493,17 @@@ F src/printf.c d3b7844ddeb11fbbdd38dd84 F src/random.c 80f5d666f23feb3e6665a6ce04c7197212a88384 F src/resolve.c 66c73fcb7719b8ff0e841b58338f13604ff3e2b50a723f9b8f383595735262f6 F src/rowset.c 7b7e7e479212e65b723bf40128c7b36dc5afdfac - F src/select.c f02352ac5cbb6fad3804add825743b924cfb6c742ba2e8666d726828a9985d73 - F src/shell.c.in 47dac081e15544f4d4373a837215391459971b312c8bed15903e7e9045c3e652 - F src/sqlite.h.in 5576a6e50560b23fb072d5824e5b60084275897eaec8235d98a81fcaa316db6d + F src/select.c 97a2131f02c605c52a6d5deac5b2ae6604db8c346829eb6b185bc38512a9b49a + F src/shell.c.in 911b9e3bce40413c78fdba28efa28363e98183819bd4b300780bf57bacfc4b84 -F src/sqlite.h.in 19762b57baa1ade67531f254de94374428fb9c82452ef305017847945f9c2911 ++F src/sqlite.h.in a95e2ac3a11c2d44faf18700c5ecc8beffc1409a0d21d8b855f1821469dd32c1 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 83a3c4ce93d650bedfd1aa558cb85a516bd6d094445ee989740827d0d944368d - F src/sqliteInt.h 51c1a7062421433bd7b352e51b4fbce9aad1d74f10fdf2597760df24dfb87024 -F src/sqliteInt.h 5c07bbc55d9eb3389a10536bd008e2d6f20f586871972610431d943595b40ca4 ++F src/sqliteInt.h 29a4735667bcc384d9b329ebbb1a2a172a9194f4dd5f392fdaf830cbcdccae0e F src/sqliteLimit.h 1513bfb7b20378aa0041e7022d04acb73525de35b80b252f1b83fedb4de6a76b - F src/status.c 9737ed017279a9e0c5da748701c3c7bf1e8ae0dae459aad20dd64fcff97a7e35 + F src/status.c 46e7aec11f79dad50965a5ca5fa9de009f7d6bde08be2156f1538a0a296d4d0e F src/table.c b46ad567748f24a326d9de40e5b9659f96ffff34 - F src/tclsqlite.c 11a2618c227fd13ccad73ee02d1199f9880c59db2b3144fd7432db1980a2577d + F src/tclsqlite.c 916a92de77ec5cbe27818ca194d8cf0c58aa7ad5b87527098f6aa5a6068800ce -F src/test1.c 1ab7cbbb6693e08364c1a9241e2aee17f8c4925e4cc52396be77ae6845a05828 +F src/test1.c c2b5de91195cf2911760cfe543eb1bf315a01e1db32a95d2ba5d8fe6be06f41c F src/test2.c 3efb99ab7f1fc8d154933e02ae1378bac9637da5 F src/test3.c b8434949dfb8aff8dfa082c8b592109e77844c2135ed3c492113839b6956255b F src/test4.c 18ec393bb4d0ad1de729f0b94da7267270f3d8e6 @@@ -517,7 -514,7 +518,7 @@@ F src/test_backup.c bf5da90c9926df0a4b9 F src/test_bestindex.c 78809f11026f18a93fcfd798d9479cba37e1201c830260bf1edc674b2fa9b857 F src/test_blob.c ae4a0620b478548afb67963095a7417cd06a4ec0a56adb453542203bfdcb31ce F src/test_btree.c 8b2dc8b8848cf3a4db93f11578f075e82252a274 - F src/test_config.c 621e3330989efdacce8e7b1e2ea4c0864bada1e7ea746ce3ba01e7466409580c -F src/test_config.c 097c6189803886a1fb26ec37d8bc62b90512cb53ab79a1fb6d35196c1ec42ded ++F src/test_config.c 7f049288c6174ba7038f37b68c809897426790170b25c178bf18d7358e6eed69 F src/test_delete.c e2fe07646dff6300b48d49b2fee2fe192ed389e834dd635e3b3bac0ce0bf9f8f F src/test_demovfs.c a0c3bdd45ed044115c2c9f7779e56eafff18741e F src/test_devsym.c 1960abbb234b97e9b920f07e99503fc04b443f62bbc3c6ff2c2cea2133e3b8a2 @@@ -560,20 -557,20 +561,20 @@@ F src/trigger.c a34539c69433276d37b0da9 F src/update.c a90a32ffc0100265b0693dbbdbe490756447af181f5ea2c138cce515b08c8795 F src/utf.c 810fbfebe12359f10bc2a011520a6e10879ab2a163bcb26c74768eab82ea62a5 F src/util.c d9eb0a6c4aae1b00a7369eadd7ca0bbe946cb4c953b6751aa20d357c2f482157 -F src/vacuum.c 762ee9bbf8733d87d8cd06f58d950e881982e416f8c767334a40ffd341b6bff5 -F src/vdbe.c 066a4e1de2ed83e253adfd2e97a684cf562eaa41d31ee7f3d3e4c8aea4485a55 +F src/vacuum.c f0b8302219b00461ac0edbb790b5ef52d3d454a7ef9b78030a44b32bbdc39e8a - F src/vdbe.c 213097212a5e1836a57cd4faa396996234481d8351c29a417d9b648f0f53a10b ++F src/vdbe.c 6f4b0624d493d3abe189658593716854e531de1b043a20e23f4b960c32792e1e F src/vdbe.h 134beb7a12a6213c00eba58febaede33447cc4441bc568a0d9c144b33fc3720a F src/vdbeInt.h 95f7adfdc5c8f1353321f55a6c5ec00a90877e3b85af5159e393afb41ff54110 - F src/vdbeapi.c fea41171884a4de119f8b10ab514c788674eeeb7f27218bb6d008e1310bfd07f + F src/vdbeapi.c 29d2baf9c1233131ec467d7bed1b7c8a03c27579048d768c4b04acf427838858 -F src/vdbeaux.c 2756ac68ac259c416554100598fc291870063288cd7e1af22847f57b3e130e56 +F src/vdbeaux.c db9d38ca41466d5cc845bedbf88f470eefb5c4edaff2070249fa08a40273d1a1 F src/vdbeblob.c f5c70f973ea3a9e915d1693278a5f890dc78594300cf4d54e64f2b0917c94191 F src/vdbemem.c 414e28d3a7e2a8bee2bb247de115dcbc68e3cbac284d5862d077002f7a93bce1 F src/vdbesort.c 731a09e5cb9e96b70c394c1b7cf3860fbe84acca7682e178615eb941a3a0ef2f F src/vdbetrace.c 48e11ebe040c6b41d146abed2602e3d00d621d7ebe4eb29b0a0f1617fd3c2f6c F src/vtab.c 0e4885495172e1bdf54b12cce23b395ac74ef5729031f15e1bc1e3e6b360ed1a F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9 - F src/wal.c b6ad12df144846d02db4a18cadf9e5fcf39f1d7b7156f94131ab4076384dec07 -F src/wal.c aa9cffc7a2bad6b826a86c8562dd4978398720ed41cb8ee7aa9d054eb8b456a0 -F src/wal.h 8de5d2d3de0956d6f6cb48c83a4012d5f227b8fe940f3a349a4b7e85ebcb492a ++F src/wal.c 05d9364fefacdff639b7fb63b1113317e045e2ae5c7908fa50157f9f24883257 +F src/wal.h 1713fefe4587678c295bbeb91c4e7442998ad74f19249869ce49dda9e8ce5d53 F src/walker.c da987a20d40145c0a03c07d8fefcb2ed363becc7680d0500d9c79915591f5b1f F src/where.c 7cae47e813393d70c6d327fdf000fcb30f76b1b0b5a5b52ff6402e0c658de32c F src/whereInt.h 82c04c5075308abbac59180c8bad5ecb45b07453981f60a53f3c7dee21e1e971 @@@ -1719,7 -1712,8 +1723,7 @@@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a9 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 - P 36801effa9ec67b551f58972e21794466420f10cd0420701fcd87695e6cd11ee 044b0b65e716bffeddedbd1b0360c4c332f6d2359167c1d327a5ff96539474cb - R db5621b69ea924f8256c1ea108391b00 - U dan - Z 5f73e55771155cb4923ea7c8cff8af6b -P ae34edb7f4fa7b37a66cdf3a1d851980cb013e9abe72bdeca23e5323051e0646 3e3849a9d1a06673e6c713a42194f5da339fbf6533fa418c38f63d09bc045867 -R b14ad23178f33348049b37fe5dfca3b5 -T +closed 3e3849a9d1a06673e6c713a42194f5da339fbf6533fa418c38f63d09bc045867 ++P fb6b7938601505186c0b1f0df6c45630039027f85ff394d290bc2c86b16a3a07 ec7addc87f97bcff3c3694b14a680453b52de3f8c106436f0708a1cc04b90faa ++R 43c5e6204e5e1e748f1b8270da37c665 + U drh -Z 2e0c8bc153c99ae88009245613a69afa ++Z dfd53febd46dc841536127bb8e42a571 diff --cc manifest.uuid index fc240c969c,be127d7703..e069a3d23c --- a/manifest.uuid +++ b/manifest.uuid @@@ -1,1 -1,1 +1,1 @@@ - fb6b7938601505186c0b1f0df6c45630039027f85ff394d290bc2c86b16a3a07 -ec7addc87f97bcff3c3694b14a680453b52de3f8c106436f0708a1cc04b90faa ++b0c2f760a637ee973f4dcc27308eec44950e6d0a9c5ab5c828c1210c1f868efa diff --cc src/pager.c index 9e1a32f1b8,e3881c6a89..6b1f501854 --- a/src/pager.c +++ b/src/pager.c @@@ -4680,14 -4619,9 +4681,15 @@@ static int pagerStress(void *p, PgHdr * return SQLITE_OK; } + pPager->aStat[PAGER_STAT_SPILL]++; pPg->pDirty = 0; if( pagerUseWal(pPager) ){ +#ifndef SQLITE_OMIT_CONCURRENT + /* If the transaction is a "BEGIN CONCURRENT" transaction, the page + ** cannot be flushed to disk. Return early in this case. */ + if( pPager->pAllRead ) return SQLITE_OK; +#endif + /* Write a single frame for this page to the log. */ rc = subjournalPageIfRequired(pPg); if( rc==SQLITE_OK ){ diff --cc src/sqlite.h.in index 13e9a59cf6,e7de61bce0..a8657979e3 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@@ -8729,31 -8748,128 +8748,153 @@@ SQLITE_EXPERIMENTAL int sqlite3_snapsho */ SQLITE_EXPERIMENTAL int sqlite3_snapshot_recover(sqlite3 *db, const char *zDb); +/* +** CAPI3REF: Wal related information regarding the most recent COMMIT +** EXPERIMENTAL +** +** This function reports on the state of the wal file (if any) for database +** zDb, which should be "main", "temp", or the name of the attached database. +** Its results - the values written to the output parameters - are only +** defined if the most recent SQL command on the connection was a successful +** COMMIT that wrote data to wal-mode database zDb. +** +** Assuming the above conditions are met, output parameter (*pnFrame) is set +** to the total number of frames in the wal file. Parameter (*pnPrior) is +** set to the number of frames that were present in the wal file before the +** most recent transaction was committed. So that the number of frames written +** by the most recent transaction is (*pnFrame)-(*pnPrior). +** +** If successful, SQLITE_OK is returned. Otherwise, an SQLite error code. It +** is not an error if this function is called at a time when the results +** are undefined. +*/ +SQLITE_EXPERIMENTAL int sqlite3_wal_info( + sqlite3 *db, const char *zDb, + unsigned int *pnPrior, unsigned int *pnFrame +); + + /* + ** CAPI3REF: Serialize a database + ** + ** The sqlite3_serialize(D,S,P,F) interface returns a pointer to memory + ** that is a serialization of the S database on [database connection] D. + ** If P is not a NULL pointer, then the size of the database in bytes + ** is written into *P. + ** + ** For an ordinary on-disk database file, the serialization is just a + ** copy of the disk file. For an in-memory database or a "TEMP" database, + ** the serialization is the same sequence of bytes which would be written + ** to disk if that database where backed up to disk. + ** + ** The usual case is that sqlite3_serialize() copies the serialization of + ** the database into memory obtained from [sqlite3_malloc64()] and returns + ** a pointer to that memory. The caller is responsible for freeing the + ** returned value to avoid a memory leak. However, if the F argument + ** contains the SQLITE_SERIALIZE_NOCOPY bit, then no memory allocations + ** are made, and the sqlite3_serialize() function will return a pointer + ** to the contiguous memory representation of the database that SQLite + ** is currently using for that database, or NULL if the no such contiguous + ** memory representation of the database exists. A contiguous memory + ** representation of the database will usually only exist if there has + ** been a prior call to [sqlite3_deserialize(D,S,...)] with the same + ** values of D and S. + ** The size of the database is written into *P even if the + ** SQLITE_SERIALIZE_NOCOPY bit is set but no contigious copy + ** of the database exists. + ** + ** A call to sqlite3_serialize(D,S,P,F) might return NULL even if the + ** SQLITE_SERIALIZE_NOCOPY bit is omitted from argument F if a memory + ** allocation error occurs. + ** + ** This interface is only available if SQLite is compiled with the + ** [SQLITE_ENABLE_DESERIALIZE] option. + */ + unsigned char *sqlite3_serialize( + sqlite3 *db, /* The database connection */ + const char *zSchema, /* Which DB to serialize. ex: "main", "temp", ... */ + sqlite3_int64 *piSize, /* Write size of the DB here, if not NULL */ + unsigned int mFlags /* Zero or more SQLITE_SERIALIZE_* flags */ + ); + + /* + ** CAPI3REF: Flags for sqlite3_serialize + ** + ** Zero or more of the following constants can be OR-ed together for + ** the F argument to [sqlite3_serialize(D,S,P,F)]. + ** + ** SQLITE_SERIALIZE_NOCOPY means that [sqlite3_serialize()] will return + ** a pointer to contiguous in-memory database that it is currently using, + ** without making a copy of the database. If SQLite is not currently using + ** a contiguous in-memory database, then this option causes + ** [sqlite3_serialize()] to return a NULL pointer. SQLite will only be + ** using a contiguous in-memory database if it has been initialized by a + ** prior call to [sqlite3_deserialize()]. + */ + #define SQLITE_SERIALIZE_NOCOPY 0x001 /* Do no memory allocations */ + + /* + ** CAPI3REF: Deserialize a database + ** + ** The sqlite3_deserialize(D,S,P,N,M,F) interface causes the + ** [database connection] D to disconnection from database S and then + ** reopen S as an in-memory database based on the serialization contained + ** in P. The serialized database P is N bytes in size. M is the size of + ** the buffer P, which might be larger than N. If M is larger than N, and + ** the SQLITE_DESERIALIZE_READONLY bit is not set in F, then SQLite is + ** permitted to add content to the in-memory database as long as the total + ** size does not exceed M bytes. + ** + ** If the SQLITE_DESERIALIZE_FREEONCLOSE bit is set in F, then SQLite will + ** invoke sqlite3_free() on the serialization buffer when the database + ** connection closes. If the SQLITE_DESERIALIZE_RESIZEABLE bit is set, then + ** SQLite will try to increase the buffer size using sqlite3_realloc64() + ** if writes on the database cause it to grow larger than M bytes. + ** + ** The sqlite3_deserialize() interface will fail with SQLITE_BUSY if the + ** database is currently in a read transaction or is involved in a backup + ** operation. + ** + ** If sqlite3_deserialize(D,S,P,N,M,F) fails for any reason and if the + ** SQLITE_DESERIALIZE_FREEONCLOSE bit is set in argument F, then + ** [sqlite3_free()] is invoked on argument P prior to returning. + ** + ** This interface is only available if SQLite is compiled with the + ** [SQLITE_ENABLE_DESERIALIZE] option. + */ + int sqlite3_deserialize( + sqlite3 *db, /* The database connection */ + const char *zSchema, /* Which DB to reopen with the deserialization */ + unsigned char *pData, /* The serialized database content */ + sqlite3_int64 szDb, /* Number bytes in the deserialization */ + sqlite3_int64 szBuf, /* Total size of buffer pData[] */ + unsigned mFlags /* Zero or more SQLITE_DESERIALIZE_* flags */ + ); + + /* + ** CAPI3REF: Flags for sqlite3_deserialize() + ** + ** The following are allowed values for 6th argument (the F argument) to + ** the [sqlite3_deserialize(D,S,P,N,M,F)] interface. + ** + ** The SQLITE_DESERIALIZE_FREEONCLOSE means that the database serialization + ** in the P argument is held in memory obtained from [sqlite3_malloc64()] + ** and that SQLite should take ownership of this memory and automatically + ** free it when it has finished using it. Without this flag, the caller + ** is resposible for freeing any dynamically allocated memory. + ** + ** The SQLITE_DESERIALIZE_RESIZEABLE flag means that SQLite is allowed to + ** grow the size of the database using calls to [sqlite3_realloc64()]. This + ** flag should only be used if SQLITE_DESERIALIZE_FREEONCLOSE is also used. + ** Without this flag, the deserialized database cannot increase in size beyond + ** the number of bytes specified by the M parameter. + ** + ** The SQLITE_DESERIALIZE_READONLY flag means that the deserialized database + ** should be treated as read-only. + */ + #define SQLITE_DESERIALIZE_FREEONCLOSE 1 /* Call sqlite3_free() on close */ + #define SQLITE_DESERIALIZE_RESIZEABLE 2 /* Resize using sqlite3_realloc64() */ + #define SQLITE_DESERIALIZE_READONLY 4 /* Database is read-only */ + /* ** Undo the hack that converts floating point types to integer for ** builds on processors without floating point support.