]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Additional test cases for tkt2822. Fix a related bug in printf(). (CVS 4624)
authordrh <drh@noemail.net>
Thu, 13 Dec 2007 17:50:22 +0000 (17:50 +0000)
committerdrh <drh@noemail.net>
Thu, 13 Dec 2007 17:50:22 +0000 (17:50 +0000)
FossilOrigin-Name: 8f184e40ff79c3c5ef98337615f58a4a6d0249dd

manifest
manifest.uuid
src/printf.c
test/tkt2822.test

index b92539930f2e512388c1972acc4bea451e5e3532..5c26290f79eb0f9d4866dd9f66e4b5880cd94424 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Return\san\serror\sif\sthe\suser\sattempts\sto\srename\sa\sview.\sRelated\sto\s(but\snot\sa\sfix\sfor)\s#2831.\s(CVS\s4623)
-D 2007-12-13T08:15:31
+C Additional\stest\scases\sfor\stkt2822.\s\sFix\sa\srelated\sbug\sin\sprintf().\s(CVS\s4624)
+D 2007-12-13T17:50:23
 F Makefile.arm-wince-mingw32ce-gcc ac5f7b2cef0cd850d6f755ba6ee4ab961b1fadf7
 F Makefile.in 0590398f62fc2c456ff4c45e9741f5a718b7e2ac
 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@@ -129,7 +129,7 @@ F src/pager.h f504f7ae84060fee0416a853e368d3d113c3d6fa
 F src/parse.y a780b33ef45dd7b3272319cf91e609d6f109a31c
 F src/pragma.c 0246032dbe681dded8710ac43eaf654eead1434e
 F src/prepare.c f811fdb6fd4a82cca673a6e1d5b041d6caf567f1
-F src/printf.c 5732e393c45be7c09bfca9a786daef017e0066ef
+F src/printf.c eb27822ba2eec669161409ca31279a24c26ac910
 F src/random.c 4a22746501bf36b0a088c66e38dde5daba6a35da
 F src/select.c 14c4a8e9d784bfc4bfbb1576226f2bc0b9fbfd10
 F src/server.c 087b92a39d883e3fa113cae259d64e4c7438bc96
@@ -479,7 +479,7 @@ F test/tkt2686.test 3022db0eee8ecf501f516557c77ef1c4039399cd
 F test/tkt2767.test 6b02308d553d194f329a469bf5c157fe724738d4
 F test/tkt2817.test 709a2201a5590bf56cb97f6fb168a62282203fd1
 F test/tkt2820.test 017fdee33aaef7abc092beab6088816f1942304b
-F test/tkt2822.test 1260ab1c84edccdb7dc27954bd555852d6877f2e
+F test/tkt2822.test 8b1526b1e5b0d38a1a993f7828fbb81759093686
 F test/tkt2832.test cd56dc66bb31898b7eb2146baa5bde2eb80f96fe
 F test/trace.test 75ffc1b992c780d054748a656e3e7fd674f18567
 F test/trans.test b73289992b46d38d9479ecc4fdc03d8edb2413dc
@@ -600,7 +600,7 @@ F www/tclsqlite.tcl 8be95ee6dba05eabcd27a9d91331c803f2ce2130
 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
 F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b
 F www/whentouse.tcl fc46eae081251c3c181bd79c5faef8195d7991a5
-P 2f88b9b3e3c9abc3ae4a5dcef82707dd74f8aace
-R c81a64bbb6406c1577adc63cf75c1142
-U danielk1977
-Z edcd429ac1cef28184ff735c983803e3
+P 19d56d997f50be81ac2baace16b7e7a1b674301a
+R 4b5d2fa59d2200569cc8c7fc8474c6f8
+U drh
+Z 31e1271ce8ebb5157a897446124f0d35
index 71f528b538dbbcfa7ea6be6e9e8b40e37120d800..35f98b3125df575148982e4fcf4067180ac833e9 100644 (file)
@@ -1 +1 @@
-19d56d997f50be81ac2baace16b7e7a1b674301a
\ No newline at end of file
+8f184e40ff79c3c5ef98337615f58a4a6d0249dd
\ No newline at end of file
index ab88e23fa56fd0d234e5f9e6b650e581541b8e47..eafe842a1c3222ccd79b066f99544eb644e4c543 100644 (file)
@@ -414,6 +414,13 @@ static void vxprintf(
         }
         bufpt = &buf[etBUFSIZE-1];
         if( xtype==etORDINAL ){
+          static const char zOrd[] = "thstndrd";
+          int x = longvalue % 10;
+          if( x>=4 || (longvalue/10)%10==1 ){
+            x = 0;
+          }
+          buf[etBUFSIZE-3] = zOrd[x*2];
+          buf[etBUFSIZE-2] = zOrd[x*2+1];
           bufpt -= 2;
         }
         {
@@ -426,13 +433,6 @@ static void vxprintf(
             longvalue = longvalue/base;
           }while( longvalue>0 );
         }
-        if( xtype==etORDINAL ){
-          static const char zOrd[] = "thstndrd";
-          int x = buf[etBUFSIZE-4] - '0';
-          if( x>=4 ) x = 0;
-          buf[etBUFSIZE-3] = zOrd[x*2];
-          buf[etBUFSIZE-2] = zOrd[x*2+1];
-        }
         length = &buf[etBUFSIZE-1]-bufpt;
         for(idx=precision-length; idx>0; idx--){
           *(--bufpt) = '0';                             /* Zero pad */
index 477510b47b405104abf0ab9250a194576525562a..1de9f3ddf1d742df0b97cb2be36af81a06cec6ba 100644 (file)
@@ -13,7 +13,7 @@
 # ORDER BY clauses on compound SELECT statements raised by ticket
 # #2822 have been dealt with.
 #
-# $Id: tkt2822.test,v 1.3 2007/12/13 07:58:51 danielk1977 Exp $
+# $Id: tkt2822.test,v 1.4 2007/12/13 17:50:23 drh Exp $
 #
 
 set testdir [file dirname $argv0]
@@ -35,8 +35,20 @@ source $testdir/tester.tcl
 # In the third rule, the expression must exactly match one
 # of the result columns.  The sequences of three rules is
 # attempted first on the left-most SELECT.  If that doesn't
-# work, we move to the right, one by one. This is not standard
-# SQL, it is an SQLite extension.
+# work, we move to the right, one by one.
+#
+# Rule (3) is not in standard SQL - it is an SQLite extension,
+# though one copied from PostgreSQL.  The rule for compound
+# queries where a search is made of SELECTs to the right
+# if the left-most SELECT does not match is not a part of
+# standard SQL either.  This extension is unique to SQLite
+# as far as we know.
+#
+# Rule (2) was added by the changes ticket #2822.  Prior to
+# that changes, SQLite did not support rule (2), making it
+# technically in violation of standard SQL semantics.  
+# No body noticed because rule (3) has the same effect as
+# rule (2) except in some obscure cases.
 #
 
 
@@ -156,5 +168,164 @@ do_test tkt2822-4.2 {
   }
 } {1 {1st ORDER BY term does not match any column in the result set}}
 
-finish_test
+# Tests for rule (2).
+#
+# The "ORDER BY b" should match the column alias (rule 2), not the
+# the t3.b value (rule 3).  
+#
+do_test tkt2822-5.1 {
+  execsql {
+    CREATE TABLE t3(a,b);
+    INSERT INTO t3 VALUES(1,8);
+    INSERT INTO t3 VALUES(9,2);
+
+    SELECT a AS b FROM t3 ORDER BY b;
+  }
+} {1 9}
+do_test tkt2822-5.2 {
+  # Case does not matter.  b should match B
+  execsql {
+    SELECT a AS b FROM t3 ORDER BY B;
+  }
+} {1 9}
+do_test tkt2822-5.3 {
+  # Quoting should not matter
+  execsql {
+    SELECT a AS 'b' FROM t3 ORDER BY "B";
+  }
+} {1 9}
+do_test tkt2822-5.4 {
+  # Quoting should not matter
+  execsql {
+    SELECT a AS "b" FROM t3 ORDER BY [B];
+  }
+} {1 9}
+
+# In "ORDER BY +b" the term is now an expression rather than
+# a label.  It therefore matches by rule (3) instead of rule (2).
+# 
+do_test tkt2822-5.5 {
+  execsql {
+    SELECT a AS b FROM t3 ORDER BY +b;
+  }
+} {9 1}
+
+# Tests for rule 2 in compound queries
+#
+do_test tkt2822-6.1 {
+  execsql {
+    CREATE TABLE t6a(p,q);
+    INSERT INTO t6a VALUES(1,8);
+    INSERT INTO t6a VALUES(9,2);
+    CREATE TABLE t6b(x,y);
+    INSERT INTO t6b VALUES(1,7);
+    INSERT INTO t6b VALUES(7,2);
 
+    SELECT p, q FROM t6a UNION ALL SELECT x, y FROM t6b ORDER BY 1, 2
+  }
+} {1 7 1 8 7 2 9 2}
+do_test tkt2822-6.2 {
+  execsql {
+    SELECT p PX, q QX FROM t6a UNION ALL SELECT x XX, y YX FROM t6b
+    ORDER BY PX, YX
+  }
+} {1 7 1 8 7 2 9 2}
+do_test tkt2822-6.3 {
+  execsql {
+    SELECT p PX, q QX FROM t6a UNION ALL SELECT x XX, y YX FROM t6b
+    ORDER BY XX, QX
+  }
+} {1 7 1 8 7 2 9 2}
+do_test tkt2822-6.4 {
+  execsql {
+    SELECT p PX, q QX FROM t6a UNION ALL SELECT x XX, y YX FROM t6b
+    ORDER BY QX, XX
+  }
+} {7 2 9 2 1 7 1 8}
+do_test tkt2822-6.5 {
+  execsql {
+    SELECT p PX, q QX FROM t6a UNION ALL SELECT x XX, y YX FROM t6b
+    ORDER BY t6b.x, QX
+  }
+} {1 7 1 8 7 2 9 2}
+do_test tkt2822-6.6 {
+  execsql {
+    SELECT p PX, q QX FROM t6a UNION ALL SELECT x XX, y YX FROM t6b
+    ORDER BY t6a.q, XX
+  }
+} {7 2 9 2 1 7 1 8}
+
+# More error message tests.  This is really more of a test of the
+# %r ordinal value formatting capablity added to sqlite3_snprintf()
+# by ticket #2822.
+#
+do_test tkt2822-7.1 {
+  execsql {
+    CREATE TABLE t7(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,
+                    a15,a16,a17,a18,a19,a20,a21,a22,a23,a24,a25);
+  }
+  catchsql {
+    SELECT * FROM t7 ORDER BY 0;
+  }
+} {1 {1st ORDER BY term out of range - should be between 1 and 25}}
+do_test tkt2822-7.2 {
+  catchsql {
+    SELECT * FROM t7 ORDER BY 1, 0;
+  }
+} {1 {2nd ORDER BY term out of range - should be between 1 and 25}}
+do_test tkt2822-7.3 {
+  catchsql {
+    SELECT * FROM t7 ORDER BY 1, 2, 0;
+  }
+} {1 {3rd ORDER BY term out of range - should be between 1 and 25}}
+do_test tkt2822-7.4 {
+  catchsql {
+    SELECT * FROM t7 ORDER BY 1, 2, 3, 0;
+  }
+} {1 {4th ORDER BY term out of range - should be between 1 and 25}}
+do_test tkt2822-7.9 {
+  catchsql {
+    SELECT * FROM t7 ORDER BY 1, 2, 3, 4, 5, 6, 7, 8, 0;
+  }
+} {1 {9th ORDER BY term out of range - should be between 1 and 25}}
+do_test tkt2822-7.10 {
+  catchsql {
+    SELECT * FROM t7 ORDER BY 1, 2, 3, 4, 5, 6, 7, 8, 9, 0;
+  }
+} {1 {10th ORDER BY term out of range - should be between 1 and 25}}
+do_test tkt2822-7.11 {
+  catchsql {
+    SELECT * FROM t7 ORDER BY 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 0;
+  }
+} {1 {11th ORDER BY term out of range - should be between 1 and 25}}
+do_test tkt2822-7.12 {
+  catchsql {
+    SELECT * FROM t7 ORDER BY 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 0;
+  }
+} {1 {12th ORDER BY term out of range - should be between 1 and 25}}
+do_test tkt2822-7.13 {
+  catchsql {
+    SELECT * FROM t7 ORDER BY 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 13, 0;
+  }
+} {1 {13th ORDER BY term out of range - should be between 1 and 25}}
+do_test tkt2822-7.20 {
+  catchsql {
+    SELECT * FROM t7 ORDER BY 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
+                             11,12,13,14,15,16,17,18,19, 0
+  }
+} {1 {20th ORDER BY term out of range - should be between 1 and 25}}
+do_test tkt2822-7.21 {
+  catchsql {
+    SELECT * FROM t7 ORDER BY 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
+                             11,12,13,14,15,16,17,18,19, 20, 0
+  }
+} {1 {21st ORDER BY term out of range - should be between 1 and 25}}
+do_test tkt2822-7.22 {
+  catchsql {
+    SELECT * FROM t7 ORDER BY 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
+                             11,12,13,14,15,16,17,18,19, 20, 21, 0
+  }
+} {1 {22nd ORDER BY term out of range - should be between 1 and 25}}
+
+
+finish_test