зеркало из https://github.com/mozilla/gecko-dev.git
Bug 481178 - mozIStorageConnection createTable and tableExists should support attached databases. r=mak
This commit is contained in:
Родитель
149bce343a
Коммит
bfd9a489d3
|
@ -704,9 +704,21 @@ Connection::databaseElementExists(enum DatabaseElementType aElementType,
|
|||
{
|
||||
if (!mDBConn) return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
nsCString query("SELECT name FROM (SELECT * FROM sqlite_master UNION ALL "
|
||||
"SELECT * FROM sqlite_temp_master) "
|
||||
"WHERE type = '");
|
||||
// When constructing the query, make sure to SELECT the correct db's sqlite_master
|
||||
// if the user is prefixing the element with a specific db. ex: sample.test
|
||||
nsCString query("SELECT name FROM (SELECT * FROM ");
|
||||
nsDependentCSubstring element;
|
||||
int32_t ind = aElementName.FindChar('.');
|
||||
if (ind == kNotFound) {
|
||||
element.Assign(aElementName);
|
||||
}
|
||||
else {
|
||||
nsDependentCSubstring db(Substring(aElementName, 0, ind + 1));
|
||||
element.Assign(Substring(aElementName, ind + 1, aElementName.Length()));
|
||||
query.Append(db);
|
||||
}
|
||||
query.Append("sqlite_master UNION ALL SELECT * FROM sqlite_temp_master) WHERE type = '");
|
||||
|
||||
switch (aElementType) {
|
||||
case INDEX:
|
||||
query.Append("index");
|
||||
|
@ -716,7 +728,7 @@ Connection::databaseElementExists(enum DatabaseElementType aElementType,
|
|||
break;
|
||||
}
|
||||
query.Append("' AND name ='");
|
||||
query.Append(aElementName);
|
||||
query.Append(element);
|
||||
query.Append("'");
|
||||
|
||||
sqlite3_stmt *stmt;
|
||||
|
|
|
@ -147,6 +147,32 @@ add_task(function test_createTable_already_created()
|
|||
}
|
||||
});
|
||||
|
||||
add_task(function test_attach_createTable_tableExists_indexExists()
|
||||
{
|
||||
var msc = getOpenedDatabase();
|
||||
var file = do_get_file("storage_attach.sqlite", true);
|
||||
var msc2 = getDatabase(file);
|
||||
msc.executeSimpleSQL("ATTACH DATABASE '" + file.path + "' AS sample");
|
||||
|
||||
do_check_false(msc.tableExists("sample.test"));
|
||||
msc.createTable("sample.test", "id INTEGER PRIMARY KEY, name TEXT");
|
||||
do_check_true(msc.tableExists("sample.test"));
|
||||
try {
|
||||
msc.createTable("sample.test", "id INTEGER PRIMARY KEY, name TEXT");
|
||||
do_throw("We shouldn't get here!");
|
||||
} catch (e if e.result == Components.results.NS_ERROR_FAILURE) {
|
||||
// we expect to fail because this table should exist already.
|
||||
}
|
||||
|
||||
do_check_false(msc.indexExists("sample.test_ind"));
|
||||
msc.executeSimpleSQL("CREATE INDEX sample.test_ind ON test (name)");
|
||||
do_check_true(msc.indexExists("sample.test_ind"));
|
||||
|
||||
msc.executeSimpleSQL("DETACH DATABASE sample");
|
||||
msc2.close();
|
||||
try { file.remove(false); } catch(e) { }
|
||||
});
|
||||
|
||||
add_task(function test_lastInsertRowID()
|
||||
{
|
||||
var msc = getOpenedDatabase();
|
||||
|
|
Загрузка…
Ссылка в новой задаче