2016-10-06 14 views
2

나는 안드로이드 sqlite 데이터베이스에서 임시 테이블을 만들고 사용하고 싶습니다.
SQL 문이 예외없이 실행되지만 테이블이 작성되지 않습니다! 아래의 샘플 코드와 함께 내 응용 프로그램을 실행
, 나는 더 테이블 없어 :안드로이드 sqlite는 TEMP 테이블을 만들 수 없습니다

START 편집을

public class DatabaseHelper extends SQLiteOpenHelper { 
public static final String DB_NAME = "mydb.db"; 
private static DatabaseHelper instance; 

public static synchronized DatabaseHelper getHelper(Context context){ 
    if (instance == null) 
     instance = new DatabaseHelper(context); 
    return instance; 
} 

private DatabaseHelper(Context c) { 
    super(c,DB_NAME,null,1); 
} 

@Override 
public void onConfigure(SQLiteDatabase db) { 
    super.onConfigure(db); 
    db.enableWriteAheadLogging(); 
    db.setLocale(Locale.getDefault()); 
} 

@Override 
public void onCreate(SQLiteDatabase db) { 
    // lots of table creation 
    db.execSQL("CREATE TABLE my_table (id INTEGER PRIMARY KEY, value TEXT)"); 
    // more tables .... 
}} 
...... sample 
DatabaseHelper databaseHelper = DatabaseHelper.getHelper(this); 

최종 편집

SQLiteDatabase db = databaseHelper.getWritableDatabase(); 
db.execSQL("create TEMP table my_temp_table (id integer primary key, value text)"); // no exceptions 

Cursor cursor = db.query("SQLITE_TEMP_MASTER", null, null, null, null, null, null); 

while(cur.moveToNext()) { 
    // no lines (no temporary tables) 
} 

난에서 임시 테이블을 작성하는 경우 select 문을 실행 한 다음 생성 된 테이블을 동일한 db 연결 내에서 쿼리하면 "no such such table .... exception"이 발생합니다! 나를 혼란 무엇

db.execSQL("create TEMP table my_temp_table as select * from my_table"); 
Cursor cursor = db.query("temp.my_temp_table", null, null, null, null, null, null); 
^^^ no such table: temp.my_temp_table(code 1): , while compiling: SELECT * FROM temp.my_temp_table 

는 동일한 SQL 코드가 응용 프로그램 외부와 안드로이드 장치 외부 SQLiteStudio 즉 내에서 완벽하게 작동합니다 ...입니다. 아마도 무언가를 사용하는 것을 잊어 버렸거나 ... 특정 장치 사용 권한이 필요합니까?

+0

당신이 당신의 databaseHelper.getWritableDatabase에서 코드를 제공 할 수 사용하도록 코드()하세요? – glethien

+0

예! DatabaseHelper 클래스로 내 게시물을 업데이트했습니다. –

+1

알고 계십니까? http://www.sqlite.org/tempfiles.html#tempdb 정말 TEMP 테이블을 만든 연결을 닫지 않았습니까? – kosa

답변

0

create temp table x의 결과는 테이블 x하지 temp.x

변경 my_temp_table

+0

제안 된대로 코드를 변경했으며 "다시 그런 테이블이 없습니다 .... 예외"가 발생했습니다! –