зеркало из https://github.com/mozilla/pjs.git
Bug 394241 - Add a closeDatabase() method to mozStorage. r=sspitzer
This commit is contained in:
Родитель
0ad40f6dfb
Коммит
4eac417aa8
|
@ -54,11 +54,17 @@ interface nsIFile;
|
||||||
* creating prepared statements, executing SQL, and examining database
|
* creating prepared statements, executing SQL, and examining database
|
||||||
* errors.
|
* errors.
|
||||||
*/
|
*/
|
||||||
[scriptable, uuid(9f36de9d-6471-4249-afed-1ee7760e325c)]
|
[scriptable, uuid(e42f0655-cdc3-47c6-824a-cdb88c731cb9)]
|
||||||
interface mozIStorageConnection : nsISupports {
|
interface mozIStorageConnection : nsISupports {
|
||||||
/*
|
/*
|
||||||
* Initialization and status
|
* Initialization and status
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Closes a database connection. C++ callers should simply set the database
|
||||||
|
* variable to NULL.
|
||||||
|
*/
|
||||||
|
void close();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* whether the database is open or not
|
* whether the database is open or not
|
||||||
|
|
|
@ -78,19 +78,7 @@ mozStorageConnection::mozStorageConnection(mozIStorageService* aService)
|
||||||
|
|
||||||
mozStorageConnection::~mozStorageConnection()
|
mozStorageConnection::~mozStorageConnection()
|
||||||
{
|
{
|
||||||
if (mDBConn) {
|
(void)Close();
|
||||||
if (mProgressHandler)
|
|
||||||
sqlite3_progress_handler(mDBConn, 0, NULL, NULL);
|
|
||||||
int srv = sqlite3_close (mDBConn);
|
|
||||||
if (srv != SQLITE_OK)
|
|
||||||
NS_WARNING("sqlite3_close failed. There are probably outstanding statements!");
|
|
||||||
|
|
||||||
// make sure it really got closed
|
|
||||||
((mozStorageService*)(mStorageService.get()))->FlushAsyncIO();
|
|
||||||
|
|
||||||
// Release all functions
|
|
||||||
mFunctions.EnumerateRead(s_ReleaseFuncEnum, NULL);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef PR_LOGGING
|
#ifdef PR_LOGGING
|
||||||
|
@ -183,6 +171,28 @@ mozStorageConnection::Initialize(nsIFile *aDatabaseFile)
|
||||||
** Core status/initialization
|
** Core status/initialization
|
||||||
**/
|
**/
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
mozStorageConnection::Close()
|
||||||
|
{
|
||||||
|
if (!mDBConn)
|
||||||
|
return NS_ERROR_NOT_INITIALIZED;
|
||||||
|
|
||||||
|
if (mProgressHandler)
|
||||||
|
sqlite3_progress_handler(mDBConn, 0, NULL, NULL);
|
||||||
|
int srv = sqlite3_close(mDBConn);
|
||||||
|
if (srv != SQLITE_OK)
|
||||||
|
NS_WARNING("sqlite3_close failed. There are probably outstanding statements!");
|
||||||
|
|
||||||
|
// make sure it really got closed
|
||||||
|
((mozStorageService*)(mStorageService.get()))->FlushAsyncIO();
|
||||||
|
|
||||||
|
// Release all functions
|
||||||
|
mFunctions.EnumerateRead(s_ReleaseFuncEnum, NULL);
|
||||||
|
|
||||||
|
mDBConn = NULL;
|
||||||
|
return ConvertResultCode(srv);
|
||||||
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
mozStorageConnection::GetConnectionReady(PRBool *aConnectionReady)
|
mozStorageConnection::GetConnectionReady(PRBool *aConnectionReady)
|
||||||
{
|
{
|
||||||
|
|
|
@ -39,9 +39,10 @@
|
||||||
|
|
||||||
const BACKUP_FILE_NAME = "test_storage.sqlite.backup";
|
const BACKUP_FILE_NAME = "test_storage.sqlite.backup";
|
||||||
|
|
||||||
function test_connectionReady()
|
function test_connectionReady_open()
|
||||||
{
|
{
|
||||||
// there doesn't seem to be a way for the connection to not be ready
|
// there doesn't seem to be a way for the connection to not be ready (unless
|
||||||
|
// we close it with mozIStorageConnection::Close(), but we don't for this).
|
||||||
// It can only fail if GetPath fails on the database file, or if we run out
|
// It can only fail if GetPath fails on the database file, or if we run out
|
||||||
// of memory trying to use an in-memory database
|
// of memory trying to use an in-memory database
|
||||||
|
|
||||||
|
@ -49,6 +50,16 @@ function test_connectionReady()
|
||||||
do_check_true(msc.connectionReady);
|
do_check_true(msc.connectionReady);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function test_connectionReady_closed()
|
||||||
|
{
|
||||||
|
// This also tests mozIStorageConnection::Close()
|
||||||
|
|
||||||
|
var msc = getOpenedDatabase();
|
||||||
|
msc.close();
|
||||||
|
do_check_false(msc.connectionReady);
|
||||||
|
gDBConn = null; // this is so later tests don't start to fail.
|
||||||
|
}
|
||||||
|
|
||||||
function test_databaseFile()
|
function test_databaseFile()
|
||||||
{
|
{
|
||||||
var msc = getOpenedDatabase();
|
var msc = getOpenedDatabase();
|
||||||
|
@ -211,7 +222,8 @@ function test_backup_new_folder()
|
||||||
parentDir.remove(true);
|
parentDir.remove(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
var tests = [test_connectionReady, test_databaseFile,
|
var tests = [test_connectionReady_open, test_connectionReady_closed,
|
||||||
|
test_databaseFile,
|
||||||
test_tableExists_not_created, test_indexExists_not_created,
|
test_tableExists_not_created, test_indexExists_not_created,
|
||||||
test_createTable_not_created, test_indexExists_created,
|
test_createTable_not_created, test_indexExists_created,
|
||||||
test_createTable_already_created, test_lastInsertRowID,
|
test_createTable_already_created, test_lastInsertRowID,
|
||||||
|
|
Загрузка…
Ссылка в новой задаче