aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordrh <drh@noemail.net>2015-05-27 13:06:55 +0000
committerdrh <drh@noemail.net>2015-05-27 13:06:55 +0000
commitfccda8a162b99c9419c6bccad4d88459a4c2dc81 (patch)
tree68d54c7bc36171a5e9f72fc8bb1f8c552e9d48e5 /src
parentb95e1193d58be876cffb061424aae2e13115c338 (diff)
downloadsqlite-fccda8a162b99c9419c6bccad4d88459a4c2dc81.tar.gz
sqlite-fccda8a162b99c9419c6bccad4d88459a4c2dc81.zip
CTEs have never add working rowids. So disallow the use of the "rowid" column
within CTEs. FossilOrigin-Name: 0055df0445932a43e42b318ef88672dcbe312c3a
Diffstat (limited to 'src')
-rw-r--r--src/build.c2
-rw-r--r--src/parse.y2
-rw-r--r--src/resolve.c4
-rw-r--r--src/select.c2
-rw-r--r--src/sqliteInt.h6
5 files changed, 9 insertions, 7 deletions
diff --git a/src/build.c b/src/build.c
index 1cf427b03..ac423a285 100644
--- a/src/build.c
+++ b/src/build.c
@@ -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);
}
}
diff --git a/src/parse.y b/src/parse.y
index 72a0a6d22..4ee553cc3 100644
--- a/src/parse.y
+++ b/src/parse.y
@@ -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);
diff --git a/src/resolve.c b/src/resolve.c
index 23636eace..27eba9fd0 100644
--- a/src/resolve.c
+++ b/src/resolve.c
@@ -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;
diff --git a/src/select.c b/src/select.c
index 5626bb070..ad9571920 100644
--- a/src/select.c
+++ b/src/select.c
@@ -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 );
diff --git a/src/sqliteInt.h b/src/sqliteInt.h
index cba17d711..b55329fce 100644
--- a/src/sqliteInt.h
+++ b/src/sqliteInt.h
@@ -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.