@@ -21663,7 +21663,7 @@ SQLITE_PRIVATE void sqlite3Reindex(Parse*, Token*, Token*);
21663
21663
SQLITE_PRIVATE void sqlite3AlterFunctions(void);
21664
21664
SQLITE_PRIVATE void sqlite3AlterRenameTable(Parse*, SrcList*, Token*);
21665
21665
SQLITE_PRIVATE void sqlite3AlterRenameColumn(Parse*, SrcList*, Token*, Token*);
21666
- void libsqlAlterAlterColumn(Parse*, SrcList*, Token*, Token*);
21666
+ void libsqlAlterAlterColumn(Parse*, SrcList*, Token*, Token*, int );
21667
21667
SQLITE_PRIVATE int sqlite3GetToken(const unsigned char *, int *);
21668
21668
SQLITE_PRIVATE void sqlite3NestedParse(Parse*, const char*, ...);
21669
21669
SQLITE_PRIVATE void sqlite3ExpirePreparedStatements(sqlite3*, int);
@@ -116496,7 +116496,8 @@ void libsqlAlterAlterColumn(
116496
116496
Parse *pParse, /* Parsing context */
116497
116497
SrcList *pSrc, /* Table being altered. pSrc->nSrc==1 */
116498
116498
Token *pOld, /* Name of column being changed */
116499
- Token *pNew /* New column declaration */
116499
+ Token *pNew, /* New column declaration */
116500
+ int nNewSqlLength /* New column declaration SQL string length (pNew.z is the start of the declaration) */
116500
116501
){
116501
116502
sqlite3 *db = pParse->db; /* Database connection */
116502
116503
Table *pTab; /* Table being updated */
@@ -116554,9 +116555,7 @@ void libsqlAlterAlterColumn(
116554
116555
}
116555
116556
// NOTICE: this is the main difference in ALTER COLUMN compared to RENAME COLUMN,
116556
116557
// we just take the whole new column declaration as it is.
116557
- // FIXME: the semicolon can also appear in the middle of the declaration when it's quoted,
116558
- // so we should check from the end.
116559
- pNew->n = sqlite3Strlen30(pNew->z);
116558
+ pNew->n = nNewSqlLength;
116560
116559
while (pNew->n > 0 && pNew->z[pNew->n - 1] == ';') pNew->n--;
116561
116560
zNew = sqlite3DbStrNDup(db, pNew->z, pNew->n);
116562
116561
if( !zNew ) goto exit_update_column;
@@ -117577,9 +117576,11 @@ static void renameColumnFunc(
117577
117576
*/
117578
117577
static void alterColumnFunc(
117579
117578
sqlite3_context *context,
117580
- int NotUsed ,
117579
+ int argc ,
117581
117580
sqlite3_value **argv
117582
117581
){
117582
+ UNUSED_PARAMETER(argc);
117583
+
117583
117584
sqlite3 *db = sqlite3_context_db_handle(context);
117584
117585
RenameCtx sCtx;
117585
117586
const char *zSql = (const char*)sqlite3_value_text(argv[0]);
@@ -117602,7 +117603,6 @@ static void alterColumnFunc(
117602
117603
sqlite3_xauth xAuth = db->xAuth;
117603
117604
#endif
117604
117605
117605
- UNUSED_PARAMETER(NotUsed);
117606
117606
if( zSql==0 ) return;
117607
117607
if( zTable==0 ) return;
117608
117608
if( zNew==0 ) return;
@@ -117655,9 +117655,10 @@ static void alterColumnFunc(
117655
117655
}
117656
117656
} else {
117657
117657
rc = SQLITE_ERROR;
117658
- sParse.zErrMsg = sqlite3MPrintf(sParse.db, "Only ordinary tables can be altered, not ", IsView(sParse.pNewTable) ? "views" : "virtual tables");
117659
- goto alterColumnFunc_done; }
117660
- } else if (sParse.pNewIndex) {
117658
+ sParse.zErrMsg = sqlite3MPrintf(sParse.db, "Only ordinary tables can be altered, not %s", IsView(sParse.pNewTable) ? "views" : "virtual tables");
117659
+ goto alterColumnFunc_done;
117660
+ }
117661
+ } else if( sParse.pNewIndex ){
117661
117662
rc = SQLITE_ERROR;
117662
117663
sParse.zErrMsg = sqlite3MPrintf(sParse.db, "Only ordinary tables can be altered, not indexes");
117663
117664
goto alterColumnFunc_done;
@@ -176759,7 +176760,8 @@ static YYACTIONTYPE yy_reduce(
176759
176760
break;
176760
176761
case 301: /* cmd ::= ALTER TABLE fullname ALTER COLUMNKW columnname TO columnname carglist */
176761
176762
{
176762
- libsqlAlterAlterColumn(pParse, yymsp[-6].minor.yy203, &yymsp[-3].minor.yy0, &yymsp[-1].minor.yy0);
176763
+ int definitionLength = (int)(pParse->sLastToken.z-yymsp[-1].minor.yy0.z) + pParse->sLastToken.n;
176764
+ libsqlAlterAlterColumn(pParse, yymsp[-6].minor.yy203, &yymsp[-3].minor.yy0, &yymsp[-1].minor.yy0, definitionLength);
176763
176765
}
176764
176766
break;
176765
176767
case 302: /* cmd ::= create_vtab */
0 commit comments