On Mon, May 16, 2011 at 12:49:14PM -0500, Nico Williams scratched on the wall:
> On May 16, 2011 9:33 AM, "Simon Slavin" <slav...@bigfraud.org> wrote:
> > On 16 May 2011, at 3:44am, romtek wrote:
> >
> > > Secondly, if I executed the above SQL code, what would happen to
> triggers,
> > > etc. that are associated with the original table?
> >
> > I suspect that's a major reason why SQLite doesn't support DROP COLUMN:
> it has to check for things that might depend on the column and refuse
> to DROP if it finds anything.
> 
> Nit: that's almost certainly the reason that SQLite3 doesn't support
> column rename,

  I think the bigger issue is that column rename requires full
  understanding of the SQL statements stored in sqlite_master.  To
  safely do a ALTER TABLE...RENAME COLUMN you have to understand the
  context and parts of the CREATE TABLE statement (and triggers, and
  indexes, and FKs of other tables).  This requires a close link between
  the modification function, the parser, and the tokenizer.  You have to
  scan the SQL statement and understand the different parts, and then
  back-trace them to a specific character in the original statement,
  so you know which substring to change.  While this is feasible, most
  tokenizers and parsers are specifically designed to be abstract layers.

> The row data encoding is also the reason that new columns can only
> be added and appear at the end of the new CREATE TABLE statement, 

  While I'm sure this is the major factor in that decision, the parsing
  issue still exists.  Adding a column def to the end of a CREATE TABLE
  statement is fairly easy... find the last ')' character in the whole
  statement and insert "',' || <new column>" right before.  Even if the
  encoding issue could be solved, inserting a column def anywhere else
  requires context-aware parsing and understanding of the CREATE TABLE
  statement, so it can be understood where the modifications have to be
  made.

   -j


-- 
Jay A. Kreibich < J A Y  @  K R E I B I.C H >

"Intelligence is like underwear: it is important that you have it,
 but showing it to the wrong people has the tendency to make them
 feel uncomfortable." -- Angela Johnson
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to