private void copyDatabase() throws IOException {
InputStream myInput = crContext.getAssets().open(DB_NAME);
String outFileName = DB_PATH + DB_NAME;
OutputStream myOutput = new FileOutputStream(outFileName);
byte[] buffer = new byte[1024];
int length;
while ((length = myInput.read(buffer))>0){
myOutput.write(buffer, 0, length);
}
myOutput.flush();
myOutput.close();
myInput.close();
}
결국 SQLite Databse Browser 로는 할 수가 없다는 결론을 내렸습니다. 한글에 대한 방법이 없을 뿐아니라, 자주 멈추거나 슬그머니 종료가 되기까지 합니다. 그러다가 SQLite Manager 라는 툴을 발견했습니다. 부분 무료 이기 때문에 결제를 하라는 메시지가 빈번하게 나타나긴 하지만, 중요한 것은 한글을 처리 할 수 있다는 것 이지요. ^^
public void openDataBase() throws SQLException{
String myPath = DB_PATH + DB_NAME;
sqlite = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.NO_LOCALIZED_COLLATORS);
}
public class DBAdapter {
private final Context context;
private DatabaseHelper DBHelper;
private SQLiteDatabase db;
public DBAdapter(Context ctx)
{
this.context = ctx;
DBHelper = new DatabaseHelper(this.context);
try {
DBHelper.createDatabase();
DBHelper.openDataBase();
} catch (IOException e) {
Log.d("DBAdapter", e.toString());
} catch (SQLException e) {
Log.d("DBAdapter", e.toString());
}
}
private static class DatabaseHelper extends SQLiteOpenHelper
{
private SQLiteDatabase sqlite;
private final Context crContext;
DatabaseHelper(Context context)
{
super(context, DB_NAME, null, 3);
this.crContext = context;
}
public void createDatabase() throws IOException {
if (!checkDatabase()){
this.getReadableDatabase();
try {
copyDatabase();
} catch (IOException e) {
throw new Error("Error copying database");
}
}
}
public boolean checkDatabase() {
SQLiteDatabase checkDB = null;
try{
String myPath = DB_PATH + DB_NAME;
checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.NO_LOCALIZED_COLLATORS);
} catch (SQLiteException e) {
Log.d("checkDatabase", e.toString());
}
if(checkDB != null){
checkDB.close();
}
return checkDB != null ? true : false;
}
private void copyDatabase() throws IOException {
InputStream myInput = crContext.getAssets().open(DB_NAME);
String outFileName = DB_PATH + DB_NAME;
OutputStream myOutput = new FileOutputStream(outFileName);
byte[] buffer = new byte[1024];
int length;
while ((length = myInput.read(buffer))>0){
myOutput.write(buffer, 0, length);
}
myOutput.flush();
myOutput.close();
myInput.close();
}
public void openDataBase() throws SQLException{
String myPath = DB_PATH + DB_NAME;
sqlite = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.NO_LOCALIZED_COLLATORS);
}
@Override
public synchronized void close() {
if(sqlite != null)
sqlite.close();
super.close();
}
@Override
public void onCreate(SQLiteDatabase db) {
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
}
public DBAdapter open() throws SQLException
{
db = DBHelper.getWritableDatabase();
return this;
}
public void close()
{
DBHelper.close();
}
}
이틀 동안 삽질한 보람이 있네요. 테스트 폰에서는 아주 잘 돌아갑니다.