]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
CTEs have never add working rowids. So disallow the use of the "rowid" column no-rowid-in-cte
authordrh <drh@noemail.net>
Wed, 27 May 2015 13:06:55 +0000 (13:06 +0000)
committerdrh <drh@noemail.net>
Wed, 27 May 2015 13:06:55 +0000 (13:06 +0000)
within CTEs.

FossilOrigin-Name: 0055df0445932a43e42b318ef88672dcbe312c3a

manifest
manifest.uuid
src/build.c
src/parse.y
src/resolve.c
src/select.c
src/sqliteInt.h
test/with1.test
test/without_rowid1.test

index 7d61d9fee0c1c1adc9d81dbe3c7fdfb81e8534bc..d66700a24b6aff1f2b6207f11701e3bd26458281 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Avoid\sa\sbuffer\soverread\swhen\scomparing\sagainst\sa\scorrupt\srecord\sthat\sspans\sat\sleast\sone\soverflow\spage.
-D 2015-05-26T20:31:20.007
+C CTEs\shave\snever\sadd\sworking\srowids.\s\sSo\sdisallow\sthe\suse\sof\sthe\s"rowid"\scolumn\nwithin\sCTEs.
+D 2015-05-27T13:06:55.466
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in 3feb7cbdad8898fe7a8a24355b4a753029c3ec3b
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -195,7 +195,7 @@ F src/btmutex.c 45a968cc85afed9b5e6cf55bf1f42f8d18107f79
 F src/btree.c 51cafeb18184dcb46285120d5574da6e19c58362
 F src/btree.h 969adc948e89e449220ff0ff724c94bb2a52e9f1
 F src/btreeInt.h 973a22a6fd61350b454ad614832b1f0a5e25a1e4
-F src/build.c 9552e7490b0310a8c73fcf3a0c36e7624789d8df
+F src/build.c 85a169a0a22f8b80caf513eaf2944d39b979f571
 F src/callback.c 7b44ce59674338ad48b0e84e7b72f935ea4f68b0
 F src/complete.c a5cf5b4b56390cfb7b8636e8f7ddef90258dd575
 F src/ctime.c 5a0b735dc95604766f5dac73973658eef782ee8b
@@ -239,7 +239,7 @@ F src/os_win.c 97f7828a9554d753665b6fcf7540e31c2b3d6a6e
 F src/os_win.h eb7a47aa17b26b77eb97e4823f20a00b8bda12ca
 F src/pager.c 9bc918a009285f96ec6dac62dd764c7063552455
 F src/pager.h c3476e7c89cdf1c6914e50a11f3714e30b4e0a77
-F src/parse.y af55d4fb5e588705112e9788364ca3af09651fcf
+F src/parse.y 44e1605840c1662e08b05e175eb8bb13b9172662
 F src/pcache.c 10539fb959849ad6efff80050541cab3d25089d4
 F src/pcache.h b44658c9c932d203510279439d891a2a83e12ba8
 F src/pcache1.c 69d137620a305f814398bd29a0c998038c0695e9
@@ -248,14 +248,14 @@ F src/pragma.h 09c89bca58e9a44de2116cc8272b8d454657129f
 F src/prepare.c 82e5db1013846a819f198336fed72c44c974e7b1
 F src/printf.c 13ce37e5574f9b0682fa86dbcf9faf76b9d82a15
 F src/random.c ba2679f80ec82c4190062d756f22d0c358180696
-F src/resolve.c 99eabf7eff0bfa65b75939b46caa82e2b2133f28
+F src/resolve.c 84c571794e3ee5806274d95158a4c0177c6c4708
 F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e
-F src/select.c 9d9f6975bb538cafc5d4ae4a45565f15f5d296ff
+F src/select.c 4dcc45372759f98754cd6171e48ec2b592fae9b7
 F src/shell.c 07dda7cd692911d2f22269953418d049f2e2c0ee
 F src/sqlite.h.in 4d0ecd8e1e0272d9a2742b39602f5e4fad8d3246
 F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad
 F src/sqlite3ext.h 2ebeb634e751a61a6f0eebfa0f4669f46a42f6cd
-F src/sqliteInt.h 26484793b2f8017960b30ae2d0cbc7512eff5b17
+F src/sqliteInt.h 01d0b8741584a827c348d663cf09dcc7830b8ab3
 F src/sqliteLimit.h 216557999cb45f2e3578ed53ebefe228d779cb46
 F src/status.c f266ad8a2892d659b74f0f50cb6a88b6e7c12179
 F src/table.c 51b46b2a62d1b3a959633d593b89bab5e2c9155e
@@ -1212,10 +1212,10 @@ F test/wild001.test bca33f499866f04c24510d74baf1e578d4e44b1c
 F test/win32heap.test ea19770974795cff26e11575e12d422dbd16893c
 F test/win32lock.test fbf107c91d8f5512be5a5b87c4c42ab9fdd54972
 F test/win32longpath.test 169c75a3b2e43481f4a62122510210c67b08f26d
-F test/with1.test a86bf7f9288ba759a25ee57221d3bffaca36032a
+F test/with1.test e99845d4f4bf7863b61f104de554c61739d65764
 F test/with2.test ee227a663586aa09771cafd4fa269c5217eaf775
 F test/withM.test e97f2a8c506ab3ea9eab94e6f6072f6cc924c991
-F test/without_rowid1.test 4cda656cb4a452296e0d8d8623513f4be80c6d86
+F test/without_rowid1.test 1a7b9bd51b899928d327052df9741d2fe8dbe701
 F test/without_rowid2.test af260339f79d13cb220288b67cd287fbcf81ad99
 F test/without_rowid3.test 1081aabf60a1e1123b7f9a8f6ae19954351843b0
 F test/without_rowid4.test 4e08bcbaee0399f35d58b5581881e7a6243d458a
@@ -1279,7 +1279,10 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1
 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32
 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
-P b4a45d3b78fede2433ac18f20b1ab7bddee77059
-R f36cc3a04ab23b9a0c27493daaf0c4c0
-U dan
-Z 4ff3966eaffa78ba4bc7061be84a775f
+P 62a5b3633a086694ef0e579a0a82322cb1ae3d60
+R aaa91eb8edb393c58a97feb3495d55b8
+T *branch * no-rowid-in-cte
+T *sym-no-rowid-in-cte *
+T -sym-trunk *
+U drh
+Z 4d193f313220f26215dcddc13be0f0b2
index 110675c7e0b0e877534b2d64d215058c16d3d672..1d4ac265381759a9454cac4fbca0223d793f5f44 100644 (file)
@@ -1 +1 @@
-62a5b3633a086694ef0e579a0a82322cb1ae3d60
\ No newline at end of file
+0055df0445932a43e42b318ef88672dcbe312c3a
\ No newline at end of file
index 1cf427b03332ab271980c027b99478f48852ecdd..ac423a2856204111634417e56c34d41bd66d0603 100644 (file)
@@ -1844,7 +1844,7 @@ void sqlite3EndTable(
     if( (p->tabFlags & TF_HasPrimaryKey)==0 ){
       sqlite3ErrorMsg(pParse, "PRIMARY KEY missing on table %s", p->zName);
     }else{
-      p->tabFlags |= TF_WithoutRowid;
+      p->tabFlags |= TF_WithoutRowid | TF_NoVisibleRowid;
       convertToWithoutRowidTable(pParse, p);
     }
   }
index 72a0a6d222d02bc83fffecfefdaa12f5dfe0b443..4ee553cc33f9028ee34adb2f9e3dacceaab9c2a7 100644 (file)
@@ -166,7 +166,7 @@ create_table_args ::= AS select(S). {
 table_options(A) ::= .    {A = 0;}
 table_options(A) ::= WITHOUT nm(X). {
   if( X.n==5 && sqlite3_strnicmp(X.z,"rowid",5)==0 ){
-    A = TF_WithoutRowid;
+    A = TF_WithoutRowid | TF_NoVisibleRowid;
   }else{
     A = 0;
     sqlite3ErrorMsg(pParse, "unknown table option: %.*s", X.n, X.z);
index 23636eacec8b254966ca82b0e12569903716545f..27eba9fd07c7aada51d95cf865b20976b1047410 100644 (file)
@@ -358,7 +358,7 @@ static int lookupName(
             break;
           }
         }
-        if( iCol>=pTab->nCol && sqlite3IsRowid(zCol) && HasRowid(pTab) ){
+        if( iCol>=pTab->nCol && sqlite3IsRowid(zCol) && VisibleRowid(pTab) ){
           /* IMP: R-51414-32910 */
           /* IMP: R-44911-55124 */
           iCol = -1;
@@ -388,7 +388,7 @@ static int lookupName(
     ** Perhaps the name is a reference to the ROWID
     */
     if( cnt==0 && cntTab==1 && pMatch && sqlite3IsRowid(zCol)
-     && HasRowid(pMatch->pTab) ){
+     && VisibleRowid(pMatch->pTab) ){
       cnt = 1;
       pExpr->iColumn = -1;     /* IMP: R-44911-55124 */
       pExpr->affinity = SQLITE_AFF_INTEGER;
index 5626bb070ff5d7033a1a27146666dc0de25f61f6..ad957192096821f8ecca9d504daf857406ef310a 100644 (file)
@@ -3991,7 +3991,7 @@ static int withExpand(
     pTab->zName = sqlite3DbStrDup(db, pCte->zName);
     pTab->iPKey = -1;
     pTab->nRowLogEst = 200; assert( 200==sqlite3LogEst(1048576) );
-    pTab->tabFlags |= TF_Ephemeral;
+    pTab->tabFlags |= TF_Ephemeral | TF_NoVisibleRowid;
     pFrom->pSelect = sqlite3SelectDup(db, pCte->pSelect, 0);
     if( db->mallocFailed ) return SQLITE_NOMEM;
     assert( pFrom->pSelect );
index cba17d711a043eba6b89db1d22820a986726137f..b55329fcead00cbbe44a43d650823c6fc25862a9 100644 (file)
@@ -1634,8 +1634,9 @@ struct Table {
 #define TF_HasPrimaryKey   0x04    /* Table has a primary key */
 #define TF_Autoincrement   0x08    /* Integer primary key is autoincrement */
 #define TF_Virtual         0x10    /* Is a virtual table */
-#define TF_WithoutRowid    0x20    /* No rowid used. PRIMARY KEY is the key */
-#define TF_OOOHidden       0x40    /* Out-of-Order hidden columns */
+#define TF_WithoutRowid    0x20    /* No rowid.  PRIMARY KEY is the key */
+#define TF_NoVisibleRowid  0x40    /* No user-visible "rowid" column */
+#define TF_OOOHidden       0x80    /* Out-of-Order hidden columns */
 
 
 /*
@@ -1653,6 +1654,7 @@ struct Table {
 
 /* Does the table have a rowid */
 #define HasRowid(X)     (((X)->tabFlags & TF_WithoutRowid)==0)
+#define VisibleRowid(X) (((X)->tabFlags & TF_NoVisibleRowid)==0)
 
 /*
 ** Each foreign key constraint is an instance of the following structure.
index 80892d26422cf46cb2df0da6cd24530fd4055d31..8d8b6f75b563f6cd80921acacf321b0a9f843e05 100644 (file)
@@ -849,4 +849,13 @@ do_execsql_test 14.1 {
   WITH x AS (SELECT * FROM t) SELECT 0 EXCEPT SELECT 0 ORDER BY 1 COLLATE binary;
 } {}
 
+# 2015-05-27:  Do not allow rowid usage within a CTE
+#
+do_catchsql_test 15.1 {
+  WITH RECURSIVE
+    d(x) AS (VALUES(1) UNION ALL SELECT rowid+1 FROM d WHERE rowid<10)
+  SELECT x FROM d;
+} {1 {no such column: rowid}}
+
+
 finish_test
index b746cca27792fd9c9a8b9c5c1618e2f7481904f5..0c77773abb3e7812fb19c5f8ff76c8a91c835f6b 100644 (file)
@@ -308,6 +308,25 @@ do_execsql_test 6.1 {
   ok  t48   sqlite_autoindex_t48_2
 }
 
+# 2015-05-28: CHECK constraints can refer to the rowid in a
+# rowid table, but not in a WITHOUT ROWID table.
+#
+do_execsql_test 7.1 {
+  CREATE TABLE t70a(
+     a INT CHECK( rowid!=33 ),
+     b TEXT PRIMARY KEY
+  );
+  INSERT INTO t70a(a,b) VALUES(99,'hello');
+} {}
+do_catchsql_test 7.2 {
+  INSERT INTO t70a(rowid,a,b) VALUES(33,99,'xyzzy');
+} {1 {CHECK constraint failed: t70a}}
+do_catchsql_test 7.3 {
+  CREATE TABLE t70b(
+     a INT CHECK( rowid!=33 ),
+     b TEXT PRIMARY KEY
+  ) WITHOUT ROWID;
+} {1 {no such column: rowid}}
 
   
 finish_test