]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Add the schema6.test module for demonstrating schemas that generate identical
authordrh <drh@noemail.net>
Sun, 30 Jul 2017 19:50:42 +0000 (19:50 +0000)
committerdrh <drh@noemail.net>
Sun, 30 Jul 2017 19:50:42 +0000 (19:50 +0000)
and different content.

FossilOrigin-Name: ac1da06a829051d393ccb8bb986e78f5bd35b060687688f6b3661913b13c9a5a

manifest
manifest.uuid
src/tclsqlite.c
test/schema6.test [new file with mode: 0644]

index 62d342089fedf0edea928f187c2523af8ead0dca..f2fe31dd551560a77cc24d7635ba1a8aa796c393 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Correctly\shandle\san\s"INTEGER\sPRIMARY\sKEY\sUNIQUE"\scolumn\sin\sa\sWITHOUT\sROWID\ntable.\s\sThis\sis\sa\sfix\sfor\sticket\s[bc115541132dad136],\sa\sproblem\sdiscovered\nby\sOSSFuzz.
-D 2017-07-30T18:40:52.132
+C Add\sthe\sschema6.test\smodule\sfor\sdemonstrating\sschemas\sthat\sgenerate\sidentical\nand\sdifferent\scontent.
+D 2017-07-30T19:50:42.416
 F Makefile.in d9873c9925917cca9990ee24be17eb9613a668012c85a343aef7e5536ae266e8
 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434
 F Makefile.msc 02b469e9dcd5b7ee63fc1fb05babc174260ee4cfa4e0ef2e48c3c6801567a016
@@ -462,7 +462,7 @@ F src/sqliteInt.h a1b8df420e8fa80fda9414ab7784d6e62271e1f7d65034ffd3e906ee6f014d
 F src/sqliteLimit.h 1513bfb7b20378aa0041e7022d04acb73525de35b80b252f1b83fedb4de6a76b
 F src/status.c a9e66593dfb28a9e746cba7153f84d49c1ddc4b1
 F src/table.c b46ad567748f24a326d9de40e5b9659f96ffff34
-F src/tclsqlite.c 2c29b0b76e91edfd1b43bf135c32c8674710089197327682b6b7e6af88062c3d
+F src/tclsqlite.c 487951d81f9704800fd9f0ffdaa2f935a83ccb6be3575c2c4ef83e4789b4c828
 F src/test1.c cfb78b728b37ae3a2b14fe1b3a6c766e0da41370eda112594e698c94011b622e
 F src/test2.c 3efb99ab7f1fc8d154933e02ae1378bac9637da5
 F src/test3.c b8434949dfb8aff8dfa082c8b592109e77844c2135ed3c492113839b6956255b
@@ -1144,6 +1144,7 @@ F test/schema2.test 906408621ea881fdb496d878b1822572a34e32c5
 F test/schema3.test 1bc1008e1f8cb5654b248c55f27249366eb7ed38
 F test/schema4.test 3b26c9fa916abb6dadf894137adcf41b7796f7b9
 F test/schema5.test 29699b4421f183c8f0e88bd28ce7d75d13ea653e
+F test/schema6.test 54599bcf0b3cbc7f57cf02855453bbdafd77ab3cefff19cb9dd858e2ab70a91f
 F test/securedel.test 5f997cb6bd38727b81e0985f53ec386c99db6441b2b9e6357240649d29017239
 F test/securedel2.test 2d54c28e46eb1fd6902089958b20b1b056c6f1c5
 F test/select1.test be62204d2bd9a5a8a149e9974cfddce893d8f686
@@ -1637,7 +1638,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
 F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P bcec155e0d6c6b17ae09d5a366c080723d01ff40dbc1a0ad0bb669a91db1b850
-R ef51b40dfe561fead55e0d7326def69b
+P 5216bfb73f1a49bdd879d470de139bf46a212474eaf6f38ad2390536d66a2afd
+R fcd196b2f8d80f06448991a0e133e88e
 U drh
-Z cbc21ed1f3f9e538b2bc83c6e8eaa497
+Z e76a816e9e2c5e050973bdc6741b8e4d
index 096f15d137ad7159aa8857f50a1f3c4d302ec15d..2dc32f1a049d30a181e86d683138f2b07d153927 100644 (file)
@@ -1 +1 @@
-5216bfb73f1a49bdd879d470de139bf46a212474eaf6f38ad2390536d66a2afd
\ No newline at end of file
+ac1da06a829051d393ccb8bb986e78f5bd35b060687688f6b3661913b13c9a5a
\ No newline at end of file
index 341d3f0dc49774651a337db9d0f750251cab48c7..1b9f91405e5dc931f003a10a57eecf9be35bd7b5 100644 (file)
@@ -3882,28 +3882,39 @@ static int SQLITE_TCLAPI md5file_cmd(
   const char **argv
 ){
   FILE *in;
+  int ofst;
+  int amt;
   MD5Context ctx;
   void (*converter)(unsigned char*, char*);
   unsigned char digest[16];
   char zBuf[10240];
 
-  if( argc!=2 ){
+  if( argc!=2 && argc!=4 ){
     Tcl_AppendResult(interp,"wrong # args: should be \"", argv[0],
-        " FILENAME\"", (char*)0);
+        " FILENAME [OFFSET AMT]\"", (char*)0);
     return TCL_ERROR;
   }
+  if( argc==4 ){
+    ofst = atoi(argv[2]);
+    amt = atoi(argv[3]);
+  }else{
+    ofst = 0;
+    amt = 2147483647;
+  }
   in = fopen(argv[1],"rb");
   if( in==0 ){
     Tcl_AppendResult(interp,"unable to open file \"", argv[1],
          "\" for reading", (char*)0);
     return TCL_ERROR;
   }
+  fseek(in, ofst, SEEK_SET);
   MD5Init(&ctx);
-  for(;;){
+  while( amt>0 ){
     int n;
-    n = (int)fread(zBuf, 1, sizeof(zBuf), in);
+    n = (int)fread(zBuf, 1, sizeof(zBuf)<=amt ? sizeof(zBuf) : amt, in);
     if( n<=0 ) break;
     MD5Update(&ctx, (unsigned char*)zBuf, (unsigned)n);
+    amt -= n;
   }
   fclose(in);
   MD5Final(digest, &ctx);
diff --git a/test/schema6.test b/test/schema6.test
new file mode 100644 (file)
index 0000000..25bb91c
--- /dev/null
@@ -0,0 +1,162 @@
+# 2017-07-30
+#
+# The author disclaims copyright to this source code.  In place of
+# a legal notice, here is a blessing:
+#
+#    May you do good and not evil.
+#    May you find forgiveness for yourself and forgive others.
+#    May you share freely, never taking more than you give.
+#
+#***********************************************************************
+# 
+# This file implements tests to show that certain CREATE TABLE statements
+# generate identical database files.  For example, changes in identifier
+# names, white-space, and formatting of the CREATE TABLE statement should
+# produce identical table content.
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+set ::testprefix schema6
+
+# Command:   check_same_database_content TESTNAME SQL1 SQL2 SQL3 ...
+#
+# This command creates fresh databases using SQL1 and subsequent arguments
+# and checks to make sure the content of all database files is byte-for-byte
+# identical.  Page 1 of the database files is allowed to be different, since
+# page 1 contains the sqlite_master table which is expected to vary.
+#
+proc check_same_database_content {basename args} {
+  set i 0
+  set hash {}
+  foreach sql $args {
+    forcedelete test.db
+    sqlite3 db test.db
+    db eval $sql
+    set pgsz [db one {PRAGMA page_size}]
+    db close
+    set sz [file size test.db]
+    set thishash [md5file test.db $pgsz [expr {$sz-$pgsz}]]
+    if {$i==0} {
+      set hash $thishash
+    } else {
+      do_test $basename-$i "set x $thishash" $hash
+    }
+    incr i
+  }
+}
+
+# Command:   check_different_database_content TESTNAME SQL1 SQL2 SQL3 ...
+#
+# This command creates fresh databases using SQL1 and subsequent arguments
+# and checks to make sure the content of all database files is different
+# in ways other than on page 1.
+#
+proc check_different_database_content {basename args} {
+  set i 0
+  set hashes {}
+  foreach sql $args {
+    forcedelete test.db
+    sqlite3 db test.db
+    db eval $sql
+    set pgsz [db one {PRAGMA page_size}]
+    db close
+    set sz [file size test.db]
+    set thishash [md5file test.db $pgsz [expr {$sz-$pgsz}]]
+    set j [lsearch $hashes $thishash]
+    if {$j>=0} {
+      do_test $basename-$i "set x {$i is the same as $j}" "All are different"
+    } else {
+      do_test $basename-$i "set x {All are different}" "All are different"
+    }
+    lappend hashes $thishash
+    incr i
+  }
+}
+
+check_same_database_content 100 {
+  CREATE TABLE t1(a INTEGER PRIMARY KEY, b UNIQUE);
+  INSERT INTO t1(a,b) VALUES(123,'Four score and seven years ago...');
+} {
+  CREATE TABLE t1(xyz INTEGER, abc, PRIMARY KEY(xyz), UNIQUE(abc));
+  INSERT INTO t1(xyz,abc) VALUES(123,'Four score and seven years ago...');
+} {
+  CREATE TABLE t1(xyz INTEGER, abc, UNIQUE(abc), PRIMARY KEY(xyz));
+  INSERT INTO t1(xyz,abc) VALUES(123,'Four score and seven years ago...');
+} {
+  CREATE TABLE t1(a INTEGER PRIMARY KEY ASC, b UNIQUE);
+  INSERT INTO t1(a,b) VALUES(123,'Four score and seven years ago...');
+} {
+  CREATE TABLE t1(a INTEGER PRIMARY KEY, b);
+  CREATE UNIQUE INDEX t1b ON t1(b);
+  INSERT INTO t1(a,b) VALUES(123,'Four score and seven years ago...');
+} {
+  CREATE TABLE t1(a INTEGER PRIMARY KEY, b);
+  INSERT INTO t1(a,b) VALUES(123,'Four score and seven years ago...');
+  CREATE UNIQUE INDEX t1b ON t1(b);
+}
+
+check_same_database_content 110 {
+  CREATE TABLE t1(a INTEGER PRIMARY KEY UNIQUE, b UNIQUE);
+  INSERT INTO t1(a,b) VALUES(123,'Four score and seven years ago...');
+} {
+  CREATE TABLE t1(a INTEGER UNIQUE PRIMARY KEY, b UNIQUE);
+  INSERT INTO t1(a,b) VALUES(123,'Four score and seven years ago...');
+} {
+  CREATE TABLE t1(a INTEGER UNIQUE PRIMARY KEY, b UNIQUE, UNIQUE(a));
+  INSERT INTO t1(a,b) VALUES(123,'Four score and seven years ago...');
+} {
+  CREATE TABLE t1(a INTEGER UNIQUE PRIMARY KEY, b);
+  CREATE UNIQUE INDEX t1b ON t1(b);
+  INSERT INTO t1(a,b) VALUES(123,'Four score and seven years ago...');
+} {
+  CREATE TABLE t1(a INTEGER UNIQUE PRIMARY KEY, b);
+  INSERT INTO t1(a,b) VALUES(123,'Four score and seven years ago...');
+  CREATE UNIQUE INDEX t1b ON t1(b);
+}
+
+check_same_database_content 120 {
+  CREATE TABLE t1(a INTEGER PRIMARY KEY, b UNIQUE) WITHOUT ROWID;
+  INSERT INTO t1(a,b) VALUES(123,'Four score and seven years ago...');
+} {
+  CREATE TABLE t1(xyz INTEGER, abc, PRIMARY KEY(xyz), UNIQUE(abc))WITHOUT ROWID;
+  INSERT INTO t1(xyz,abc) VALUES(123,'Four score and seven years ago...');
+} {
+  CREATE TABLE t1(xyz INTEGER, abc, UNIQUE(abc), PRIMARY KEY(xyz))WITHOUT ROWID;
+  INSERT INTO t1(xyz,abc) VALUES(123,'Four score and seven years ago...');
+} {
+  CREATE TABLE t1(a INTEGER PRIMARY KEY ASC, b UNIQUE) WITHOUT ROWID;
+  INSERT INTO t1(a,b) VALUES(123,'Four score and seven years ago...');
+} {
+  CREATE TABLE t1(a INTEGER PRIMARY KEY UNIQUE, b UNIQUE) WITHOUT ROWID;
+  INSERT INTO t1(a,b) VALUES(123,'Four score and seven years ago...');
+} {
+  CREATE TABLE t1(a INTEGER UNIQUE PRIMARY KEY, b UNIQUE) WITHOUT ROWID;
+  INSERT INTO t1(a,b) VALUES(123,'Four score and seven years ago...');
+} {
+  CREATE TABLE t1(a INTEGER UNIQUE PRIMARY KEY, b UNIQUE, UNIQUE(a))
+       WITHOUT ROWID;
+  INSERT INTO t1(a,b) VALUES(123,'Four score and seven years ago...');
+} {
+  CREATE TABLE t1(a INTEGER PRIMARY KEY, b) WITHOUT ROWID;
+  CREATE UNIQUE INDEX t1b ON t1(b);
+  INSERT INTO t1(a,b) VALUES(123,'Four score and seven years ago...');
+} {
+  CREATE TABLE t1(a INTEGER PRIMARY KEY, b) WITHOUT ROWID;
+  INSERT INTO t1(a,b) VALUES(123,'Four score and seven years ago...');
+  CREATE UNIQUE INDEX t1b ON t1(b);
+}
+
+check_different_database_content 130 {
+  CREATE TABLE t1(a INTEGER PRIMARY KEY, b UNIQUE);
+  INSERT INTO t1(a,b) VALUES(123,'Four score and seven years ago...');
+} {
+  CREATE TABLE t1(a INTEGER PRIMARY KEY UNIQUE, b UNIQUE);
+  INSERT INTO t1(a,b) VALUES(123,'Four score and seven years ago...');
+} {
+  CREATE TABLE t1(a INTEGER PRIMARY KEY, b UNIQUE) WITHOUT ROWID;
+  INSERT INTO t1(a,b) VALUES(123,'Four score and seven years ago...');
+}
+
+
+finish_test