BlackBerry SQLite: Attach one SQLite database to another
I'm trying to attach one SQLite database to another on BlackBerry using SQLite ATTACH DATABASE command.
Database d1, d2;
Statement st;
URI dbURI1 = URI.create("file:///SDCard/Databases/SQLiteExample/MyTestDatabase1.db")
if (DatabaseFactory.exists(dbURI1)) {
d1 = DatabaseFactory.open(dbURI1);
} else {
d1 = DatabaseFactory.create(dbURI1);
st = d1.createStatement("CREATE TABLE 'People' ( 'Name' TEXT, 'Age' INTEGER )");
st.prepare();
st.execute();
st.close();
}
URI dbURI2 = URI.create("file:///SDCard/Databases/SQLiteExample/MyTestDatabase2.db");
if (DatabaseFactory.exists(dbURI2)) {
d2 = DatabaseFactory.open(dbURI2);
} else {
d2 = DatabaseFactory.create(dbURI2);
st = d2.createStatement("CREATE TABLE 'People2' ('Name2' TEXT, 'Age2' INTEGER )");
开发者_如何学JAVA st.prepare();
st.execute();
st.close();
d2.close();
}
st = d1.createStatement("ATTACH DATABASE '/SDCard/Databases/SQLiteExample/MyTestDatabase2.db' as SECOND_TABLE");
st.prepare(); //THROWS AN EXCEPTION "SQL logic error or missing database"
st.execute();
st.close();
I'm getting an Exception ATTACH DATABASE /SDCard/Databases/SQLiteExample/MyTestDatabase2.db' as SECOND_TABLE: SQLlogic error or missing database
when it tries to prepare statement for "Attach Database" command.
Is it possible to use ATTACH DATABASE
command with BlackBerry SQLite API?
Thanks.
No, the BlackBerry implementation of SQLite does not support ATTACH DATABASE. See the BlackBerry documentation "Working with SQLite databases" for confirmation.
RIM has added Attach/Detach Database
commands to their BlackBerry OS 7.0 API:
BlackBerry 7.0 API Docs
精彩评论