dcanh121
dcanh121

Reputation: 4695

android sqlite fts3 create table if not exists

I see that we cannot use "if not exists" in the create virtual table statement

CREATE VIRTUAL TABLE WORLD_LIST IF NOT EXISTS USING FTS3(_ID INTEGER PRIMARY KEY AUTOINCREMENT, WORD TEXT)

If I remove the IF NOT EXISTS it works only once. Is there any alternative for this.

Upvotes: 0

Views: 1217

Answers (2)

Tom Kerr
Tom Kerr

Reputation: 10720

It only works once because the table already exists the second time. You are receiving an error because of name conflicts. It is working as intended. Do you expect something different?

Not executing the statement would be a good option. Pushing the decision of whether or not to run that statement into the storage logic is not recommended.

If you are testing and want to recreate every time, then just drop the table.

DROP TABLE WORLD_LIST;
CREATE VIRTUAL TABLE WORLD_LIST USING FTS3...

Upvotes: 1

Simon
Simon

Reputation: 14472

You could test for the existence of the table then branch accordingly:

SELECT DISTINCT tablename from sqlite_master where tablename = ?

Upvotes: 1

Related Questions