mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 472963 - TableExists and IndexExists does not work for temporary tables, r=mak
This commit is contained in:
parent
183bab5e57
commit
5628f20963
@ -704,7 +704,9 @@ Connection::databaseElementExists(enum DatabaseElementType aElementType,
|
||||
{
|
||||
if (!mDBConn) return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
nsAutoCString query("SELECT name FROM sqlite_master WHERE type = '");
|
||||
nsCString query("SELECT name FROM (SELECT * FROM sqlite_master UNION ALL "
|
||||
"SELECT * FROM sqlite_temp_master) "
|
||||
"WHERE type = '");
|
||||
switch (aElementType) {
|
||||
case INDEX:
|
||||
query.Append("index");
|
||||
|
@ -108,6 +108,19 @@ add_task(function test_indexExists_not_created()
|
||||
do_check_false(msc.indexExists("foo"));
|
||||
});
|
||||
|
||||
add_task(function test_temp_tableExists_and_indexExists()
|
||||
{
|
||||
var msc = getOpenedDatabase();
|
||||
msc.executeSimpleSQL("CREATE TEMP TABLE test_temp(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)");
|
||||
do_check_true(msc.tableExists("test_temp"));
|
||||
|
||||
msc.executeSimpleSQL("CREATE INDEX test_temp_ind ON test_temp (name)");
|
||||
do_check_true(msc.indexExists("test_temp_ind"));
|
||||
|
||||
msc.executeSimpleSQL("DROP INDEX test_temp_ind");
|
||||
msc.executeSimpleSQL("DROP TABLE test_temp");
|
||||
});
|
||||
|
||||
add_task(function test_createTable_not_created()
|
||||
{
|
||||
var msc = getOpenedDatabase();
|
||||
|
@ -600,9 +600,7 @@ OpenedConnection.prototype = Object.freeze({
|
||||
},
|
||||
|
||||
/**
|
||||
* Whether a table exists in the database.
|
||||
*
|
||||
* IMPROVEMENT: Look for temporary tables.
|
||||
* Whether a table exists in the database (both persistent and temporary tables).
|
||||
*
|
||||
* @param name
|
||||
* (string) Name of the table.
|
||||
@ -611,7 +609,9 @@ OpenedConnection.prototype = Object.freeze({
|
||||
*/
|
||||
tableExists: function (name) {
|
||||
return this.execute(
|
||||
"SELECT name FROM sqlite_master WHERE type='table' AND name=?",
|
||||
"SELECT name FROM (SELECT * FROM sqlite_master UNION ALL " +
|
||||
"SELECT * FROM sqlite_temp_master) " +
|
||||
"WHERE type = 'table' AND name=?",
|
||||
[name])
|
||||
.then(function onResult(rows) {
|
||||
return Promise.resolve(rows.length > 0);
|
||||
@ -620,9 +620,7 @@ OpenedConnection.prototype = Object.freeze({
|
||||
},
|
||||
|
||||
/**
|
||||
* Whether a named index exists.
|
||||
*
|
||||
* IMPROVEMENT: Look for indexes in temporary tables.
|
||||
* Whether a named index exists (both persistent and temporary tables).
|
||||
*
|
||||
* @param name
|
||||
* (string) Name of the index.
|
||||
@ -631,7 +629,9 @@ OpenedConnection.prototype = Object.freeze({
|
||||
*/
|
||||
indexExists: function (name) {
|
||||
return this.execute(
|
||||
"SELECT name FROM sqlite_master WHERE type='index' AND name=?",
|
||||
"SELECT name FROM (SELECT * FROM sqlite_master UNION ALL " +
|
||||
"SELECT * FROM sqlite_temp_master) " +
|
||||
"WHERE type = 'index' AND name=?",
|
||||
[name])
|
||||
.then(function onResult(rows) {
|
||||
return Promise.resolve(rows.length > 0);
|
||||
|
@ -60,6 +60,22 @@ function getDummyDatabase(name, extraOptions={}) {
|
||||
throw new Task.Result(c);
|
||||
}
|
||||
|
||||
function getDummyTempDatabase(name, extraOptions={}) {
|
||||
const TABLES = {
|
||||
dirs: "id INTEGER PRIMARY KEY AUTOINCREMENT, path TEXT",
|
||||
files: "id INTEGER PRIMARY KEY AUTOINCREMENT, dir_id INTEGER, path TEXT",
|
||||
};
|
||||
|
||||
let c = yield getConnection(name, extraOptions);
|
||||
c._initialStatementCount = 0;
|
||||
|
||||
for (let [k, v] in Iterator(TABLES)) {
|
||||
yield c.execute("CREATE TEMP TABLE " + k + "(" + v + ")");
|
||||
c._initialStatementCount++;
|
||||
}
|
||||
|
||||
throw new Task.Result(c);
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
Cu.import("resource://testing-common/services-common/logging.js");
|
||||
@ -203,6 +219,27 @@ add_task(function test_index_exists() {
|
||||
yield c.close();
|
||||
});
|
||||
|
||||
add_task(function test_temp_table_exists() {
|
||||
let c = yield getDummyTempDatabase("temp_table_exists");
|
||||
|
||||
do_check_false(yield c.tableExists("temp_does_not_exist"));
|
||||
do_check_true(yield c.tableExists("dirs"));
|
||||
do_check_true(yield c.tableExists("files"));
|
||||
|
||||
yield c.close();
|
||||
});
|
||||
|
||||
add_task(function test_temp_index_exists() {
|
||||
let c = yield getDummyTempDatabase("temp_index_exists");
|
||||
|
||||
do_check_false(yield c.indexExists("temp_does_not_exist"));
|
||||
|
||||
yield c.execute("CREATE INDEX my_index ON dirs (path)");
|
||||
do_check_true(yield c.indexExists("my_index"));
|
||||
|
||||
yield c.close();
|
||||
});
|
||||
|
||||
add_task(function test_close_cached() {
|
||||
let c = yield getDummyDatabase("close_cached");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user