SQLite
Check-in [d48f7bbdf4]
Not logged in
Overview
Comment:Fix a problem with renaming columns on tables with REFERENCES clauses that specify a large number of columns.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | alter-table-rename-column
Files: files | file ages | folders
SHA3-256:d48f7bbdf4a1686c25e634a8dec6ead88bf2866fee94ed8e5058f830363424a8
User & Date: dan 2018-08-10 14:23:41
Context
2018-08-10
15:27
Merge latest trunk changes with this branch. check-in: c355a83707 user: dan tags: alter-table-rename-column
14:23
Fix a problem with renaming columns on tables with REFERENCES clauses that specify a large number of columns. check-in: d48f7bbdf4 user: dan tags: alter-table-rename-column
2018-08-09
20:47
Experimental implementation of ALTER TABLE ... RENAME COLUMN. Still buggy. check-in: fa0fc01eb4 user: dan tags: alter-table-rename-column
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/build.c.

2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
      if( j>=p->nCol ){
        sqlite3ErrorMsg(pParse, 
          "unknown column \"%s\" in foreign key definition", 
          pFromCol->a[i].zName);
        goto fk_end;
      }
      if( IN_RENAME_COLUMN ){
        sqlite3MoveRenameToken(pParse, &pFKey->aCol[i], &pFromCol->a[i]);
      }
    }
  }
  if( pToCol ){
    for(i=0; i<nCol; i++){
      int n = sqlite3Strlen30(pToCol->a[i].zName);
      pFKey->aCol[i].zCol = z;







|







2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
      if( j>=p->nCol ){
        sqlite3ErrorMsg(pParse, 
          "unknown column \"%s\" in foreign key definition", 
          pFromCol->a[i].zName);
        goto fk_end;
      }
      if( IN_RENAME_COLUMN ){
        sqlite3MoveRenameToken(pParse, &pFKey->aCol[i], pFromCol->a[i].zName);
      }
    }
  }
  if( pToCol ){
    for(i=0; i<nCol; i++){
      int n = sqlite3Strlen30(pToCol->a[i].zName);
      pFKey->aCol[i].zCol = z;

Changes to src/parse.y.

1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
        && pParse->db->init.busy==0
    ){
      sqlite3ErrorMsg(pParse, "syntax error after column name \"%.*s\"",
                         pIdToken->n, pIdToken->z);
    }
    sqlite3ExprListSetName(pParse, p, pIdToken, 1);
    if( IN_RENAME_COLUMN ){
      sqlite3RenameToken(pParse, (void*)&(p->a[p->nExpr-1]), pIdToken);
    }
    return p;
  }
} // end %include

eidlist_opt(A) ::= .                         {A = 0;}
eidlist_opt(A) ::= LP eidlist(X) RP.         {A = X;}







|







1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
        && pParse->db->init.busy==0
    ){
      sqlite3ErrorMsg(pParse, "syntax error after column name \"%.*s\"",
                         pIdToken->n, pIdToken->z);
    }
    sqlite3ExprListSetName(pParse, p, pIdToken, 1);
    if( IN_RENAME_COLUMN ){
      sqlite3RenameToken(pParse, (void*)(p->a[p->nExpr-1].zName), pIdToken);
    }
    return p;
  }
} // end %include

eidlist_opt(A) ::= .                         {A = 0;}
eidlist_opt(A) ::= LP eidlist(X) RP.         {A = X;}

Changes to test/altercol.test.

88
89
90
91
92
93
94










95
96
97
    set res [list $after]
  }
  do_execsql_test 1.$tn.4 {
    SELECT sql FROM sqlite_master WHERE tbl_name='t1' AND sql!=''
  } $res
}











finish_test









>
>
>
>
>
>
>
>
>
>



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
    set res [list $after]
  }
  do_execsql_test 1.$tn.4 {
    SELECT sql FROM sqlite_master WHERE tbl_name='t1' AND sql!=''
  } $res
}

#-------------------------------------------------------------------------
do_execsql_test 2.0 {
  CREATE TABLE t3(a, b, c, d, e, f, g, h, i, j, k, l, m, FOREIGN KEY (b, c, d, e, f, g, h, i, j, k, l, m) REFERENCES t4);
}

do_execsql_test 2.1 {
  ALTER TABLE t3 RENAME b TO biglongname;
  SELECT sql FROM sqlite_master WHERE name='t3';
} {{CREATE TABLE t3(a, biglongname, c, d, e, f, g, h, i, j, k, l, m, FOREIGN KEY (biglongname, c, d, e, f, g, h, i, j, k, l, m) REFERENCES t4)}}

finish_test