|
|
d8894c |
Subject: [PATCH] Do not allow a virtual table to be renamed into the name of
|
|
|
d8894c |
one of its shadows.
|
|
|
d8894c |
|
|
|
d8894c |
---
|
|
|
d8894c |
src/alter.c | 5 ++++-
|
|
|
d8894c |
src/build.c | 28 ++++++++++++++++++++++------
|
|
|
d8894c |
src/sqliteInt.h | 5 +++++
|
|
|
d8894c |
3 files changed, 31 insertions(+), 7 deletions(-)
|
|
|
d8894c |
|
|
|
d8894c |
diff --git a/src/alter.c b/src/alter.c
|
|
|
d8894c |
index 1280e90..0fa24c0 100644
|
|
|
d8894c |
--- a/src/alter.c
|
|
|
d8894c |
+++ b/src/alter.c
|
|
|
d8894c |
@@ -117,7 +117,10 @@ void sqlite3AlterRenameTable(
|
|
|
d8894c |
/* Check that a table or index named 'zName' does not already exist
|
|
|
d8894c |
** in database iDb. If so, this is an error.
|
|
|
d8894c |
*/
|
|
|
d8894c |
- if( sqlite3FindTable(db, zName, zDb) || sqlite3FindIndex(db, zName, zDb) ){
|
|
|
d8894c |
+ if( sqlite3FindTable(db, zName, zDb)
|
|
|
d8894c |
+ || sqlite3FindIndex(db, zName, zDb)
|
|
|
d8894c |
+ || sqlite3IsShadowTableOf(db, pTab, zName)
|
|
|
d8894c |
+ ){
|
|
|
d8894c |
sqlite3ErrorMsg(pParse,
|
|
|
d8894c |
"there is already another table or index with this name: %s", zName);
|
|
|
d8894c |
goto exit_rename_table;
|
|
|
d8894c |
diff --git a/src/build.c b/src/build.c
|
|
|
d8894c |
index e0fed8a..426428b 100644
|
|
|
d8894c |
--- a/src/build.c
|
|
|
d8894c |
+++ b/src/build.c
|
|
|
d8894c |
@@ -1899,6 +1899,27 @@ static void convertToWithoutRowidTable(Parse *pParse, Table *pTab){
|
|
|
d8894c |
recomputeColumnsNotIndexed(pPk);
|
|
|
d8894c |
}
|
|
|
d8894c |
|
|
|
d8894c |
+
|
|
|
d8894c |
+#ifndef SQLITE_OMIT_VIRTUALTABLE
|
|
|
d8894c |
+/*
|
|
|
d8894c |
+** Return true if pTab is a virtual table and zName is a shadow table name
|
|
|
d8894c |
+** for that virtual table.
|
|
|
d8894c |
+*/
|
|
|
d8894c |
+int sqlite3IsShadowTableOf(sqlite3 *db, Table *pTab, const char *zName){
|
|
|
d8894c |
+ int nName; /* Length of zName */
|
|
|
d8894c |
+
|
|
|
d8894c |
+ if( !IsVirtual(pTab) ) return 0;
|
|
|
d8894c |
+ nName = sqlite3Strlen30(pTab->zName);
|
|
|
d8894c |
+ if( sqlite3_strnicmp(zName, pTab->zName, nName)!=0 ) return 0;
|
|
|
d8894c |
+ if( zName[nName]!='_' ) return 0;
|
|
|
d8894c |
+ Module *pMod = (Module*)sqlite3HashFind(&db->aModule, pTab->azModuleArg[0]);
|
|
|
d8894c |
+ if( pMod==0 ) return 0;
|
|
|
d8894c |
+ if( pMod->pModule->iVersion<3 ) return 0;
|
|
|
d8894c |
+ if( pMod->pModule->xShadowName==0 ) return 0;
|
|
|
d8894c |
+ return pMod->pModule->xShadowName(zName+nName+1);
|
|
|
d8894c |
+}
|
|
|
d8894c |
+#endif /* ifndef SQLITE_OMIT_VIRTUALTABLE */
|
|
|
d8894c |
+
|
|
|
d8894c |
#ifndef SQLITE_OMIT_VIRTUALTABLE
|
|
|
d8894c |
/*
|
|
|
d8894c |
** Return true if zName is a shadow table name in the current database
|
|
|
d8894c |
@@ -1910,7 +1931,6 @@ static void convertToWithoutRowidTable(Parse *pParse, Table *pTab){
|
|
|
d8894c |
static int isShadowTableName(sqlite3 *db, char *zName){
|
|
|
d8894c |
char *zTail; /* Pointer to the last "_" in zName */
|
|
|
d8894c |
Table *pTab; /* Table that zName is a shadow of */
|
|
|
d8894c |
- Module *pMod; /* Module for the virtual table */
|
|
|
d8894c |
|
|
|
d8894c |
zTail = strrchr(zName, '_');
|
|
|
d8894c |
if( zTail==0 ) return 0;
|
|
|
d8894c |
@@ -1919,11 +1939,7 @@ static int isShadowTableName(sqlite3 *db, char *zName){
|
|
|
d8894c |
*zTail = '_';
|
|
|
d8894c |
if( pTab==0 ) return 0;
|
|
|
d8894c |
if( !IsVirtual(pTab) ) return 0;
|
|
|
d8894c |
- pMod = (Module*)sqlite3HashFind(&db->aModule, pTab->azModuleArg[0]);
|
|
|
d8894c |
- if( pMod==0 ) return 0;
|
|
|
d8894c |
- if( pMod->pModule->iVersion<3 ) return 0;
|
|
|
d8894c |
- if( pMod->pModule->xShadowName==0 ) return 0;
|
|
|
d8894c |
- return pMod->pModule->xShadowName(zTail+1);
|
|
|
d8894c |
+ return sqlite3IsShadowTableOf(db, pTab, zName);
|
|
|
d8894c |
}
|
|
|
d8894c |
#else
|
|
|
d8894c |
# define isShadowTableName(x,y) 0
|
|
|
d8894c |
diff --git a/src/sqliteInt.h b/src/sqliteInt.h
|
|
|
d8894c |
index b7d3571..76337f7 100644
|
|
|
d8894c |
--- a/src/sqliteInt.h
|
|
|
d8894c |
+++ b/src/sqliteInt.h
|
|
|
d8894c |
@@ -4407,6 +4407,11 @@ void sqlite3AutoLoadExtensions(sqlite3*);
|
|
|
d8894c |
);
|
|
|
d8894c |
# define sqlite3VtabInSync(db) ((db)->nVTrans>0 && (db)->aVTrans==0)
|
|
|
d8894c |
#endif
|
|
|
d8894c |
+#ifndef SQLITE_OMIT_VIRTUALTABLE
|
|
|
d8894c |
+ int sqlite3IsShadowTableOf(sqlite3*,Table*,const char*);
|
|
|
d8894c |
+#else
|
|
|
d8894c |
+# define sqlite3IsShadowTableOf(A,B,C) 0
|
|
|
d8894c |
+#endif
|
|
|
d8894c |
int sqlite3VtabEponymousTableInit(Parse*,Module*);
|
|
|
d8894c |
void sqlite3VtabEponymousTableClear(sqlite3*,Module*);
|
|
|
d8894c |
void sqlite3VtabMakeWritable(Parse*,Table*);
|
|
|
d8894c |
--
|
|
|
d8894c |
2.24.1
|
|
|
d8894c |
|