저는 sqlite, LocationsContentProvider를 사용하여 Android 애플리케이션을 개발 중입니다. JOIN에 문제가 있습니다.Android sqlite JOIN에 데이터가 표시되지 않습니다.
// Returns all the locations from the table
public Cursor getAllLocations(){
Cursor cursor;
cursor = mDB.query(DATABASE_TABLE, new String[] { FIELD_ROW_ID, FIELD_LAT , FIELD_LNG, FIELD_ZOOM, FIELD_ADDRESS } , null, null, null, null, null);
Log.d(TAG, "DB: query complete" + cursor);
return cursor;
}
을 그리고 이것은 작동하지 않습니다 :
이
는 잘 작동했다// Return all locations joined with sub map name
public Cursor getAllLocations(){
Cursor cursor;
String query;
query = "SELECT a._id, a.lat, a.lng, a.sub_map_id, a.zoom, a.address, b._id, b.sub_map FROM locations a" +
" INNER JOIN sub_map_table b ON a.sub_map_id=b._id";
Log.d(TAG, "DB: query = \n" + query;
Log.d(TAG, "DB: query complete");
cursor = mDB.rawQuery(query, null);
return cursor;
}
데이터베이스 구조의 일부 기타 세부 사항 :
// Fields for locations table
public static final String FIELD_ROW_ID ="_id";
public static final String FIELD_LAT = "lat";
public static final String FIELD_LNG = "lng";
public static final String FIELD_ZOOM = "zoom";
public static final String FIELD_ADDRESS ="address";
public static final String FIELD_SUB_MAP_ID = "sub_map_id";
// Fields for SUB_MAP_TABLE table
public static final String FIELD_SUB_MAP_ROW_ID = "_id";
public static final String FIELD_SUB_MAP = "sub_map";
//table name, a constant
private static final String DATABASE_TABLE = "locations";
private static final String SUB_MAP_TABLE = "sub_map_table";
private static final String TAG = null;
//instance variable for SQLiteDatabse
private SQLiteDatabase mDB;
//constructor
public LocationsDB(Context context) {
super(context, DBNAME, null, VERSION);
this.mDB = getWritableDatabase();
}
/** This is a callback method, invoked when the method getReadableDatabase()/getWritableDatabase() is called
* provided the database does not exists
* */
@Override
public void onCreate(SQLiteDatabase db) {
String create_table_locations = "create table " + DATABASE_TABLE + " (" +
FIELD_ROW_ID + " integer primary key autoincrement , " +
FIELD_LNG + " double , " +
FIELD_LAT + " double , " +
FIELD_ZOOM + " text , " +
FIELD_ADDRESS + " text , " +
FIELD_SUB_MAP_ID + " integer " +
") ";
String create_table_submap = "create table " + SUB_MAP_TABLE + " (" +
FIELD_SUB_MAP_ROW_ID + " integer primary key autoincrement , " +
FIELD_SUB_MAP + " text " +
") ";
db.execSQL(create_table_locations);
db.execSQL(create_table_submap);
는 동안보고 된 하루 종일 나는 틀린 것이 무엇인지 알 수 없다. 제발 조언 해주세요. 아무 것도 전송되지 않는 것 같습니다. 또는 전송 된 경우 캡처되지 않습니다.
) logcat에 오류가 있습니까? 잘못된 쿼리 인 경우 SQLite가 알려줍니다. 그렇지 않은 경우 검색어에 0 개의 결과가있을 수 있으며 데이터베이스 데이터와 구조를 알지 못하면 답변을 드릴 수 없습니다. –
'DATABASE_TABLE '=''locations "'입니까? 그리고 모든'FIELD_' *는''a._' *'''와 일치합니까? –