これは私のtable-creation-commandです:
private static final String PINGPONG_CREATE = "create table " + TABLE_PINGPONG + "(" + COLUMN_ID_PINGPONG + " integer primary key autoincrement, " + COLUMN_CNAME +
" text not null, " + COLUMN_DATE + " text not null, " + " text not null, " + COLUMN_LEAD + " numeric, " + COLUMN_PLACE + " text not null, "
+ COLUMN_SET_ONE1 + " numeric, " + COLUMN_SET_ONE2 + " numeric, " + COLUMN_SET_TWO1 + " numeric, " + COLUMN_SET_TWO2 + " numeric, " + COLUMN_SET_THREE1
+ " numeric, " + COLUMN_SET_THREE2 + " numeric, " + COLUMN_SET_FOUR1 + " numeric, " + COLUMN_SET_FOUR2 + " numeric, " + COLUMN_SET_FIVE1 + " numeric, "
+ COLUMN_SET_FIVE2 + " numeric, " + COLUMN_SET_SIX1 + " numeric, " + COLUMN_SET_SIX2 + " numeric, " + COLUMN_SET_SEVEN1 + " numeric, " + COLUMN_SET_SEVEN2
+ " numeric, " + COLUMN_RESULT1 + " numeric, " + COLUMN_RESULT2 + " numeric);";
これは、データベースに「PingPongeEntry」を入力するための私の方法です。
public void createPingPongEntry(int lead, String challengeName, String date, String place, int set11, int set12, int set21, int set22,
int set31, int set32, int set41, int set42, int set51, int set52, int set61, int set62, int set71, int set72, int tot1, int tot2){
ContentValues values = new ContentValues();
values.put(CustomSQLiteHelper.COLUMN_LEAD, lead);
values.put(CustomSQLiteHelper.COLUMN_CNAME, challengeName);
values.put(CustomSQLiteHelper.COLUMN_DATE, date);
values.put(CustomSQLiteHelper.COLUMN_PLACE, place);
values.put(CustomSQLiteHelper.COLUMN_SET_ONE1, set11);
values.put(CustomSQLiteHelper.COLUMN_SET_ONE2, set12);
values.put(CustomSQLiteHelper.COLUMN_SET_TWO1, set21);
values.put(CustomSQLiteHelper.COLUMN_SET_TWO2, set22);
values.put(CustomSQLiteHelper.COLUMN_SET_THREE1, set31);
values.put(CustomSQLiteHelper.COLUMN_SET_THREE2, set32);
values.put(CustomSQLiteHelper.COLUMN_SET_FOUR1, set41);
values.put(CustomSQLiteHelper.COLUMN_SET_FOUR2, set42);
values.put(CustomSQLiteHelper.COLUMN_SET_FIVE1, set51);
values.put(CustomSQLiteHelper.COLUMN_SET_FIVE2, set52);
values.put(CustomSQLiteHelper.COLUMN_SET_SIX1, set61);
values.put(CustomSQLiteHelper.COLUMN_SET_SIX2, set62);
values.put(CustomSQLiteHelper.COLUMN_SET_SEVEN1, set71);
values.put(CustomSQLiteHelper.COLUMN_SET_SEVEN2, set72);
values.put(CustomSQLiteHelper.COLUMN_RESULT1, tot1);
values.put(CustomSQLiteHelper.COLUMN_RESULT2, tot2);
long insertID = database.insert(CustomSQLiteHelper.TABLE_PINGPONG, null, values);
Cursor cursor = database.query(CustomSQLiteHelper.TABLE_PINGPONG, allColumns3, CustomSQLiteHelper.COLUMN_ID_RUNNING + " = " + insertID, null, null, null, null);
cursor.moveToFirst();
cursor.close();
}
それがallColums3-String[]です
private String[] allColumns3 = {CustomSQLiteHelper.COLUMN_ID_PINGPONG, CustomSQLiteHelper.COLUMN_CNAME, CustomSQLiteHelper.COLUMN_DATE, CustomSQLiteHelper.COLUMN_PLACE, CustomSQLiteHelper.COLUMN_LEAD,
CustomSQLiteHelper.COLUMN_SET_ONE1,
CustomSQLiteHelper.COLUMN_SET_ONE2, CustomSQLiteHelper.COLUMN_SET_TWO1, CustomSQLiteHelper.COLUMN_SET_TWO2, CustomSQLiteHelper.COLUMN_SET_THREE1, CustomSQLiteHelper.COLUMN_SET_THREE2,
CustomSQLiteHelper.COLUMN_SET_FOUR1, CustomSQLiteHelper.COLUMN_SET_FOUR2, CustomSQLiteHelper.COLUMN_SET_FIVE1, CustomSQLiteHelper.COLUMN_SET_FIVE2, CustomSQLiteHelper.COLUMN_SET_SIX1,
CustomSQLiteHelper.COLUMN_SET_SIX2, CustomSQLiteHelper.COLUMN_SET_SEVEN1, CustomSQLiteHelper.COLUMN_SET_SEVEN2, CustomSQLiteHelper.COLUMN_RESULT1, CustomSQLiteHelper.COLUMN_RESULT2};
今行long insertID = database.insert(CustomSQLiteHelper.TABLE_PINGPONG, null, values);
でSQLiteConstraintExceptionが発生していますが、その理由はわかりません。それは言う:
09-29 19:55:13.151: E/Database(1609): Error inserting set51=0 set52=0 set41=3 set61=0 lead=0 set72=0 set71=0 set62=0 date=29-09-2012 result1=4 result2=0 name=pingpong set32=1 set31=3 set42=1 place=hier set22=1 set21=3 set12=1 set11=3
(値を挿入する順序がない理由もここで混乱しています)
このトピックに関するいくつかの質問をここで読みましたが、そこに示されているすべての推奨事項に従います。主キーは自動インクリメントされ、さらに、レコードを挿入しようとしているこの時点では、データベースは空です。
挿入する方法は2つFootBallEntrys
ありGames
、これに例えると、すべて正常に機能します。では、なぜここで一意のuidが作成されないのでしょうか。