スタックオーバーフローに似たものがあったことは知っていますが、答えが見つからなかったので、誰かが私を助けて、そのrawQueryの何が問題なのかを説明できるかもしれません..
私の定数があります:
// id column for all tables & DB version
public static final String KEY_ID = "_id";
private static final int DATABASE_VERSION = 1;
// TABLE PLAYER
private static final String DATABASE_TABLE_PLAYER = "Player";
// columns in player table
public static final String PLAYER_COLUMN_NAME = "name";
public static final int PLAYER_NAME_INDEX = 1;
// TABLE RESULT
private static final String DATABASE_TABLE_RESULT = "Result";
// columns in result table
public static final String RESULT_COLUMN_GAME_ID = "game_id";
public static final int RESULT_GAME_ID_INDEX = 1;
public static final String RESULT_COLUMN_PLAYER_ID = "player_id";
public static final int RESULT_PLAYER_ID_INDEX = 2;
public static final String RESULT_COLUMN_POSITION = "position";
public static final int RESULT_POSITION_INDEX = 3;
// TABLE GAME
public static final String DATABASE_TABLE_GAME = "Game";
// columns in game_result tabe
public static final String GAME_COLUMN_DATE = "date";
public static final int GAME_DATE_INDEX = 1;
public static final String GAME_COLUMN_DURATION = "duration";
public static final int GAME_DURATION_INDEX = 2;
private static final String DBCREATE_SQL_1 = "create table " + DATABASE_TABLE_PLAYER + " ( " + KEY_ID
+ " integer primary key autoincrement, " + PLAYER_COLUMN_NAME + " text not null); ";
private static final String DBCREATE_SQL_2 = "create table " + DATABASE_TABLE_GAME + " ( " + KEY_ID
+ " integer primary key autoincrement, " + GAME_COLUMN_DATE + " string not null, " + GAME_COLUMN_DURATION + " int not null); ";
private static final String DBCREATE_SQL_3 = "create table " + DATABASE_TABLE_RESULT + " ( " + KEY_ID
+ " integer primary key autoincrement, " + RESULT_COLUMN_POSITION + " integer not null, " + RESULT_COLUMN_GAME_ID
+ " integer not null, " + RESULT_COLUMN_PLAYER_ID + " integer not null, FOREIGN KEY( " + RESULT_COLUMN_GAME_ID
+ " ) REFERENCES " + DATABASE_TABLE_GAME + "(" + KEY_ID + "), " + "FOREIGN KEY( " + RESULT_COLUMN_PLAYER_ID + " ) REFERENCES "
+ DATABASE_TABLE_PLAYER + "(" + KEY_ID + ") );";
// JOIN STATEMENT NEED TO JOIN TABLES WHEN GIVING TO STATS TABLE
private static final String DBJOIN_SQL = "SELECT * FROM ( ? JOIN ? ON ? = ? ) JOIN ? ON ? = ?";
そして、私の rawQuery メソッドがあります:
public List<GameResultOut> getRowsToTable() {
// SELECT * FROM (? JOIN ? ON ?=?) JOIN ? ON ?=?
Cursor resultRows = database.rawQuery(DBJOIN_SQL, new String[] { DATABASE_TABLE_PLAYER, DATABASE_TABLE_RESULT,
DATABASE_TABLE_PLAYER + "." + KEY_ID, DATABASE_TABLE_RESULT + "." + RESULT_COLUMN_PLAYER_ID, DATABASE_TABLE_GAME,
DATABASE_TABLE_RESULT + "." + RESULT_COLUMN_GAME_ID, DATABASE_TABLE_GAME + "." + KEY_ID } );
database.ra
List<GameResultOut> resultList = new ArrayList<GameResultOut>();
resultRows.moveToFirst();
boolean isLast = resultRows.isLast();
int columnIndexName = resultRows.getColumnIndex(PLAYER_COLUMN_NAME);
int columnIndexPosition = resultRows.getColumnIndex(RESULT_COLUMN_POSITION);
int columnIndexDate = resultRows.getColumnIndex(GAME_COLUMN_DATE);
int columnIndexDuration = resultRows.getColumnIndex(GAME_COLUMN_DURATION);
DateFormat df = DateFormat.getInstance();
while (!isLast) {
try {
GameResultOut result = new GameResultOut(resultRows.getString(columnIndexName), resultRows.getInt(columnIndexPosition),
df.parse(resultRows.getString(columnIndexDate)), resultRows.getInt(columnIndexDuration), 0);
resultList.add(result);
} catch (java.text.ParseException e) {
Log.e("PARSE EXCEPTION (Krystian)", "Error during date parse in DBAdapter.getRowsToTable");
return null;
}
isLast = !resultRows.moveToNext();
}
return resultList;
}
そして、LogCat からのエラーがあります
10-27 15:05:39.825: E/AndroidRuntime(2344): Caused by: android.database.sqlite.SQLiteException: near "?": syntax error (code 1): , while compiling: SELECT * FROM ( ? JOIN ? ON ? = ? ) JOIN ? ON ? = ?
助けてくれてありがとう.. :)