Bug 394241 - Add a closeDatabase() method to mozStorage. r=sspitzer

This commit is contained in:
sdwilsh@shawnwilsher.com 2007-08-30 06:43:17 -07:00
Родитель 0ad40f6dfb
Коммит 4eac417aa8
3 изменённых файлов: 45 добавлений и 17 удалений

Просмотреть файл

@ -54,11 +54,17 @@ interface nsIFile;
* creating prepared statements, executing SQL, and examining database
* errors.
*/
[scriptable, uuid(9f36de9d-6471-4249-afed-1ee7760e325c)]
[scriptable, uuid(e42f0655-cdc3-47c6-824a-cdb88c731cb9)]
interface mozIStorageConnection : nsISupports {
/*
* 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

Просмотреть файл

@ -78,19 +78,7 @@ mozStorageConnection::mozStorageConnection(mozIStorageService* aService)
mozStorageConnection::~mozStorageConnection()
{
if (mDBConn) {
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);
}
(void)Close();
}
#ifdef PR_LOGGING
@ -183,6 +171,28 @@ mozStorageConnection::Initialize(nsIFile *aDatabaseFile)
** 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
mozStorageConnection::GetConnectionReady(PRBool *aConnectionReady)
{

Просмотреть файл

@ -39,9 +39,10 @@
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
// of memory trying to use an in-memory database
@ -49,6 +50,16 @@ function test_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()
{
var msc = getOpenedDatabase();
@ -211,7 +222,8 @@ function test_backup_new_folder()
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_createTable_not_created, test_indexExists_created,
test_createTable_already_created, test_lastInsertRowID,