2017-01-18 6 views
1

次のコマンドを実行するとエラーが発生します。その前にアプリケーションをアンインストールして再インストールする前にクエリが以前の更新で機能していたため、CREATE INDEXSQLite:単一のSQLコマンドで列とインデックスを作成する方法

private static final String DATABASE_NAME = "db_name.db"; 
    private static final int DATABASE_VERSION = 1; 

    private static final String CREATE_TABLE_MESSAGES = "create table messages" 
      + "(" 
      + "_id" + " integer primary key autoincrement, " 
      + "message_id" + " text not null, " 
      + "sender" + " text not null, " 
      + "recipient" + " text DEFAULT NA, " 
      + "message" + " text not null, " 
      + "shared" + " text not null, " 
      + "sent" + " Boolean DEFAULT false, " 
      + "delivered" + " Boolean DEFAULT false, " 
      + "read" + " Boolean DEFAULT false, " 
      + "hasobject" + " Boolean DEFAULT false, " 
      ///object// 
      + "object" + " text DEFAULT NA, " 
      ///meta/// 
      + "deviceid" + " text DEFAULT NA, " 
      + "modified_time" + " integer not null, " 
      + "time" + " integer not null, " 
      + "CREATE INDEX IF NOT EXISTS shared_index on messages(shared)," 
      + "created_time" + " integer not null " + ")"; 


    public DatabaseHelper(Context context) { 
     super(context, DATABASE_NAME, null, DATABASE_VERSION); 
    } 

    @Override 
    public void onCreate(SQLiteDatabase db) { 
     db.execSQL(CREATE_TABLE_MESSAGES); 
    } 

    @Override 
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { 
     if (newVersion > oldVersion) { 
     // db.execSQL("CREATE INDEX IF NOT EXISTS shared_index on messages(shared);"); 
     } 
    } 
+2

@ロットワン、それはそんなことは考えていない。あなたのコメントを答えとして書いてください。 – Relm

答えて

1

あなたすることはできません。それらは個別 SQLコマンドです - あなたは単にをマージできません。 ;を使用して、マージコマンドまたはクエリがSQLiteの

では動作しません

マインドは

は単純に二つの連続execSQL()命令を実行し、それだけで大丈夫です。

関連する問題