[英]Android SQLiteDatabase.openDatabase returns the path instead of the Database itself
I'm trying to open a database passed from a intent, when I try to open the DB it will return the DB path instead of the DB self, so when I try to perform SQLite commands it wont work 我正在尝试打开从意图传递的数据库,当我尝试打开数据库时,它将返回数据库路径而不是数据库自身,因此当我尝试执行SQLite命令时,它将无法工作
URI uri = (Uri) getIntent().getExtras().get(Intent.EXTRA_STREAM);
SQLiteDatabase oldDB = SQLiteDatabase.openDatabase(uri.getPath(), null, 1);
database.selectTable(oldDB)
//select table from old DB
selectTable(SQLiteDatabase oldDB){
database.execSQL("SELECT * FROM " +
oldDB +
".table1"
}
will result in error: SELECT * FROM SQLiteDatabase: /mnt/sdcard/path/to/database.db.table1 I need to get the actual Database "SELECT * FROM nameOfDatabase.table1" 将导致错误:SELECT * FROM SQLiteDatabase:/mnt/sdcard/path/to/database.db.table1我需要获取实际的数据库“ SELECT * FROM nameOfDatabase.table1”
when I try to open the DB it will return the DB path instead of the DB self
当我尝试打开数据库时,它将返回数据库路径而不是数据库自身
No, it does not. 不,不是的。
toString()
on a SQLiteDatabase
returns the path. SQLiteDatabase
上的toString()
返回路径。 You are concatenating toString()
on a SQLiteDatabase
in your query, for unknown reasons. 由于未知原因,您正在查询中的
SQLiteDatabase
上串联toString()
。 If you want to perform a query on oldDB
, call query()
or rawQuery()
on oldDB
, not whatever database
is. 如果你想执行一个查询
oldDB
,调用query()
或rawQuery()
上oldDB
,没有任何database
的。
The name of a database that you have opened with openDatabase
is always main
. 使用
openDatabase
打开的数据库的名称始终为main
。
You get different database names only when you actually attach a database to another, ie, when you execute an ATTACH statement on a database. 仅当您实际将一个数据库附加到另一个数据库时,即在数据库上执行ATTACH语句时,才能获得不同的数据库名称。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.