void BaseDatabaseUnitImpl::runCreateStatements()
	{
		loadDatabaseInfo();

		if (database_)
		{
			try
			{
				uint32_t version = databaseInfo_->latest_.version_;
				for (auto it = databaseInfo_->latest_.tableList_.begin(); it != databaseInfo_->latest_.tableList_.end(); ++it)
				{
					CppSQLite3Statement statement = database_->compileStatement(it->statement_.c_str());
					runTransaction(statement);
				}

				CppSQLite3Statement statement = database_->compileStatement(SQL_VERSION_TABLE_CREATE);
				runTransaction(statement);

				statement = database_->compileStatement(SQL_VERSION_TABLE_SET_VERSION);
				statement.bind(1, VERSION_KEY);
				statement.bind(2, (int)version);
				runTransaction(statement);

				runUpdateStatements();
			}
			catch (CppSQLite3Exception e)
			{
				LOG_ERR_R(DATABASE_MANAGER_LOG_TAG, _T("Failed to run create statements, error: %u"), e.errorCode());
				LOG_ERR_D_A(DATABASE_MANAGER_LOG_TAG_A, "Message: %s", e.errorMessage());
			}
		}
	}
void Database::changeVersion(const String& oldVersion, const String& newVersion,
                             PassRefPtr<SQLTransactionCallback> callback, PassRefPtr<SQLTransactionErrorCallback> errorCallback,
                             PassRefPtr<VoidCallback> successCallback)
{
    ChangeVersionData data(oldVersion, newVersion);
    runTransaction(callback, errorCallback, successCallback, false, &data);
}
	void BaseDatabaseUnitImpl::runTransaction(CppSQLite3Statement & statement)
	{
		std::vector<CppSQLite3Statement> statements;
		statements.push_back(statement);

		runTransaction(statements);
	}
void Database::runTransaction(
    SQLTransactionCallback* callback,
    SQLTransactionErrorCallback* errorCallback,
    VoidCallback* successCallback,
    bool readOnly,
    const ChangeVersionData* changeVersionData)
{
    ASSERT(executionContext()->isContextThread());
    // FIXME: Rather than passing errorCallback to SQLTransaction and then
    // sometimes firing it ourselves, this code should probably be pushed down
    // into Database so that we only create the SQLTransaction if we're
    // actually going to run it.
#if ENABLE(ASSERT)
    SQLTransactionErrorCallback* originalErrorCallback = errorCallback;
#endif
    SQLTransaction* transaction = SQLTransaction::create(this, callback, successCallback, errorCallback, readOnly);
    SQLTransactionBackend* transactionBackend = runTransaction(transaction, readOnly, changeVersionData);
    if (!transactionBackend) {
        SQLTransactionErrorCallback* callback = transaction->releaseErrorCallback();
        ASSERT(callback == originalErrorCallback);
        if (callback) {
            OwnPtr<SQLErrorData> error = SQLErrorData::create(SQLError::UNKNOWN_ERR, "database has been closed");
            executionContext()->postTask(BLINK_FROM_HERE, createSameThreadTask(&callTransactionErrorCallback, callback, error.release()));
        }
    }
}
void Database::readTransaction(
    SQLTransactionCallback* callback,
    SQLTransactionErrorCallback* errorCallback,
    VoidCallback* successCallback)
{
    runTransaction(callback, errorCallback, successCallback, true);
}
	void BaseDatabaseUnitImpl::runUpdateStatements()
	{
		loadDatabaseInfo();

		if (database_)
		{
			uint32_t version = getDatabaseVersion();
			if (version > 0)
			{
				auto it = databaseInfo_->updateMap_.find(boost::lexical_cast<std::string>(version + 1));
				if (it != databaseInfo_->updateMap_.end())
				{
					try
					{
						for (it; it != databaseInfo_->updateMap_.end(); ++it)
						{
							for (auto it2 = it->second.tableList_.begin(); it2 != it->second.tableList_.end(); ++it2)
							{
								CppSQLite3Statement statement = database_->compileStatement(it2->statement_.c_str());
								runTransaction(statement);
							}

							try
							{
								version = boost::lexical_cast<uint32_t>(it->first);
							}
							catch (...)
							{
							}
						}

						CppSQLite3Statement statement = database_->compileStatement(SQL_VERSION_TABLE_SET_VERSION);
						statement.bind(1, VERSION_KEY);
						statement.bind(2, (int)version);
						runTransaction(statement);
					}
					catch (CppSQLite3Exception e)
					{
						LOG_ERR_R(DATABASE_MANAGER_LOG_TAG, _T("Failed to run update statements, error: %u"), e.errorCode());
						LOG_ERR_D_A(DATABASE_MANAGER_LOG_TAG_A, "Message: %s", e.errorMessage());
					}
				}
			}
		}
	}
void Database::changeVersion(
    const String& oldVersion,
    const String& newVersion,
    SQLTransactionCallback* callback,
    SQLTransactionErrorCallback* errorCallback,
    VoidCallback* successCallback)
{
    ChangeVersionData data(oldVersion, newVersion);
    runTransaction(callback, errorCallback, successCallback, false, &data);
}
Exemple #8
0
void Database::runTransaction(RefPtr<SQLTransactionCallback>&& callback, RefPtr<SQLTransactionErrorCallback>&& errorCallback, RefPtr<VoidCallback>&& successCallback, bool readOnly, const ChangeVersionData* changeVersionData)
{
    RefPtr<SQLTransaction> transaction = SQLTransaction::create(*this, WTF::move(callback), WTF::move(successCallback), errorCallback.copyRef(), readOnly);

    RefPtr<SQLTransactionBackend> transactionBackend = runTransaction(transaction.release(), readOnly, changeVersionData);
    if (!transactionBackend && errorCallback) {
        WTF::RefPtr<SQLTransactionErrorCallback> errorCallbackProtector = WTF::move(errorCallback);
        m_scriptExecutionContext->postTask([errorCallbackProtector](ScriptExecutionContext&) {
            errorCallbackProtector->handleEvent(SQLError::create(SQLError::UNKNOWN_ERR, "database has been closed").get());
        });
    }
}
void Database::readTransaction(PassRefPtr<SQLTransactionCallback> callback, PassRefPtr<SQLTransactionErrorCallback> errorCallback, PassRefPtr<VoidCallback> successCallback)
{
    runTransaction(callback, errorCallback, successCallback, true);
}
void DatabaseSync::readTransaction(PassRefPtr<SQLTransactionSyncCallback> callback, ExceptionCode& ec)
{
    runTransaction(callback, true, ec);
}
Exemple #11
0
void Database::changeVersion(const String& oldVersion, const String& newVersion,
                             PassRefPtr<SQLTransactionCallback> callback, PassRefPtr<SQLTransactionErrorCallback> errorCallback,
                             PassRefPtr<VoidCallback> successCallback)
{
    runTransaction(callback, errorCallback, successCallback, ChangeVersionWrapper::create(oldVersion, newVersion), false);
}
void DatabaseSync::readTransaction(PassOwnPtr<SQLTransactionSyncCallback> callback, ExceptionState& exceptionState)
{
    runTransaction(callback, true, exceptionState);
}