Rename View/Index/Trigger

SQLite…
Renaming a TABLE is easy

ALTER TABLE mytable RENAME to newname

but I cannot find any similar command to programmitically rename

  • Views
  • Indexes
  • Triggers

Is the best way to

  • extract the SQL statment from SQLITE_MASTER
  • drop the original view/index/trigger
  • alter the SQL string to replace the original name with the new name
  • execute the altered SQL statement
    seems a bit heavy handed…was hoping for a “clean” method

ideas?

[quote=323358:@Dave S]I cannot find any similar command to programmitically rename

Views
Indexes
Triggers[/quote]
There is none in SQLite.

[quote=323358:@Dave S]Is the best way to

extract the SQL statment from SQLITE_MASTER
drop the original view/index/trigger
alter the SQL string to replace the original name with the new name
execute the altered SQL statement
seems a bit heavy handed…was hoping for a “clean” method[/quote]
Unfortunately this is the only way at the moment.

http://sqlite.org/lang.html

Ian, you mean this : http://sqlite.org/lang_altertable.html

short : you must copy all the datas in another table, then delete the old table.

if you only want to rename a column, or a trigger or an index, you can edit the sqlite_master table with the correct pragma
(http://sqlite.org/pragma.html#pragma_writable_schema)

but it you change a column type, or order, you must use the “safe” method above.

[quote=323379:@Jean-Yves Pochez]Ian, you mean this : http://sqlite.org/lang_altertable.html

short : you must copy all the datas in another table, then delete the old table.[/quote]
No, I really did mean http://sqlite.org/lang.html as that shows the limits of SQLite’s SQL syntax, i.e. it’s missing ALTER <ANYTHING EXCEPT TABLE>.

Thanks Ian and Jean-Yves…

I think I will go with the method I mentioned in my OP…
Altering SQLITE_MASTER directly via PRAGMA does not seem to be a “safe” way , the other way if there is some type of ERROR, I can catch it, and remain “safe”