Cursorを使用してテーブルの行を取得する際に問題が発生する。 私は3つのテーブルを持っています:連絡先、試合、プレーヤー(最後はnxn関係から出てきます)。 私が望むのは、自分のIDを入力として与えるすべての一致(現在のユーザーログイン)を取得することです。 ここではクラスDatabaseHelperの私のテーブルはSQLiteOpenHelper延びている。CursorとSQLiteDatabaseで特定の行を取得する
// Tabella contacts
static final String TABLE_NAME="contacts";
static final String COLUMN_ID="id";
static final String COLUMN_NAME="name";
static final String COLUMN_EMAIL="email";
static final String COLUMN_USERNAME="username";
static final String COLUMN_PASSWORD="password";
//Tabella match
static final String TABLE_MATCH="match";
static final String COLUMN_ID_MATCH="id_match";
static final String COLUMN_NAME_MATCH="name_match";
static final String COLUMN_CONTATTO_MATCH="id_contatto";
static final String COLUMN_MAX_GIOCATORI="max_giocatori";
static final String COLUMN_CITTA="citta";
static final String COLUMN_INDIRIZZO="indirizzo";
static final String COLUMN_DATA="data";
static final String COLUMN_ORA="ora";
static final String COLUMN_LATITUDE="latitude";
static final String COLUMN_LONGITUDE="longitude";
// Tabella Player
static final String TABLE_PLAYER="player";
static final String COLUMN_ID_PLAYER="id_player";
static final String COLUMN_ID_CONTACT_PLAYER="id_contact_player";
static final String COLUMN_ID_MATCH_PLAYER="id_match_player";
...
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(TABLE_CREATE);
db.execSQL(TABLE_CREATE_MATCH);
db.execSQL(TABLE_CREATE_PLAYER);
this.db=db;
}
...
public String getContact() {
return contact3;
}
//ここに私の関数である...
public Cursor getMyMatchList3(SQLiteDatabase db){
// db=this.getReadableDatabase();
databaseHolder=new DatabaseHolder();
String contatto=databaseHolder.getContact();
String query="select id_contact_player,id_match_player from "+TABLE_PLAYER;
String query1="select * from "+TABLE_MATCH;
Cursor cursor=db.rawQuery(query,null);
Cursor cursor1=db.rawQuery(query1, null);
String id_contatto_player;
String id_partita;
String nome,citta,indirizzo,data,ora;
if(cursor.moveToFirst()){
do{
id_contatto_player=cursor.getString(0);
if (id_contatto_player.equals(contatto)){
id_partita=cursor.getString(1);
Log.e("ID_MATCH_PLAYER",id_partita);
if (cursor1.moveToFirst()){
do{
if (id_partita.equals(cursor1.getString(0))){
id_partita=cursor1.getString(0);
nome=cursor1.getString(1);
citta=cursor1.getString(4);
indirizzo=cursor1.getString(5);
data=cursor1.getString(6);
ora=cursor1.getString(7);
Log.e("ID_PARTITA_CURSOR_1",id_partita);
Log.e("nome",nome);
Log.e("citta",citta);
Log.e("indirizzo",indirizzo);
Log.e("data",data);
Log.e("ora",ora);
return cursor1;
}
}
while (cursor1.moveToNext());
}
}
}
while (cursor.moveToNext());
}
return cursor1;
}
しかし、この方法では、カーソル1は私に正しい行を返しませんが、同時にログ出力は大丈夫です。どのようにできるのか??私は、このような方法でそれを呼び出す他のクラスに比べて
原因私は戻って、それは簡単ですテーブル全体のマッチをしたい場合は...
public Cursor getMatch(SQLiteDatabase db){
String query="select * from "+TABLE_MATCH;
Cursor cursor=db.rawQuery(query,null);
return cursor;
}
が...
私はdo {..} while(cursor1.moveToNext())を削除しましたが、それでも同じ...私は正しい行を取得しません – Koalito