Reputation: 1742
I am trying to execute this statement in mozilla sqlite add-on
alter table (select tbl_name from sqlite_master where rowid=1) add GUID varchar
But this runs into error :
SQLiteManager: Likely SQL syntax error: alter table (select tbl_name from sqlite_master where rowid=1) add GUID varchar [ near "(": syntax error ] Exception Name: NS_ERROR_FAILURE Exception Message: Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [mozIStorageConnection.createStatement]
the statement :select tbl_name from sqlite_master where rowid=1 works fine
Upvotes: 1
Views: 2232
Reputation: 726709
You cannot do that: in SQL, table names and column names must be identifiers embedded in the SQL string itself. They cannot come from values that you query, or even in a query parameter.
You need to select the table name, make the alter table
statement, and then execute it separately.
Upvotes: 1