Renjith K N
Renjith K N

Reputation: 2633

Creation ( if table not exists ) and insertion of table using a single query in sqlite Android

I want to use a single query to insert into a table and if that table is not yet created create it and perform the insertion

Any ideas, answers suggestions or sample queries are welcome

Advanced thanks for all

Upvotes: 1

Views: 100

Answers (2)

Aswin Kumar
Aswin Kumar

Reputation: 5278

Use SQLiteDatabase.execSQL() command, and execute two queries seperated by ';', like:

db.execSQL("create table if not exists('columns and details here');insert into 'whatever you want to insert');"

Upvotes: 1

Sanket Kachhela
Sanket Kachhela

Reputation: 10856

first you have to ckeck that table is already created or not so use this query

CREATE TABLE IF NOT EXISTS "abcxyz" ( ' +
           '"id" INTEGER PRIMARY KEY AUTOINCREMENT,' +
           '"vorname" TEXT,' +
           '"name" TEXT,' +
           '"geburtsdatum" TEXT,' +
           '"suchid" TEXT )'

and than write your insert query.

Upvotes: 0

Related Questions