From 4ee09b4bcc491037416597306a53b8508e4dbec3 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 1 May 2013 19:49:27 +0000 Subject: [PATCH 1/3] Allocate 4 bytes of unused header space for an "Application ID". Add the "PRAGMA application_id" command to set and query this identifier. Add the "magic.txt" file to show how the posix file command might use this application id. FossilOrigin-Name: 28c9e7fdee2471a3026ee05ff591194d5f398131 --- magic.txt | 28 ++++++++++++++++++++++++++++ manifest | 22 +++++++++++++--------- manifest.uuid | 2 +- src/btree.h | 1 + src/pragma.c | 9 +++++++++ test/pragma.test | 10 ++++++++++ tool/showdb.c | 2 +- 7 files changed, 63 insertions(+), 11 deletions(-) create mode 100644 magic.txt diff --git a/magic.txt b/magic.txt new file mode 100644 index 0000000000..22bdae5712 --- /dev/null +++ b/magic.txt @@ -0,0 +1,28 @@ +# This file contains suggested magic(5) text for the unix file(1) +# utility for recognizing SQLite3 databases. +# +# When SQLite is used as an application file format, it is desirable to +# have file(1) recognize the database file as being with the specific +# application. You can set the application_id for a database file +# using: +# +# PRAGMA application_id = INTEGER; +# +# INTEGER can be any signed 32-bit integer. That integer is written as +# a 4-byte big-endian integer into offset 68 of the database header. In +# the tests below, this integer is sometimes rendered as a string. For +# example, instead of "belong =1598444364" we write "string =_FSL" and +# instead of "belong =1598903374" we write "string =_MTN". +# +# The Monotone application used "PRAGMA user_version=1598903374;" to set +# its identifier long before "PRAGMA application_id" became available. +# The user_version is very similar to application_id except that it is +# stored at offset 60 instead of offset 68. The user of +# "PRAGMA application_id" is preferred now. The rules using offset 60 +# for Monotone are for historical compatibility only. +# +0 string =SQLite\ format\ 3 +>68 string =_FSL Fossil repository +>68 belong =0 +>>60 string =_MTN Monotone source repository +>>60 string !_MTN SQLite 3.x database diff --git a/manifest b/manifest index a5bd0b436b..706371cb24 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Do\snot\suse\sa\stransitive\sconstraint\sto\san\sIN\soperator\swhere\sthe\sRHS\sis\sa\nconstant\sif\sthere\sexists\sa\sdirect\s==\soperator\sto\sanother\stable\sin\san\souter\nloop. -D 2013-05-01T17:58:35.871 +C Allocate\s4\sbytes\sof\sunused\sheader\sspace\sfor\san\s"Application\sID".\s\sAdd\nthe\s"PRAGMA\sapplication_id"\scommand\sto\sset\sand\squery\sthis\sidentifier.\nAdd\sthe\s"magic.txt"\sfile\sto\sshow\show\sthe\sposix\sfile\scommand\smight\suse\nthis\sapplication\sid. +D 2013-05-01T19:49:27.740 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in ce81671efd6223d19d4c8c6b88ac2c4134427111 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -112,6 +112,7 @@ F ext/rtree/tkt3363.test 142ab96eded44a3615ec79fba98c7bde7d0f96de F ext/rtree/viewrtree.tcl eea6224b3553599ae665b239bd827e182b466024 F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895 x F ltmain.sh 3ff0879076df340d2e23ae905484d8c15d5fdea8 +F magic.txt 4255db3a17f0da4b3f561a904585a6605fe6a6b8 F main.mk 1b25be82452366abc27cc9ab2acf3244a773d5a1 F mkdll.sh 7d09b23c05d56532e9d44a50868eb4b12ff4f74a F mkextu.sh 416f9b7089d80e5590a29692c9d9280a10dbad9f @@ -137,7 +138,7 @@ F src/backup.c b266767351ae2d847716c56fcb2a1fea7c761c03 F src/bitvec.c 19a4ba637bd85f8f63fc8c9bae5ade9fb05ec1cb F src/btmutex.c 976f45a12e37293e32cae0281b15a21d48a8aaa7 F src/btree.c 480a6d255cc4f066029daf23dd54acf152cd0e13 -F src/btree.h d9490cd37aaeb530a41b07f06e1262950b1be916 +F src/btree.h 6fa8a3ff2483d0bb64a9f0105a8cedeac9e00cca F src/btreeInt.h eecc84f02375b2bb7a44abbcbbe3747dde73edb2 F src/build.c 083da8466fd7e481cb8bd5264398f537507f6176 F src/callback.c d7e46f40c3cf53c43550b7da7a1d0479910b62cc @@ -183,7 +184,7 @@ F src/parse.y 9708365594eea519cdc8504dee425c0a41c79502 F src/pcache.c f8043b433a57aba85384a531e3937a804432a346 F src/pcache.h a5e4f5d9f5d592051d91212c5949517971ae6222 F src/pcache1.c 9fd22671c270b35131ef480bbc00392b8b5f8ab9 -F src/pragma.c 3eacf001cbf4becbd494f8d82d08fdf1648cf8cb +F src/pragma.c 8779308bc1ea1901c4bc94dfe9a83d436f73f52c F src/prepare.c 743e484233c51109666d402f470523553b41797c F src/printf.c 4a9f882f1c1787a8b494a2987765acf9d97ac21f F src/random.c cd4a67b3953b88019f8cd4ccd81394a8ddfaba50 @@ -677,7 +678,7 @@ F test/pagesize.test 1dd51367e752e742f58e861e65ed7390603827a0 F test/pcache.test 065aa286e722ab24f2e51792c1f093bf60656b16 F test/pcache2.test a83efe2dec0d392f814bfc998def1d1833942025 F test/permutations.test 3d0bab9c49c1ec08b868059e30a3e1956f2162e2 -F test/pragma.test 60d29cd3d8098a2c20bf4c072810f99e3bf2757a +F test/pragma.test 5e7de6c32a5d764f09437d2025f07e4917b9e178 F test/pragma2.test 3a55f82b954242c642f8342b17dffc8b47472947 F test/printf.test ec9870c4dce8686a37818e0bf1aba6e6a1863552 F test/progress.test 5b075c3c790c7b2a61419bc199db87aaf48b8301 @@ -1040,7 +1041,7 @@ F tool/omittest.tcl 4665982e95a6e5c1bd806cf7bc3dea95be422d77 F tool/opcodeDoc.awk b3a2a3d5d3075b8bd90b7afe24283efdd586659c F tool/restore_jrnl.tcl 6957a34f8f1f0f8285e07536225ec3b292a9024a F tool/rollback-test.c 9fc98427d1e23e84429d7e6d07d9094fbdec65a5 -F tool/showdb.c acd24ea035a3bd2ffe266f1ef8a161812c29b2f0 +F tool/showdb.c 525ecc443578647703051308ad50a93de6ba2c4b F tool/showjournal.c b62cecaab86a4053d944c276bb5232e4d17ece02 F tool/showwal.c 3f7f7da5ec0cba51b1449a75f700493377da57b5 F tool/soak1.tcl 8d407956e1a45b485a8e072470a3e629a27037fe @@ -1060,7 +1061,10 @@ F tool/vdbe-compress.tcl f12c884766bd14277f4fcedcae07078011717381 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac -P 329478cbed06f93652de50abdb31a6b41af02b9e -R cc457983507eee39e1b071292dee5b26 +P faedaeace9c7ed9a8aaf96700caee09db0c0c061 +R 4f1b06c15d2f5747c86dc6db3cebcf91 +T *branch * application-id +T *sym-application-id * +T -sym-trunk * U drh -Z 944723cfd5dfa8d16765eaab2fd82886 +Z 76bc7425f1509081256079e29083992d diff --git a/manifest.uuid b/manifest.uuid index f88e8ae7a8..1b206e6fa8 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -faedaeace9c7ed9a8aaf96700caee09db0c0c061 \ No newline at end of file +28c9e7fdee2471a3026ee05ff591194d5f398131 \ No newline at end of file diff --git a/src/btree.h b/src/btree.h index 23f6ad7068..ace0f8cd21 100644 --- a/src/btree.h +++ b/src/btree.h @@ -140,6 +140,7 @@ int sqlite3BtreeNewDb(Btree *p); #define BTREE_TEXT_ENCODING 5 #define BTREE_USER_VERSION 6 #define BTREE_INCR_VACUUM 7 +#define BTREE_APPLICATION_ID 8 /* ** Values that may be OR'd together to form the second argument of an diff --git a/src/pragma.c b/src/pragma.c index 65efbd8b21..3056a7d8e2 100644 --- a/src/pragma.c +++ b/src/pragma.c @@ -1567,6 +1567,11 @@ void sqlite3Pragma( ** PRAGMA [database.]user_version ** PRAGMA [database.]user_version = ** + ** PRAGMA [database.]freelist_count = + ** + ** PRAGMA [database.]application_id + ** PRAGMA [database.]application_id = + ** ** The pragma's schema_version and user_version are used to set or get ** the value of the schema-version and user-version, respectively. Both ** the schema-version and the user-version are 32-bit signed integers @@ -1588,10 +1593,14 @@ void sqlite3Pragma( if( sqlite3StrICmp(zLeft, "schema_version")==0 || sqlite3StrICmp(zLeft, "user_version")==0 || sqlite3StrICmp(zLeft, "freelist_count")==0 + || sqlite3StrICmp(zLeft, "application_id")==0 ){ int iCookie; /* Cookie index. 1 for schema-cookie, 6 for user-cookie. */ sqlite3VdbeUsesBtree(v, iDb); switch( zLeft[0] ){ + case 'a': case 'A': + iCookie = BTREE_APPLICATION_ID; + break; case 'f': case 'F': iCookie = BTREE_FREE_PAGE_COUNT; break; diff --git a/test/pragma.test b/test/pragma.test index 3eb624328e..a6d198eb69 100644 --- a/test/pragma.test +++ b/test/pragma.test @@ -936,6 +936,16 @@ proc check_temp_store {} { return "unknown" } +# Application_ID +# +do_test pragma-8.3.1 { + execsql { + PRAGMA application_id; + } +} {0} +do_test pragma-8.3.2 { + execsql {PRAGMA Application_ID(12345); PRAGMA application_id;} +} {12345} # Test temp_store and temp_store_directory pragmas # diff --git a/tool/showdb.c b/tool/showdb.c index dbd79e9586..27424e0920 100644 --- a/tool/showdb.c +++ b/tool/showdb.c @@ -176,7 +176,7 @@ static void print_db_header(void){ print_decode_line(aData, 56, 4, "Text encoding"); print_decode_line(aData, 60, 4, "User version"); print_decode_line(aData, 64, 4, "Incremental-vacuum mode"); - print_decode_line(aData, 68, 4, "meta[7]"); + print_decode_line(aData, 68, 4, "Application ID"); print_decode_line(aData, 72, 4, "meta[8]"); print_decode_line(aData, 76, 4, "meta[9]"); print_decode_line(aData, 80, 4, "meta[10]"); From b8a67ec827b5a5987f447d68d63648bd2045b3cd Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 1 May 2013 20:36:23 +0000 Subject: [PATCH 2/3] Preserve the application-ID across VACUUM. Updates to the magic number file. FossilOrigin-Name: 4a190bea18e156b6fa4dc9f21c3ad32409049603 --- magic.txt | 11 ++++++----- manifest | 17 +++++++---------- manifest.uuid | 2 +- src/vacuum.c | 1 + 4 files changed, 15 insertions(+), 16 deletions(-) diff --git a/magic.txt b/magic.txt index 22bdae5712..90e2dc50a0 100644 --- a/magic.txt +++ b/magic.txt @@ -17,12 +17,13 @@ # The Monotone application used "PRAGMA user_version=1598903374;" to set # its identifier long before "PRAGMA application_id" became available. # The user_version is very similar to application_id except that it is -# stored at offset 60 instead of offset 68. The user of +# stored at offset 68 instead of offset 60. The user of # "PRAGMA application_id" is preferred now. The rules using offset 60 # for Monotone are for historical compatibility only. # 0 string =SQLite\ format\ 3 ->68 string =_FSL Fossil repository ->68 belong =0 ->>60 string =_MTN Monotone source repository ->>60 string !_MTN SQLite 3.x database +>68 belong =0x0f055111 Fossil repository - +>68 belong =0x0f055112 Fossil checkout - +>68 belong =0x0f055113 Fossil global configuration - +>60 belong =0x5f4d544e Monotone source repository - +>0 string =SQLite SQLite3 database diff --git a/manifest b/manifest index 706371cb24..06e860720a 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Allocate\s4\sbytes\sof\sunused\sheader\sspace\sfor\san\s"Application\sID".\s\sAdd\nthe\s"PRAGMA\sapplication_id"\scommand\sto\sset\sand\squery\sthis\sidentifier.\nAdd\sthe\s"magic.txt"\sfile\sto\sshow\show\sthe\sposix\sfile\scommand\smight\suse\nthis\sapplication\sid. -D 2013-05-01T19:49:27.740 +C Preserve\sthe\sapplication-ID\sacross\sVACUUM.\s\sUpdates\sto\sthe\smagic\snumber\nfile. +D 2013-05-01T20:36:23.594 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in ce81671efd6223d19d4c8c6b88ac2c4134427111 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -112,7 +112,7 @@ F ext/rtree/tkt3363.test 142ab96eded44a3615ec79fba98c7bde7d0f96de F ext/rtree/viewrtree.tcl eea6224b3553599ae665b239bd827e182b466024 F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895 x F ltmain.sh 3ff0879076df340d2e23ae905484d8c15d5fdea8 -F magic.txt 4255db3a17f0da4b3f561a904585a6605fe6a6b8 +F magic.txt 626cd2e726c22440f94d5342e872011990f90401 F main.mk 1b25be82452366abc27cc9ab2acf3244a773d5a1 F mkdll.sh 7d09b23c05d56532e9d44a50868eb4b12ff4f74a F mkextu.sh 416f9b7089d80e5590a29692c9d9280a10dbad9f @@ -250,7 +250,7 @@ F src/trigger.c cd95ac64efa60e39faf9b5597443192ff27a22fa F src/update.c a2a5631d618cbe240fc83725fa9e95c56ae0084c F src/utf.c 8d819e2e5104a430fc2005f018db14347c95a38f F src/util.c f566b5138099a2df8533b190d0dcc74b7dfbe0c9 -F src/vacuum.c 2727bdd08847fcb6b2d2da6d14f018910e8645d3 +F src/vacuum.c ddf21cc9577c4cb459d08bee9863a78ec000c5bb F src/vdbe.c 5f0047130f80c7fd0bc41bc51a653b5542c4fbd5 F src/vdbe.h b52887278cb173e66188da84dfab216bea61119d F src/vdbeInt.h c1e830268b75f04a2901dd895b51a637a26c7045 @@ -1061,10 +1061,7 @@ F tool/vdbe-compress.tcl f12c884766bd14277f4fcedcae07078011717381 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac -P faedaeace9c7ed9a8aaf96700caee09db0c0c061 -R 4f1b06c15d2f5747c86dc6db3cebcf91 -T *branch * application-id -T *sym-application-id * -T -sym-trunk * +P 28c9e7fdee2471a3026ee05ff591194d5f398131 +R eb1c61fca07cfc02ebd6d8ced912d19c U drh -Z 76bc7425f1509081256079e29083992d +Z b916c83ab322021bf56be2467b81fddd diff --git a/manifest.uuid b/manifest.uuid index 1b206e6fa8..f4b80354d1 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -28c9e7fdee2471a3026ee05ff591194d5f398131 \ No newline at end of file +4a190bea18e156b6fa4dc9f21c3ad32409049603 \ No newline at end of file diff --git a/src/vacuum.c b/src/vacuum.c index 7ed2478326..4afb2cca64 100644 --- a/src/vacuum.c +++ b/src/vacuum.c @@ -289,6 +289,7 @@ int sqlite3RunVacuum(char **pzErrMsg, sqlite3 *db){ BTREE_DEFAULT_CACHE_SIZE, 0, /* Preserve the default page cache size */ BTREE_TEXT_ENCODING, 0, /* Preserve the text encoding */ BTREE_USER_VERSION, 0, /* Preserve the user version */ + BTREE_APPLICATION_ID, 0, /* Preserve the application id */ }; assert( 1==sqlite3BtreeIsInTrans(pTemp) ); From 8a28a310281f08c81d0f1c1461ba71f6bf32397c Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 1 May 2013 20:40:46 +0000 Subject: [PATCH 3/3] Fix comments in the magic number file. FossilOrigin-Name: 5a500848d2fa96fc7397e2acb64d5ae6551b5b1e --- magic.txt | 11 ++++------- manifest | 12 ++++++------ manifest.uuid | 2 +- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/magic.txt b/magic.txt index 90e2dc50a0..c99b4e004c 100644 --- a/magic.txt +++ b/magic.txt @@ -9,17 +9,14 @@ # PRAGMA application_id = INTEGER; # # INTEGER can be any signed 32-bit integer. That integer is written as -# a 4-byte big-endian integer into offset 68 of the database header. In -# the tests below, this integer is sometimes rendered as a string. For -# example, instead of "belong =1598444364" we write "string =_FSL" and -# instead of "belong =1598903374" we write "string =_MTN". +# a 4-byte big-endian integer into offset 68 of the database header. # # The Monotone application used "PRAGMA user_version=1598903374;" to set # its identifier long before "PRAGMA application_id" became available. # The user_version is very similar to application_id except that it is -# stored at offset 68 instead of offset 60. The user of -# "PRAGMA application_id" is preferred now. The rules using offset 60 -# for Monotone are for historical compatibility only. +# stored at offset 68 instead of offset 60. The application_id pragma +# is preferred. The rule using offset 60 for Monotone is for historical +# compatibility only. # 0 string =SQLite\ format\ 3 >68 belong =0x0f055111 Fossil repository - diff --git a/manifest b/manifest index 06e860720a..89c31cf5be 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Preserve\sthe\sapplication-ID\sacross\sVACUUM.\s\sUpdates\sto\sthe\smagic\snumber\nfile. -D 2013-05-01T20:36:23.594 +C Fix\scomments\sin\sthe\smagic\snumber\sfile. +D 2013-05-01T20:40:46.379 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in ce81671efd6223d19d4c8c6b88ac2c4134427111 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -112,7 +112,7 @@ F ext/rtree/tkt3363.test 142ab96eded44a3615ec79fba98c7bde7d0f96de F ext/rtree/viewrtree.tcl eea6224b3553599ae665b239bd827e182b466024 F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895 x F ltmain.sh 3ff0879076df340d2e23ae905484d8c15d5fdea8 -F magic.txt 626cd2e726c22440f94d5342e872011990f90401 +F magic.txt 291863ca976425e2e7bf3f775eb98ece4dd120f6 F main.mk 1b25be82452366abc27cc9ab2acf3244a773d5a1 F mkdll.sh 7d09b23c05d56532e9d44a50868eb4b12ff4f74a F mkextu.sh 416f9b7089d80e5590a29692c9d9280a10dbad9f @@ -1061,7 +1061,7 @@ F tool/vdbe-compress.tcl f12c884766bd14277f4fcedcae07078011717381 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac -P 28c9e7fdee2471a3026ee05ff591194d5f398131 -R eb1c61fca07cfc02ebd6d8ced912d19c +P 4a190bea18e156b6fa4dc9f21c3ad32409049603 +R 22c224f485fe7b9b09b8cd93def953de U drh -Z b916c83ab322021bf56be2467b81fddd +Z f2d15752a1c82c60eb5f877e525be03c diff --git a/manifest.uuid b/manifest.uuid index f4b80354d1..4ee88a6f3c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -4a190bea18e156b6fa4dc9f21c3ad32409049603 \ No newline at end of file +5a500848d2fa96fc7397e2acb64d5ae6551b5b1e \ No newline at end of file