Create a sequence if not exists

@return null
769756
private static function _checkSequence()
    {
        if (Driver::$primary_key_behaviour!=Driver::PRIMARY_KEY_SEQUENCE) {
            return null;
        }

        if (self::_sequenceExists()) {
            return;
        }

        switch (Driver::$name) {
        case "oracle":
            self::_createOracleSequence();
            break;
        case "postgresql":
            self::_createPostgresqlSequence();
            break;
        }
    }
985460
public function buildRuntimeSequence(): Sequence
    {
        $sequence = $this->buildEssentialsSequence('runtime');
        $sequence->addStep(new Step('neos.flow:objectmanagement:proxyclasses', [Scripts::class, 'initializeProxyClasses']), 'neos.flow:systemlogger');
        $sequence->addStep(new Step('neos.flow:classloader:cache', [Scripts::class, 'initializeClassLoaderClassesCache']), 'neos.flow:objectmanagement:proxyclasses');
        $sequence->addStep(new Step('neos.flow:objectmanagement:runtime', [Scripts::class, 'initializeObjectManager']), 'neos.flow:classloader:cache');

        if (!$this->context->isProduction()) {
            $sequence->addStep(new Step('neos.flow:systemfilemonitor', [Scripts::class, 'initializeSystemFileMonitor']), 'neos.flow:objectmanagement:runtime');
            $sequence->addStep(new Step('neos.flow:objectmanagement:recompile', [Scripts::class, 'recompileClasses']), 'neos.flow:systemfilemonitor');
        }

        $sequence->addStep(new Step('neos.flow:reflectionservice:factory', [Scripts::class, 'initializeReflectionServiceFactory']), 'neos.flow:objectmanagement:runtime');
        $sequence->addStep(new Step('neos.flow:resources', [Scripts::class, 'initializeResources']), 'neos.flow:reflectionservice:factory');
        return $sequence;
    }
1057272
private function findAutoincrementSequence($tableName)
    {
        if (!$this->connection->getDatabasePlatform()->supportsSequences()) {
            return null;
        }

        $table = $this->findTableByName($tableName);
        $pkColumns = $table->getPrimaryKey()->getColumns();

        if (\count($pkColumns) !== 1) {
            return;
        }

        $tableSequenceName = \sprintf('%s_%s_seq', $table->getName(), $pkColumns[0]);
        $sequences = $this->getSchemaManager()->listSequences();
        foreach ($sequences as $sequence) {
            if ($tableSequenceName === $sequence->getName()) {
                return $sequence;
            }
        }
    }
1278460
public function toASN1(): Sequence
    {
        $elements = array_map(
            function (Attribute $attr) {
                return $attr->toASN1();
            }, array_values($this->_attributes));
        return new Sequence(...$elements);
    }
1254944
public function toASN1(): Sequence
    {
        return new Sequence($this->_tbsCertificate->toASN1(),
            $this->_signatureAlgorithm->toASN1(),
            $this->_signatureValue->bitString());
    }
516809
function iterateSequence()
    {
        if ( !$this->hasSequence() )
            return;

        $fName    = $this->Name;
        $uniqid   = $this->UniqID;
        $seqArray = "${fName}_sequence_array_$uniqid";
        $seqVar   = "${fName}_sequence_var_$uniqid";
        $alterSeqValCode =
            "if ( ( \$$seqVar = next( \$$seqArray ) ) === false )\n" .
            "{\n" .
            "   reset( \$$seqArray );\n" .
            "   \$$seqVar = current( \$$seqArray );\n" .
            "}\n";
        $this->NewNodes[] = eZTemplateNodeTool::createCodePieceNode( "// sequence iteration" );
        $this->NewNodes[] = eZTemplateNodeTool::createCodePieceNode( $alterSeqValCode );
    }
766529
public function isEmpty()
    {
        $returnValue = (bool) false;

        
        $returnValue = (count($this->sequence) == 0);
        

        return (bool) $returnValue;
    }
223367
public function create()
    {
        $this->sql = new PhiberQueryWriter("create", [
            "table"  => $this->table,
            "fields" => $this->fields,
            "values" => $this->fieldsValues
        ]);

        if ($this->phiberConfig->verifyExecuteQueries()) {
            $stmt = $this->PDO->prepare($this->sql);

            for ($i = 0; $i < count($this->fields); $i++) {
                if ($this->fieldsValues[$i] != null) {
                    $stmt->bindValue($this->fields[$i], $this->fieldsValues[$i]);
                }
            }
            if ($stmt->execute()) {
                return $this->PDO->lastInsertId();
            }
        }

        return false;
    }
1067046
function setSequenceGenerator(\Tecnocreaciones\Bundle\ToolsBundle\Service\SequenceGenerator $sequenceGenerator) {
        $this->sequenceGenerator = $sequenceGenerator;
    }
494484
function createRepeat() {
    $cnt = count( $this->repeat );
    if( 0 >= $cnt )
      return;
    $attributes = $this->_createParams( $this->repeat['params'] );
    return $this->_createElement( 'REPEAT', $attributes, $this->repeat['value'] );
  }
514531
public function toASN1(): Sequence
    {
        $elements = [];
        if (isset($this->_baseCertificateID)) {
            $elements[] = new ImplicitlyTaggedType(0,
                $this->_baseCertificateID->toASN1());
        }
        if (isset($this->_entityName)) {
            $elements[] = new ImplicitlyTaggedType(1,
                $this->_entityName->toASN1());
        }
        if (isset($this->_objectDigestInfo)) {
            $elements[] = new ImplicitlyTaggedType(2,
                $this->_objectDigestInfo->toASN1());
        }
        return new Sequence(...$elements);
    }
713156
function CreateSequence2008($seq='adodbseq',$start=1)
	{
		if($this->debug) ADOConnection::outp("<hr>CreateSequence($seq,$start)");
		sqlsrv_begin_transaction($this->_connectionID);
		$start -= 1;
		$this->Execute("create table $seq (id int)");//was float(53)
		$ok = $this->Execute("insert into $seq with (tablock,holdlock) values($start)");
		if (!$ok) {
			if($this->debug) ADOConnection::outp("<hr>Error: ROLLBACK");
			sqlsrv_rollback($this->_connectionID);
			return false;
		}
		sqlsrv_commit($this->_connectionID);
		return true;
	}
803998
private function createExist(): string
    {
        // 先构造子查询
        $this->createSelect();

        // 使用子查询构造存在查询
        $this->prepare = $this->db->createExist($this->prepare);
        $this->sql = $this->db->createExist($this->sql);

        $this->tables = [$this->table];
        return $this->prepare;
    }
881202
private function _lockSequence($sequence)
    {
        $result = $this->_connection->execute(
            "SELECT id FROM sequences WHERE name=? FOR UPDATE", $sequence);

        switch (count($result)) {
            case 0:
                // sequence not in table; insert and use startId value
                $this->_connection->execute(
                    "INSERT INTO sequences VALUES (?,?)",
                    $sequence, $this->_startId);
                $id = $this->_startId;
                break;

            case 1:
                // sequence already in table; remember its current ID
                $id = $result[0]['id'];
                break;

            default:
                // multiple rows for sequence; bad
                throw new \Pheasant\Exception("Multiple rows exist for sequence '$sequence'");
                break;
        }

        return $id;
    }
1355321
public function create($name, $start = 1, $nocache = false, $min = 1, $max = false, $increment = 1)
    {
        if (! $name) {
            return false;
        }

        if ($this->connection->getConfig('prefix_schema')) {
            $name = $this->connection->getConfig('prefix_schema') . '.' . $name;
        }

        $nocache = $nocache ? 'nocache' : '';

        $max = $max ? " maxvalue {$max}" : '';

        $sequence_stmt = "create sequence {$name} minvalue {$min} {$max} start with {$start} increment by {$increment} {$nocache}";

        return $this->connection->statement($sequence_stmt);
    }
1126644
public function autoIncrement($table, $column, $triggerName, $sequenceName)
    {
        if (! $table || ! $column || ! $triggerName || ! $sequenceName) {
            return false;
        }

        if ($this->connection->getConfig('prefix_schema')) {
            $table        = $this->connection->getConfig('prefix_schema') . '.' . $table;
            $triggerName  = $this->connection->getConfig('prefix_schema') . '.' . $triggerName;
            $sequenceName = $this->connection->getConfig('prefix_schema') . '.' . $sequenceName;
        }

        $table  = $this->wrapValue($table);
        $column = $this->wrapValue($column);

        return $this->connection->statement("
            create trigger $triggerName
            before insert on {$table}
            for each row
                begin
            if :new.{$column} is null then
                select {$sequenceName}.nextval into :new.{$column} from dual;
            end if;
            end;");
    }
598130
public function toASN1(): Sequence
    {
        $elements = array($this->_base->toASN1());
        if (isset($this->_min) && $this->_min != 0) {
            $elements[] = new ImplicitlyTaggedType(0, new Integer($this->_min));
        }
        if (isset($this->_max)) {
            $elements[] = new ImplicitlyTaggedType(1, new Integer($this->_max));
        }
        return new Sequence(...$elements);
    }