/*!
\note Transaction unsafe. If you call several transaction unsafe methods you must enclose
the calls within a db transaction; thus within db->begin and db->commit.
545994
static function createNew( $policyID, $identifier )
    {
        $policyParameter = new eZPolicyLimitation( array() );
        $policyParameter->setAttribute( 'policy_id', $policyID );
        $policyParameter->setAttribute( 'identifier', $identifier );
        $policyParameter->store();

        return $policyParameter;
    }
649471
public function rollBack()
    {
        if (!$this->getIsActive()) {
            // do nothing if transaction is not active: this could be the transaction is committed
            // but the event handler to "commitTransaction" throw an exception
            return;
        }

        $this->_level--;
        if ($this->_level === 0) {
            Log::debug('Roll back transaction' . __METHOD__);
            $this->db->pdo->rollBack();
            $this->db->trigger(Connection::EVENT_ROLLBACK_TRANSACTION);
            return;
        }

        $schema = $this->db->getSchema();
        if ($schema->supportsSavepoint()) {
            Log::debug('Roll back to savepoint ' . $this->_level . __METHOD__);
            $schema->rollBackSavepoint('LEVEL' . $this->_level);
        } else {
            Log::info('Transaction not rolled back: nested transaction not supported' . __METHOD__);
            // throw an exception to fail the outer transaction
            throw new Exception('Roll back failed: nested transaction not supported.');
        }
    }
98061
public void commit() throws DBException
    {
        if (DBConstants.FALSE.equalsIgnoreCase(this.getProperty(SQLParams.AUTO_COMMIT_PARAM)))
        {
            if (!(this.getDatabaseOwner() instanceof RecordOwner))
                throw new DatabaseException("Transactions requires DB RecordOwnership");
        }
        else
            throw new DatabaseException("Auto-commit enabled");
    }
371097
public function begin() {
        if($this->isInTransaction()) {
            throw new \Exception('You cannot start a new transaction once you are already in one (Originally started at: ' . self::$stackTrace . ')');
        } else {
            $e = new \Exception();
            self::$stackTrace = $e->getTraceAsString();
        }
        $transactionManager = new TransactionManager();
        $transactionManager->setDbService($this->getDbService());
        $this->setTransaction($transactionManager->get());
    }
88277
function createTransaction(dbInfo, mode, callback, retries) {
    if (retries === undefined) {
        retries = 1;
    }

    try {
        var tx = dbInfo.db.transaction(dbInfo.storeName, mode);
        callback(null, tx);
    } catch (err) {
        if (retries > 0 && (!dbInfo.db || err.name === 'InvalidStateError' || err.name === 'NotFoundError')) {
            return Promise$1.resolve().then(function () {
                if (!dbInfo.db || err.name === 'NotFoundError' && !dbInfo.db.objectStoreNames.contains(dbInfo.storeName) && dbInfo.version <= dbInfo.db.version) {
                    // increase the db version, to create the new ObjectStore
                    if (dbInfo.db) {
                        dbInfo.version = dbInfo.db.version + 1;
                    }
                    // Reopen the database for upgrading.
                    return _getUpgradedConnection(dbInfo);
                }
            }).then(function () {
                return _tryReconnect(dbInfo).then(function () {
                    createTransaction(dbInfo, mode, callback, retries - 1);
                });
            })["catch"](callback);
        }

        callback(err);
    }
}
652994
function _close()
	{
		if ($this->transCnt) $this->RollbackTrans();
		$rez = @mssql_close($this->_connectionID);
		$this->_connectionID = false;
		return $rez;
	}
512117
public function commit($xid)
    {
        if ($this->activeTransaction != $xid || $this->activeTransaction === false) {
            return;
        }

        $this->activeTransaction = false;

        if (!$this->connection->commit()) {
            throw new DbException("Commit failed");
        }

        $this->connection->autocommit(true);
    }
942611
public function safeUp()
    {
        // Rename the FK columns
        // ---------------------------------------------------------------------

        if ($this->db->columnExists('{{%supertableblocks}}', 'ownerLocale__siteId')) {
            MigrationHelper::renameColumn('{{%supertableblocks}}', 'ownerLocale__siteId', 'ownerSiteId');
        }

        // Drop the old FKs
        // ---------------------------------------------------------------------

        MigrationHelper::dropForeignKeyIfExists('{{%supertableblocks}}', ['ownerLocale'], $this);

        // Drop the old indexes
        // ---------------------------------------------------------------------

        MigrationHelper::dropIndexIfExists('{{%supertableblocks}}', ['ownerLocale'], false, $this);

        // Drop the locale columns
        // ---------------------------------------------------------------------

        if ($this->db->columnExists('{{%supertableblocks}}', 'ownerLocale')) {
            $this->dropColumn('{{%supertableblocks}}', 'ownerLocale');
        }

        // Super Table content tables
        // ---------------------------------------------------------------------

        $superTableTablePrefix = $this->db->getSchema()->getRawTableName('{{%stc_}}');

        foreach ($this->db->getSchema()->getTableNames() as $tableName) {
            if (StringHelper::startsWith($tableName, $superTableTablePrefix)) {
                // There's actually an issue here in the MigrationHelper::dropAllIndexesOnTable class, not using the current migration
                // as context to find existing indexes. This is important, because the indexes have changed from their current names
                $this->dropAllForeignKeysOnTable($tableName);
                $this->dropAllIndexesOnTable($tableName);

                // Rename column
                if ($this->db->columnExists($tableName, 'locale__siteId')) {
                    $this->renameColumn($tableName, 'locale__siteId', 'siteId');
                }

                // Add them back (like creating a new Matrix would)
                $this->createIndex(null, $tableName, ['elementId', 'siteId'], true);
                $this->addForeignKey(null, $tableName, ['elementId'], '{{%elements}}', ['id'], 'CASCADE', null);
                $this->addForeignKey(null, $tableName, ['siteId'], '{{%sites}}', ['id'], 'CASCADE', 'CASCADE');

                // Delete the old column
                if ($this->db->columnExists($tableName, 'locale')) {
                    $this->dropColumn($tableName, 'locale');
                }
            }
        }

        Craft::$app->getDb()->getSchema()->refresh();

        // Update Super Table/relationship field settings
        // ---------------------------------------------------------------------

        $fields = (new Query())
            ->select(['id', 'type', 'translationMethod', 'settings'])
            ->from(['{{%fields}}'])
            ->where([
                'type' => [
                    SuperTableField::class,
                ]
            ])
            ->all($this->db);

        foreach ($fields as $field) {

            $settings = Json::decodeIfJson($field['settings']);

            if (!is_array($settings)) {
                echo 'Field '.$field['id'].' ('.$field['type'].') settings were invalid JSON: '.$field['settings']."\n";
                $settings = [];
            }

            $localized = ($field['translationMethod'] === 'site');

            $settings['localizeBlocks'] = $localized;

            $this->update(
                '{{%fields}}',
                [
                    'translationMethod' => 'none',
                    'settings' => Json::encode($settings),
                ],
                ['id' => $field['id']],
                [],
                false);
        }
    }
885967
function initializeObjectAttribute( $contentObjectAttribute, $currentVersion, $originalContentObjectAttribute )
    {
        if ( $currentVersion != false )
        {
            $originalContentObjectAttributeID = $originalContentObjectAttribute->attribute( 'id' );
            $contentObjectAttributeID = $contentObjectAttribute->attribute( 'id' );
            $contentObjectAttributeVersion = $contentObjectAttribute->attribute( 'version' );

            $db = eZDB::instance();
            $db->begin();

            // Delete stored object attributes when initialize translated attribute.
            if ( $originalContentObjectAttributeID != $contentObjectAttributeID )
                $this->deleteStoredObjectAttribute( $contentObjectAttribute, $currentVersion );

            $newVersionEnumObject = eZEnumObjectValue::fetchAllElements( $originalContentObjectAttributeID, $currentVersion );

            for ( $i = 0; $i < count( $newVersionEnumObject ); ++$i )
            {
                $enumobjectvalue =  $newVersionEnumObject[$i];
                $enumobjectvalue->setAttribute( 'contentobject_attribute_id', $contentObjectAttribute->attribute( 'id' ) );
                $enumobjectvalue->setAttribute( 'contentobject_attribute_version',  $contentObjectAttributeVersion );
                $enumobjectvalue->store();
            }

            $db->commit();
        }
    }
866518
protected boolean beginTransaction(SQLiteDatabase db) {
		boolean endTransaction = false;
		if (!db.inTransaction()) {
			db.beginTransaction();
			endTransaction = true;
			LOGGER.trace("Begin transaction");
		}
		return endTransaction;
	}
1076731
function _close()
	{
		if (!$this->_connectionID) {
			return;
		}


		if (!$this->autoCommit) {
			oci_rollback($this->_connectionID);
		}
		if (count($this->_refLOBs) > 0) {
			foreach ($this ->_refLOBs as $key => $value) {
				$this->_refLOBs[$key]['LOB']->free();
				unset($this->_refLOBs[$key]);
			}
		}
		oci_close($this->_connectionID);

		$this->_stmt = false;
		$this->_connectionID = false;
	}
1225742
function begin() {
		$this->dbh or $this->setup();

		if ($this->savepoint == 0) {
			$this->dbh->beginTransaction();
		}
		else { // already in a transaction
			$this->dbh->exec('SAVEPOINT save'.$this->savepoint);
		}

		$this->savepoint++;
		return $this;
	}
1205980
static function begin($name = NULL, $mode = NULL)
	{
		$object = static::_instance($name);
		$name = static::instanceName($name);

		if (static::$transactions[$name]) return FALSE;
		static::$transactions[$name] = $object->begin($mode);

		return static::$transactions[$name];
	}
783165
public function beginTransaction()
    {
        if (self::$transaction) {
            throw new TransactionException("Transaction Already Started");
        }

        self::$transaction = true;
        foreach (self::$connectionList as $dbDriver) {
            $dbDriver->beginTransaction();
        }
    }
78099
protected function commit_transaction() {
        if (!$this->transactions_supported()) {
            return;
        }

        $sql = "COMMIT";
        $this->query_start($sql, NULL, SQL_QUERY_AUX);
        $result = $this->mysqli->query($sql);
        $this->query_end($result);
    }
1156777
public function commitTransaction() {
        // check that a transaction is really active - do not check/renew the connection - renewing a connection breaks the transaction
        if (!$this->getConnection(false)->inTransaction())
            throw new \Exception("Not inside a DB transaction. Cannot commit.");

        try {
            $this->getConnection(false)->commit();
        } catch (Exception $_e) {
            throw new \Exception("Error while committing DB transaction: ".$pe->getMessage());
        }
    }
221125
private function rollback()
    {
        // We only need to rollback if we are in a transaction. Otherwise the resulting
        // error would hide the real problem why rollback was called. We might not be
        // in a transaction when not using the transactional locking behavior or when
        // two callbacks (e.g. destroy and write) are invoked that both fail.
        if ($this->inTransaction) {
            if ('sqlite' === $this->driver) {
                $this->pdo->exec('ROLLBACK');
            } else {
                $this->pdo->rollBack();
            }
            $this->inTransaction = false;
        }
    }