zahreelay
zahreelay

Reputation: 1742

SQLite alter table with result from select statement

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

Answers (1)

Sergey Kalinichenko
Sergey Kalinichenko

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

Related Questions