Android sqlcipher getDatabaseName()
Android sqlcipher getDatabaseName()
在我的项目中,我正确使用了库 https://www.zetetic.net/sqlcipher/。现在我需要获取数据库的名称。在经典的SQLite中,有一个方法getDatabaseName()而不是密码似乎没有它,我该怎么办?你有什么想法吗?
import net.sqlcipher.database.SQLiteDatabase;
import net.sqlcipher.database.SQLiteOpenHelper;
public class DbCrypt extends SQLiteOpenHelper {
private static final String DB_NAME = "data.db";
private static final int DB_VERSION = 1;
private static SQLiteDatabase db = null;
public DbCrypt(Context context) {
super(context, DB_NAME, null, DB_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
DbCrypt.db = db;
...
...
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
编辑
在您的 SQLCipher 版本 SQLiteOpenHelper
的子类中,实施一个 getDatabaseName()
方法 returns 您的数据库名称。您也可以在构造函数中使用它,这样您就不必重复数据库名称值:
import net.sqlcipher.database.SQLiteDatabase;
import net.sqlcipher.database.SQLiteOpenHelper;
public class DbCrypt extends SQLiteOpenHelper {
private static final String DB_NAME = "data.db";
private static final int DB_VERSION = 1;
private static SQLiteDatabase db = null;
public DbCrypt(Context context) {
super(context, getDatabaseName(), null, DB_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
DbCrypt.db = db;
...
...
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
public String getDatabaseName() {
return(DB_NAME);
}
在我的项目中,我正确使用了库 https://www.zetetic.net/sqlcipher/。现在我需要获取数据库的名称。在经典的SQLite中,有一个方法getDatabaseName()而不是密码似乎没有它,我该怎么办?你有什么想法吗?
import net.sqlcipher.database.SQLiteDatabase;
import net.sqlcipher.database.SQLiteOpenHelper;
public class DbCrypt extends SQLiteOpenHelper {
private static final String DB_NAME = "data.db";
private static final int DB_VERSION = 1;
private static SQLiteDatabase db = null;
public DbCrypt(Context context) {
super(context, DB_NAME, null, DB_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
DbCrypt.db = db;
...
...
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
编辑
在您的 SQLCipher 版本 SQLiteOpenHelper
的子类中,实施一个 getDatabaseName()
方法 returns 您的数据库名称。您也可以在构造函数中使用它,这样您就不必重复数据库名称值:
import net.sqlcipher.database.SQLiteDatabase;
import net.sqlcipher.database.SQLiteOpenHelper;
public class DbCrypt extends SQLiteOpenHelper {
private static final String DB_NAME = "data.db";
private static final int DB_VERSION = 1;
private static SQLiteDatabase db = null;
public DbCrypt(Context context) {
super(context, getDatabaseName(), null, DB_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
DbCrypt.db = db;
...
...
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
public String getDatabaseName() {
return(DB_NAME);
}