Commit Graph

42 Commits

Author SHA1 Message Date
dan
1d14ffe63d Fix a problem with renaming a column when there is a quoted string immediately following the column name somewhere in the schema.
FossilOrigin-Name: 4719fae6262aa3563f3df6aca0170c6d847bb18ab7b0e6e7609a0e7b6f0c6b1b
2021-03-23 22:15:34 +00:00
dan
2ad080aa82 Have ALTER TABLE RENAME COLUMN and DROP COLUMN use sqlite_rename_quotefix() to convert any double-quoted strings in the database schema to their single-quoted equivalents.
FossilOrigin-Name: 6446c0961077396086251670102ea7bf17d54a6b0f0ca56c6af89028a1ff9039
2021-03-16 16:14:48 +00:00
dan
776a578c21 Fix a problem with ALTER TABLE RENAME COLUMN when used on a schema that features generated columns.
FossilOrigin-Name: 0e255b26872b50581d470952dd98e21dd82d081885006f58d49daa4b4576b35d
2021-03-16 11:11:07 +00:00
dan
3083d5f5ea Fix a problem with using ALTER TABLE commands on database schemas that contain expressions of the form "<expr> NOT NULL" or "<expr> IS NULL" that can be evaluated at prepare time.
FossilOrigin-Name: d2630ffafa077b8cfd75110b6b73da30f780edc920d2788769a4dc747f09d3f6
2021-03-03 11:00:31 +00:00
drh
171c50ec38 New test-only SQL functions: implies_nonnull_row(), expr_compare(), and
expr_implies_expr().  The SQLITE_TESTCTRL_INTERNAL_FUNCTIONS test-control
is modified to toggle internal function access on and off for a single
database connection.

FossilOrigin-Name: 473892a8eceacf24d57fd0c72ff2a0b8be4e0d75e0af7a30bdb24fbc3b453601
2020-01-01 15:43:30 +00:00
drh
885eeb676b Enhance the ALTER TABLE RENAME COLUMN feature so that it works on tables
that have redundant UNIQUE and/or PRIMARY KEY constraints.
Fix for ticket [bc8d94f0fbd633fd9a051e3]

FossilOrigin-Name: f09aa3248e2b4a32ff5b5d37084cb2a27445322cb06a3354cef723f4f0b2cd34
2019-01-09 02:02:24 +00:00
drh
eea8eb6d04 Do not allow direct access to internal-use SQL functions such as
sqlite_rename_column() and sqlite3_rename_table() except when the
new SQLITE_TESTCTRL_INTERNAL_FUNCTIONS flag is set.

FossilOrigin-Name: 6e1330545e7b74fe5f1f20751a3425e2788441485fc07fcb7626e448c72027ce
2018-11-26 18:09:15 +00:00
drh
6ab91a7a7a Add the SQLITE_DEFAULT_DEFENSIVE compile-time option. Fix up test cases
so that they work with DEFENSIVE enabled.

FossilOrigin-Name: 3212733cb6d1a59516d67a86df7c7b1d2456a1b2e5d7080c26b0e87b2609c65d
2018-11-07 02:17:01 +00:00
dan
e8ab40d219 Fix an invalid pointer comparison triggered by renaming a table column when
there are views with explicit column names in the schema.

FossilOrigin-Name: 572de7e4e33562c72cd90790b267ba389370f21ddcaebc4db609fd76ae9b7ada
2018-09-12 08:51:48 +00:00
dan
7ea1edb703 Fix test script problems causing SQLITE_OMIT_VIRTUALTABLE builds to fail.
FossilOrigin-Name: 37ad064e5f5704cf345d23b38b3f6d627fbcf20dbb78c8a91e96c9704760a1b8
2018-09-06 17:23:08 +00:00
dan
b87a9a8a5e Fix a problem with renaming a column in a table that has a temp trigger that
references another attached database.

FossilOrigin-Name: 336b8a0923bf65b7a2c35811cb6dec0e262a0b31e534d2a6ab093d2afdb05c1f
2018-09-01 20:23:28 +00:00
drh
010f8ee2fb Merge fixes from the alter-table-rename-column branch that occurred after
this branch separated from that one.

FossilOrigin-Name: 22e785aa2bbce4ae0852bc3d127d4b12222a192eb6e3ee874bf8e5c8582d05f3
2018-09-01 15:55:44 +00:00
dan
9d324823a8 Test the schema after renaming a table. Ensure that temp database triggers and
views are updated when renaming a column.

FossilOrigin-Name: f3c27d916d4837f8fc3dd812bd004535f04c7a53bd2a0a2419613275f48bec76
2018-08-30 20:03:44 +00:00
drh
050398bdf1 Fix a minor issue in the altercol.test script so that it runs on Windows.
FossilOrigin-Name: 62089c6daf9ea51be769c077c23d6fa881ba797255fa22d71baaac191a9c1ba7
2018-08-25 16:22:33 +00:00
dan
aa42e9816b Fix a problem by renaming a column when the schema contains an trigger program
featuring an UPSERT that uses an "excluded.*" reference to a different table.

FossilOrigin-Name: 83d5f5abce6be2f6d342a6fc68839289400d7bcb80eaa38194789142c93a80c3
2018-08-24 20:20:33 +00:00
dan
85a9d508df Fix a problem with renaming a column that occurs as an "excluded.colname"
construction in an UPSERT that is part of a trigger program.

FossilOrigin-Name: bb2f7234968157b605522dea8e115d8772ab4234147894089d6e48fedf5d6a5d
2018-08-24 20:10:22 +00:00
dan
0d5fa6b979 After modifying and reparsing the schema as part of an ALTER TABLE RENAME
COLUMN, check that no new schema errors have been introduced (e.g. ambiguous
column names in views) before committing the operation.

FossilOrigin-Name: a0e06d2c5e3abb3f300491e7651bb177a436899efd4506de9239359096b6a9e7
2018-08-24 17:55:49 +00:00
dan
1b0c5de434 Avoid incorrectly replacing tokens that refer to a column being renamed via an
alias. For example, do not overwrite "xyz" when "a" is renamed in "CREATE VIEW
v1 AS SELECT a AS xyz FROM tbl WHERE xyz=1"

FossilOrigin-Name: ad072a835f97ff418f5919d94f547ce8afb4fc7c7b590deba41f1e62136a79ac
2018-08-24 16:04:26 +00:00
drh
79a5ee93c7 Fix harmless compiler warnings in the ALTER TABLE logic. Rephrase an
error message to use active voice.

FossilOrigin-Name: a7dae59a7e7b187fa2e9457bbb4b01cfe3d48bbdf59c3f8f7b4156bcde3bda98
2018-08-23 19:32:04 +00:00
dan
0624939818 Rationalize some duplicated code in alter.c. Also improve error messages for
ALTER TABLE RENAME COLUMN in some cases.

FossilOrigin-Name: 5d2163c734aea8c0e1611af1161734bf141e7bd02c08f0b5f2e7bac3c7dfd2a5
2018-08-21 15:06:59 +00:00
dan
b013738b4c Add further tests for RENAME COLUMN.
FossilOrigin-Name: 82c4c10a96db76f39edf5f6d027294d449d75b5a18da70da3667786da90e184d
2018-08-20 20:01:01 +00:00
dan
9d70557e80 Ensure that it is not possible to rename columns of system tables, views or
virtual tables.

FossilOrigin-Name: 786b5991dc0bb6ba13327a3ac9d04efbf8b591dedc736b719b206ffd865b1918
2018-08-20 16:16:05 +00:00
dan
24fedb94c2 Improvements to error handling in ALTER TABLE RENAME COLUMN.
FossilOrigin-Name: 7fa1faeaff30b74b68ee6f4b363d837f21cf313d8262361c901bda884df139a2
2018-08-18 17:35:38 +00:00
dan
499b825487 Allow an ALTER TABLE RENAME COLUMN to proceed even if the schema contains a
virtual table for which the module is unavailable.

FossilOrigin-Name: 7b72b2360a70eb1f788b3c4d745967dfedb2c80af6b2e146ba940a3741fd51a1
2018-08-17 18:08:28 +00:00
dan
dabc268f96 Ensure that CREATE VIEW, TRIGGER or INDEX statements can be edited by ALTER
TABLE RENAME COLUMN even if they use collation-sequences or
user-defined-functions that are not available.

FossilOrigin-Name: 540014efd6a048373313c6cd9413de10d5d7114daf537cf5999ccf3c5c3f9358
2018-08-17 17:18:16 +00:00
dan
0cbb0b11f1 Further progress on updating trigger programs as part of ALTER TABLE RENAME
COLUMN.

FossilOrigin-Name: 3f47222b6e20e1c1ef41c0f7391c8b5c7648e2a2d6013303d155ad59ce27143a
2018-08-16 19:49:16 +00:00
dan
5be60c55e8 (no comment)
FossilOrigin-Name: e272dc2b1c0edab59a40f32c77c81a3e636937280524161eff5669cb0046ad84
2018-08-15 20:28:39 +00:00
dan
356afab163 Fix a problem when renaming an IPK column that is also part of a child key.
FossilOrigin-Name: 6e6a2bfdbbfd4ffc14be88962ff97bf3c626fef9d1a337715d2a4be1a657fb0d
2018-08-14 21:05:35 +00:00
dan
f62e8937ac Fix a problem when renaming an IPK column that is also part of a child key.
FossilOrigin-Name: ad15486022209205c65fb5ffdbe30a7b99379170451e6aff4bab6e90b549d6c7
2018-08-14 21:03:38 +00:00
dan
72238130d0 Merge latest trunk and ALTER TABLE error message improvements into this
branch.

FossilOrigin-Name: 7a45802dafaed3c058f59d1487fe8091e1f309cc5f0a5bcf2579f0bdd8e92d89
2018-08-14 20:40:25 +00:00
dan
987db767d2 Have ALTER TABLE RENAME edit column references in CREATE VIEW statements.
FossilOrigin-Name: db829dc1a2d7afa49798a2fd32d1f070185b23e513416e65d8144fda24f23b50
2018-08-14 20:18:50 +00:00
dan
689b9d269c Fix ALTER TABLE RENAME COLUMN in cases where the column being renamed is an
IPK declared with a separate PRIMARY KEY clause - "CREATE TABLE x(y INTEGER,
PRIMARY KEY(y))".

FossilOrigin-Name: 32ca8418df8735a6c53e53153f733579e514711f091e4e09ecce83db85fe4d85
2018-08-14 16:18:19 +00:00
dan
5496d6a25a Edit the WHEN and UPDATE OF clauses of trigger programs as part of ALTER TABLE
RENAME COLUMN.

FossilOrigin-Name: 5fdb6b0aafba727139e1937ef5950e4434a77f95a10fc46f8010ca2de3922326
2018-08-13 17:14:26 +00:00
dan
404c3ba0d6 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
2018-08-11 20:38:33 +00:00
dan
b0c7920d86 Avoid an assert() sometimes triggered by ALTER TABLE RENAME COLUMN in non-debug builds.
FossilOrigin-Name: 520c1c75dae5e3f4695fcdf0aad5fb9f492f0e528b5fbb49d5d3b5fc02762f47
2018-08-11 18:34:25 +00:00
dan
a8762ae27c Fix a bug causing ALTER TABLE RENAME COLUMN to fail when renaming an IPK
column that is used in a CHECK constraint.

FossilOrigin-Name: 6595c8811f13719d0aed8041abc7e1cade41c57427bcbf3503e2e42408eaa03b
2018-08-11 17:49:23 +00:00
dan
872165f260 Fix a bug causing all ALTER TABLE RENAME COLUMN commands to fail if ANALYZE
had been run on the database. Also prevent the user from renaming the columns
of system tables.

FossilOrigin-Name: ca644a2877c26561f8fb3b3feb74a070cd46621acb105577f04bc936c9b72a95
2018-08-11 17:34:38 +00:00
dan
e325ffed04 Reload the entire schema after renaming a column in order to ensure that the
schema for any tables for which parent key definitions were changed are
reloaded.

FossilOrigin-Name: f4497b0136e9fcb1121a834c86f84eeaf8f1e7d3157d409484e086bcef3487f1
2018-08-11 13:40:20 +00:00
dan
5da06d3d7e Ensure the schema cookie is changed when a column is renamed.
FossilOrigin-Name: 2dec9ea4ab1779d00bb22add0aa9a8536661d8abc9f4c2fb8628e04d4cd84326
2018-08-10 20:19:34 +00:00
dan
6fe7f23fa9 When a column is renamed, update any references to it in REFERENCES clauses
that belong to other tables.

FossilOrigin-Name: 191079bd4f774528a1e39b71b4a4ce7859dee0edf0ce72e4b6968ae889dc35c8
2018-08-10 19:19:33 +00:00
dan
e9a2fa3182 Fix a problem with renaming columns on tables with REFERENCES clauses that
specify a large number of columns.

FossilOrigin-Name: d48f7bbdf4a1686c25e634a8dec6ead88bf2866fee94ed8e5058f830363424a8
2018-08-10 14:23:41 +00:00
dan
cf8f289542 Experimental implementation of ALTER TABLE ... RENAME COLUMN. Still buggy.
FossilOrigin-Name: fa0fc01eb48a864f0a3d43f9b805d5ed2e530846ee0c34fcbc2eabd9e5696277
2018-08-09 20:47:01 +00:00