If the new column name in an ALTER TABLE RENAME COLUMN statement is quoted,
then also use quotes for the column name in the edited SQL statements. FossilOrigin-Name: ca5184a25f9150540a3e401ef67df0606efa7a294d70e3fa5edad9854003eb36
This commit is contained in:
parent
b0c7920d86
commit
404c3ba0d6
14
manifest
14
manifest
@ -1,5 +1,5 @@
|
||||
C Avoid\san\sassert()\ssometimes\striggered\sby\sALTER\sTABLE\sRENAME\sCOLUMN\sin\snon-debug\sbuilds.
|
||||
D 2018-08-11T18:34:25.522
|
||||
C If\sthe\snew\scolumn\sname\sin\san\sALTER\sTABLE\sRENAME\sCOLUMN\sstatement\sis\squoted,\nthen\salso\suse\squotes\sfor\sthe\scolumn\sname\sin\sthe\sedited\sSQL\sstatements.
|
||||
D 2018-08-11T20:38:33.809
|
||||
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
|
||||
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
|
||||
F Makefile.in 0a3a6c81e6fcb969ff9106e882f0a08547014ba463cb6beca4c4efaecc924ee6
|
||||
@ -432,7 +432,7 @@ F spec.template 86a4a43b99ebb3e75e6b9a735d5fd293a24e90ca
|
||||
F sqlite.pc.in 42b7bf0d02e08b9e77734a47798d1a55a9e0716b
|
||||
F sqlite3.1 fc7ad8990fc8409983309bb80de8c811a7506786
|
||||
F sqlite3.pc.in 48fed132e7cb71ab676105d2a4dc77127d8c1f3a
|
||||
F src/alter.c 8c3ce11294672a328514ecd645e73a835a1dcb263f96f5a03c8f51788b259432
|
||||
F src/alter.c 87911da129f661ce101e9636656787a4c78ca66bb26212ccae55509ccadd6e7c
|
||||
F src/analyze.c 3dc6b98cf007b005af89df165c966baaa48e8124f38c87b4d2b276fe7f0b9eb9
|
||||
F src/attach.c 4bd5b92633671d3e8ce431153ebb1893b50335818423b5373f3f27969f79769a
|
||||
F src/auth.c 32a5bbe3b755169ab6c66311c5225a3cd4f75a46c041f7fb117e0cbb68055114
|
||||
@ -599,7 +599,7 @@ F test/alter.test b820ab9dcf85f8e3a65bc8326accb2f0c7be64ef
|
||||
F test/alter2.test 7ea05c7d92ac99349a802ef7ada17294dd647060
|
||||
F test/alter3.test 4d79934d812eaeacc6f22781a080f8cfe012fdc3
|
||||
F test/alter4.test b6d7b86860111864f6cddb54af313f5862dda23b
|
||||
F test/altercol.test 4b75873d10291311ac59bb2fdb16f1d7077641acdc2d4d6500a5312600e49147
|
||||
F test/altercol.test a64f69f67a8ac2ab7fd671b3166ad3454e0fea6bf8c22fdc3630a4b0cdeb57e8
|
||||
F test/altermalloc.test e81ac9657ed25c6c5bb09bebfa5a047cd8e4acfc
|
||||
F test/amatch1.test b5ae7065f042b7f4c1c922933f4700add50cdb9f
|
||||
F test/analyze.test b3a9c67d00e1df7588a5b7be9a0292899f94fe8cac1f94a017277474ca2e59df
|
||||
@ -1755,7 +1755,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 6595c8811f13719d0aed8041abc7e1cade41c57427bcbf3503e2e42408eaa03b
|
||||
R 25f48ed98267af2b0ec49eb02ce9f5ff
|
||||
P 520c1c75dae5e3f4695fcdf0aad5fb9f492f0e528b5fbb49d5d3b5fc02762f47
|
||||
R 42d189b99bda0a148c429a132edf76e5
|
||||
U dan
|
||||
Z 0e86d27a3bccdcdae5cb6df7ac4b0bc4
|
||||
Z 03ad3aa61b255b569ff4ff7e8834b149
|
||||
|
@ -1 +1 @@
|
||||
520c1c75dae5e3f4695fcdf0aad5fb9f492f0e528b5fbb49d5d3b5fc02762f47
|
||||
ca5184a25f9150540a3e401ef67df0606efa7a294d70e3fa5edad9854003eb36
|
33
src/alter.c
33
src/alter.c
@ -803,6 +803,7 @@ void sqlite3AlterRenameColumn(
|
||||
char *zNew = 0;
|
||||
const char *zDb;
|
||||
int iSchema;
|
||||
int bQuote;
|
||||
|
||||
pTab = sqlite3LocateTableItem(pParse, 0, &pSrc->a[0]);
|
||||
if( !pTab ) goto exit_rename_column;
|
||||
@ -824,14 +825,15 @@ void sqlite3AlterRenameColumn(
|
||||
|
||||
zNew = sqlite3NameFromToken(db, pNew);
|
||||
if( !zNew ) goto exit_rename_column;
|
||||
|
||||
assert( pNew->n>0 );
|
||||
bQuote = sqlite3Isquote(pNew->z[0]);
|
||||
sqlite3NestedParse(pParse,
|
||||
"UPDATE \"%w\".%s SET "
|
||||
"sql = sqlite_rename_column(sql, %d, %Q, %Q, %Q) "
|
||||
"sql = sqlite_rename_column(sql, %d, %d, %Q, %Q, %Q) "
|
||||
"WHERE name NOT LIKE 'sqlite_%%' AND ("
|
||||
" type = 'table' OR (type='index' AND tbl_name = %Q)"
|
||||
")",
|
||||
zDb, MASTER_NAME, iCol, zNew, pTab->zName, zOld, pTab->zName
|
||||
zDb, MASTER_NAME, iCol, bQuote, zNew, pTab->zName, zOld, pTab->zName
|
||||
);
|
||||
|
||||
/* Drop and reload the database schema. */
|
||||
@ -931,7 +933,7 @@ static RenameToken *renameColumnTokenNext(struct RenameCtx *pCtx){
|
||||
}
|
||||
|
||||
/*
|
||||
** sqlite_rename_table(SQL, iCol, zNew, zTable, zOld)
|
||||
** sqlite_rename_column(SQL, iCol, bQuote, zNew, zTable, zOld)
|
||||
*/
|
||||
static void renameColumnFunc(
|
||||
sqlite3_context *context,
|
||||
@ -942,10 +944,11 @@ static void renameColumnFunc(
|
||||
struct RenameCtx sCtx;
|
||||
const char *zSql = (const char*)sqlite3_value_text(argv[0]);
|
||||
int nSql = sqlite3_value_bytes(argv[0]);
|
||||
const char *zNew = (const char*)sqlite3_value_text(argv[2]);
|
||||
int nNew = sqlite3_value_bytes(argv[2]);
|
||||
const char *zTable = (const char*)sqlite3_value_text(argv[3]);
|
||||
const char *zOld = (const char*)sqlite3_value_text(argv[4]);
|
||||
int bQuote = sqlite3_value_int(argv[2]);
|
||||
const char *zNew = (const char*)sqlite3_value_text(argv[3]);
|
||||
int nNew = sqlite3_value_bytes(argv[3]);
|
||||
const char *zTable = (const char*)sqlite3_value_text(argv[4]);
|
||||
const char *zOld = (const char*)sqlite3_value_text(argv[5]);
|
||||
|
||||
int rc;
|
||||
char *zErr = 0;
|
||||
@ -991,12 +994,9 @@ static void renameColumnFunc(
|
||||
return;
|
||||
}
|
||||
|
||||
for(i=0; i<nNew; i++){
|
||||
if( sqlite3IsIdChar(zNew[i])==0 ){
|
||||
zNew = zQuot;
|
||||
nNew = nQuot;
|
||||
break;
|
||||
}
|
||||
if( bQuote ){
|
||||
zNew = zQuot;
|
||||
nNew = nQuot;
|
||||
}
|
||||
|
||||
#ifdef SQLITE_DEBUG
|
||||
@ -1059,7 +1059,8 @@ static void renameColumnFunc(
|
||||
sqlite3WalkExpr(&sWalker, sParse.pNewIndex->pPartIdxWhere);
|
||||
}
|
||||
|
||||
zOut = sqlite3DbMallocZero(db, nSql + sCtx.nList*nNew + 1);
|
||||
assert( nQuot>=nNew );
|
||||
zOut = sqlite3DbMallocZero(db, nSql + sCtx.nList*nQuot + 1);
|
||||
if( zOut ){
|
||||
int nOut = nSql;
|
||||
memcpy(zOut, zSql, nSql);
|
||||
@ -1109,7 +1110,7 @@ static void renameColumnFunc(
|
||||
void sqlite3AlterFunctions(void){
|
||||
static FuncDef aAlterTableFuncs[] = {
|
||||
FUNCTION(sqlite_rename_table, 2, 0, 0, renameTableFunc),
|
||||
FUNCTION(sqlite_rename_column, 5, 0, 0, renameColumnFunc),
|
||||
FUNCTION(sqlite_rename_column, 6, 0, 0, renameColumnFunc),
|
||||
#ifndef SQLITE_OMIT_TRIGGER
|
||||
FUNCTION(sqlite_rename_trigger, 2, 0, 0, renameTriggerFunc),
|
||||
#endif
|
||||
|
@ -200,5 +200,13 @@ do_execsql_test 6.1 {
|
||||
ALTER TABLE "blob" RENAME COLUMN "rid" TO "a1";
|
||||
}
|
||||
|
||||
do_catchsql_test 6.2 {
|
||||
ALTER TABLE "blob" RENAME COLUMN "a1" TO [where];
|
||||
} {0 {}}
|
||||
|
||||
do_execsql_test 6.3 {
|
||||
SELECT "where" FROM blob;
|
||||
} {}
|
||||
|
||||
finish_test
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user