复制数据库文件出错

时间:2015-04-15 12:24:41

标签: sqlite root cp busybox

String gaanaDB = "/data/data/com.xyz/databases/DB";
String converterDB = "/data/data/com.abc/databases/DB";
Runtime.getRuntime().exec("su");
Runtime.getRuntime().exec("busybox cp -f " + gaanaDB + " " + converterDB);

DBhelper.java

package com.aks.gaanaconverter.util;
import android.content.Context; 
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DBHelper extends SQLiteOpenHelper {
private static final String DATABASE_NAME = "GaanaDB";
private static final String TABLE_NAME = "table_track_metadata";
private static final String ID = "track_id";
private static final String NAME = "track_name";
private static final String HAS_DOWNLOADED = "has_downloaded";
private static final int HAS_DOWNLOADED_VALUE = 1;

public DBHelper(Context context) {
    super(context, DATABASE_NAME, null, 6);
    // TODO Auto-generated constructor stub
}

@Override
public void onCreate(SQLiteDatabase arg0) {
    // TODO Auto-generated method stub
}

@Override
public void onUpgrade(SQLiteDatabase arg0, int arg1, int arg2) {
    // TODO Auto-generated method stub

}

public Cursor getData() {
    SQLiteDatabase db = this.getReadableDatabase();
    Cursor res = db.rawQuery("select " + ID + "," + NAME + " from "
            + TABLE_NAME/*
                         * +" where "+HAS_DOWNLOADED+"="+HAS_DOWNLOADED_VALUE
                         */, null);
    return res;
}
}

当我尝试访问数据库时,它不会抛出这样的表。

我在Shell Commander应用程序中尝试过该命令它完美无缺。 但是,当我尝试在我的应用程序中使用它时,它不会复制数据库中的表。

安装Rooted Kitkat和BusyBox。

1 个答案:

答案 0 :(得分:0)

首先尝试创建表格:

 public void onCreate(SQLiteDatabase db) {
    db.execSQL("CREATE TABLE if not exists table_track_metadata(track_id INTEGER PRIMARY KEY AUTOINCREMENT,"
            + "track_name"
            + " TEXT,"...)");

}