0

Is there any way to add multiple column in a single statement in ORMLite. Although i have gone through this Sqlite question: sqlite alter table add MULTIPLE columns in a single statement

And according to this link there is no way in Sqlite but as ORMLite is a wrapper on sqlite as per my knowledge, is there any way to add multiple columns in a single statement like we do in sql:

ALTER TABLE table_name
   ADD (column_1 column-definition,
      column_2 column-definition,
      ...
      column_n column_definition);

Thanks in advance!!

Community
  • 1
  • 1
Ankur Chaudhary
  • 2,709
  • 3
  • 19
  • 30

2 Answers2

2

So Finally after a lot search i don't think that there is any way to put multiple column in a single statement in OrmLite as SQLite does not support multiple iteration for ADD keyword.

Thanks for the answer SQLite alter table

and even it's mentioned in the doc SQLite docs

Community
  • 1
  • 1
Ankur Chaudhary
  • 2,709
  • 3
  • 19
  • 30
1

Is there any way to add multiple column in a single statement in ORMLite

Any schema changes in ORMLite will have to be done using the Dao.executeRaw(...) method which just runs raw statements on the database and returns the number of lines changed (as reported by the database).

If Sqlite supports the alter statement then you should be able to do something like:

dao.executeRaw("ALTER TABLE table_name ADD (column_1 column-definition,"
      + " column_2 column-definition,"
      + " ...,"
      + " column_n column_definition);
Gray
  • 115,027
  • 24
  • 293
  • 354
  • I tried executing this statement but it's throwing exception Could not run raw execute statement ALTER TABLE 'testbean' ADD (l INTEGER, m INTEGER) at com.j256.ormlite.dao.RuntimeExceptionDao.executeRaw(RuntimeExceptionDao.java:488). where l, m are column names. Although using this query ALTER TABLE 'reminderbean' ADD COLUMN appointDayDifference INTEGER i am able to add one column at a time. Either i'm doing mistake in making query as i have less experience in making db query. Please help me to optimize my android code. – Ankur Chaudhary Aug 24 '15 at 13:01
  • Sorry, I'm not an Android expert @AnkurChaudhary. – Gray Aug 26 '15 at 02:24