/ Check-in [91f701d3]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Fix a problem with renaming an INTEGER PRIMARY KEY column of a WITHOUT ROWID table using ALTER TABLE.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 91f701d39852ef1ddb29d1527d1520867c5efea110333315c55d8b08084384e7
User & Date: dan 2019-05-06 16:15:28
Context
2019-05-07
16:37
Optimize the restarting of an RBU vacuum. check-in: 82062351 user: dan tags: trunk
2019-05-06
16:15
Fix a problem with renaming an INTEGER PRIMARY KEY column of a WITHOUT ROWID table using ALTER TABLE. check-in: 91f701d3 user: dan tags: trunk
2019-05-04
17:32
Fix the NOT NULL logic in the theorem prover that determines when a partial index can be used. Ticket [5c6955204c392ae763a95]. check-in: c2e439bc user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/build.c.

  1855   1855     if( pTab->iPKey>=0 ){
  1856   1856       ExprList *pList;
  1857   1857       Token ipkToken;
  1858   1858       sqlite3TokenInit(&ipkToken, pTab->aCol[pTab->iPKey].zName);
  1859   1859       pList = sqlite3ExprListAppend(pParse, 0, 
  1860   1860                     sqlite3ExprAlloc(db, TK_ID, &ipkToken, 0));
  1861   1861       if( pList==0 ) return;
         1862  +    if( IN_RENAME_OBJECT ){
         1863  +      sqlite3RenameTokenRemap(pParse, pList->a[0].pExpr, &pTab->iPKey);
         1864  +    }
  1862   1865       pList->a[0].sortOrder = pParse->iPkSortOrder;
  1863   1866       assert( pParse->pNewTable==pTab );
         1867  +    pTab->iPKey = -1;
  1864   1868       sqlite3CreateIndex(pParse, 0, 0, 0, pList, pTab->keyConf, 0, 0, 0, 0,
  1865   1869                          SQLITE_IDXTYPE_PRIMARYKEY);
  1866   1870       if( db->mallocFailed || pParse->nErr ) return;
  1867   1871       pPk = sqlite3PrimaryKeyIndex(pTab);
  1868         -    pTab->iPKey = -1;
  1869   1872     }else{
  1870   1873       pPk = sqlite3PrimaryKeyIndex(pTab);
  1871   1874       assert( pPk!=0 );
  1872   1875   
  1873   1876       /*
  1874   1877       ** Remove all redundant columns from the PRIMARY KEY.  For example, change
  1875   1878       ** "PRIMARY KEY(a,b,a,b,c,b,c,d)" into just "PRIMARY KEY(a,b,c,d)".  Later

Changes to test/altertab.test.

   565    565     CREATE TABLE sqlite1234 (id integer);
   566    566     ALTER TABLE sqlite1234 RENAME TO User;
   567    567     SELECT name, sql FROM sqlite_master WHERE sql IS NOT NULL;
   568    568   } {
   569    569     User {CREATE TABLE "User" (id integer)}
   570    570   }
   571    571   
          572  +#-------------------------------------------------------------------------
          573  +reset_db
          574  +do_execsql_test 18.1.0 {
          575  +  CREATE TABLE t0 (c0 INTEGER, PRIMARY KEY(c0)) WITHOUT ROWID;
          576  +}
          577  +breakpoint
          578  +do_execsql_test 18.1.1 {
          579  +  ALTER TABLE t0 RENAME COLUMN c0 TO c1;
          580  +}
          581  +do_execsql_test 18.1.2 {
          582  +  SELECT sql FROM sqlite_master;
          583  +} {{CREATE TABLE t0 (c1 INTEGER, PRIMARY KEY(c1)) WITHOUT ROWID}}
          584  +
          585  +reset_db
          586  +do_execsql_test 18.2.0 {
          587  +  CREATE TABLE t0 (c0 INTEGER, PRIMARY KEY(c0));
          588  +}
          589  +do_execsql_test 18.2.1 {
          590  +  ALTER TABLE t0 RENAME COLUMN c0 TO c1;
          591  +}
          592  +do_execsql_test 18.2.2 {
          593  +  SELECT sql FROM sqlite_master;
          594  +} {{CREATE TABLE t0 (c1 INTEGER, PRIMARY KEY(c1))}}
          595  +
   572    596   finish_test
          597  +