テーブルにAutoIncrement列を作ったのはいんだけど、どうやったらその値取れるの?って思って調べた。
やりかた
まずはテーブル作成
なんだか主キー列は_idっていうフィールド名にするのが決まりみたいだからそうする。create table table1 ( _id integer primary key autoincrement not null, name text not null )主キー以外の場合はやったことない。
Insert実行
private long insert(SQLiteDatabase db){
SQLiteStatement stmt = db.compileStatement("insert into table1(name) values (?)");
stmt.bindString(1, "なまえ");
long id = stmt.executeInsert();
return id;
}
これでインサートされた_idの値が返ってくる。いい感じにできた。
