idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
3,200
private function getDatabasePlatformVersion ( ) { if ( ! $ this -> _driver instanceof VersionAwarePlatformDriver ) { return null ; } if ( isset ( $ this -> params [ 'serverVersion' ] ) ) { return $ this -> params [ 'serverVersion' ] ; } if ( $ this -> _conn === null ) { try { $ this -> connect ( ) ; } catch ( Throwable $ originalException ) { if ( empty ( $ this -> params [ 'dbname' ] ) ) { throw $ originalException ; } $ databaseName = $ this -> params [ 'dbname' ] ; $ this -> params [ 'dbname' ] = null ; try { $ this -> connect ( ) ; } catch ( Throwable $ fallbackException ) { $ this -> params [ 'dbname' ] = $ databaseName ; throw $ originalException ; } $ this -> params [ 'dbname' ] = $ databaseName ; $ serverVersion = $ this -> getServerVersion ( ) ; $ this -> close ( ) ; return $ serverVersion ; } } return $ this -> getServerVersion ( ) ; }
Returns the version of the related platform if applicable .
3,201
private function getServerVersion ( ) { $ connection = $ this -> getWrappedConnection ( ) ; if ( $ connection instanceof ServerInfoAwareConnection && ! $ connection -> requiresQueryForServerVersion ( ) ) { return $ connection -> getServerVersion ( ) ; } return null ; }
Returns the database server version if the underlying driver supports it .
3,202
public function setAutoCommit ( $ autoCommit ) { $ autoCommit = ( bool ) $ autoCommit ; if ( $ autoCommit === $ this -> autoCommit ) { return ; } $ this -> autoCommit = $ autoCommit ; if ( $ this -> isConnected !== true || $ this -> transactionNestingLevel === 0 ) { return ; } $ this -> commitAll ( ) ; }
Sets auto - commit mode for this connection .
3,203
public function fetchAssoc ( $ statement , array $ params = [ ] , array $ types = [ ] ) { return $ this -> executeQuery ( $ statement , $ params , $ types ) -> fetch ( FetchMode :: ASSOCIATIVE ) ; }
Prepares and executes an SQL query and returns the first row of the result as an associative array .
3,204
public function fetchArray ( $ statement , array $ params = [ ] , array $ types = [ ] ) { return $ this -> executeQuery ( $ statement , $ params , $ types ) -> fetch ( FetchMode :: NUMERIC ) ; }
Prepares and executes an SQL query and returns the first row of the result as a numerically indexed array .
3,205
private function addIdentifierCondition ( array $ identifier , array & $ columns , array & $ values , array & $ conditions ) : void { $ platform = $ this -> getDatabasePlatform ( ) ; foreach ( $ identifier as $ columnName => $ value ) { if ( $ value === null ) { $ conditions [ ] = $ platform -> getIsNullExpression ( $ columnName ) ; continue ; } $ columns [ ] = $ columnName ; $ values [ ] = $ value ; $ conditions [ ] = $ columnName . ' = ?' ; } }
Adds identifier condition to the query components
3,206
public function delete ( $ tableExpression , array $ identifier , array $ types = [ ] ) { if ( empty ( $ identifier ) ) { throw InvalidArgumentException :: fromEmptyCriteria ( ) ; } $ columns = $ values = $ conditions = [ ] ; $ this -> addIdentifierCondition ( $ identifier , $ columns , $ values , $ conditions ) ; return $ this -> executeUpdate ( 'DELETE FROM ' . $ tableExpression . ' WHERE ' . implode ( ' AND ' , $ conditions ) , $ values , is_string ( key ( $ types ) ) ? $ this -> extractTypeValues ( $ columns , $ types ) : $ types ) ; }
Executes an SQL DELETE statement on a table .
3,207
public function setTransactionIsolation ( $ level ) { $ this -> transactionIsolationLevel = $ level ; return $ this -> executeUpdate ( $ this -> getDatabasePlatform ( ) -> getSetTransactionIsolationSQL ( $ level ) ) ; }
Sets the transaction isolation level .
3,208
public function getTransactionIsolation ( ) { if ( $ this -> transactionIsolationLevel === null ) { $ this -> transactionIsolationLevel = $ this -> getDatabasePlatform ( ) -> getDefaultTransactionIsolationLevel ( ) ; } return $ this -> transactionIsolationLevel ; }
Gets the currently active transaction isolation level .
3,209
public function update ( $ tableExpression , array $ data , array $ identifier , array $ types = [ ] ) { $ columns = $ values = $ conditions = $ set = [ ] ; foreach ( $ data as $ columnName => $ value ) { $ columns [ ] = $ columnName ; $ values [ ] = $ value ; $ set [ ] = $ columnName . ' = ?' ; } $ this -> addIdentifierCondition ( $ identifier , $ columns , $ values , $ conditions ) ; if ( is_string ( key ( $ types ) ) ) { $ types = $ this -> extractTypeValues ( $ columns , $ types ) ; } $ sql = 'UPDATE ' . $ tableExpression . ' SET ' . implode ( ', ' , $ set ) . ' WHERE ' . implode ( ' AND ' , $ conditions ) ; return $ this -> executeUpdate ( $ sql , $ values , $ types ) ; }
Executes an SQL UPDATE statement on a table .
3,210
private function extractTypeValues ( array $ columnList , array $ types ) { $ typeValues = [ ] ; foreach ( $ columnList as $ columnIndex => $ columnName ) { $ typeValues [ ] = $ types [ $ columnName ] ?? ParameterType :: STRING ; } return $ typeValues ; }
Extract ordered type list from an ordered column list and type map .
3,211
public function fetchAll ( $ sql , array $ params = [ ] , $ types = [ ] ) { return $ this -> executeQuery ( $ sql , $ params , $ types ) -> fetchAll ( ) ; }
Prepares and executes an SQL query and returns the result as an associative array .
3,212
public function executeQuery ( $ query , array $ params = [ ] , $ types = [ ] , ? QueryCacheProfile $ qcp = null ) { if ( $ qcp !== null ) { return $ this -> executeCacheQuery ( $ query , $ params , $ types , $ qcp ) ; } $ connection = $ this -> getWrappedConnection ( ) ; $ logger = $ this -> _config -> getSQLLogger ( ) ; if ( $ logger ) { $ logger -> startQuery ( $ query , $ params , $ types ) ; } try { if ( $ params ) { [ $ query , $ params , $ types ] = SQLParserUtils :: expandListParameters ( $ query , $ params , $ types ) ; $ stmt = $ connection -> prepare ( $ query ) ; if ( $ types ) { $ this -> _bindTypedValues ( $ stmt , $ params , $ types ) ; $ stmt -> execute ( ) ; } else { $ stmt -> execute ( $ params ) ; } } else { $ stmt = $ connection -> query ( $ query ) ; } } catch ( Throwable $ ex ) { throw DBALException :: driverExceptionDuringQuery ( $ this -> _driver , $ ex , $ query , $ this -> resolveParams ( $ params , $ types ) ) ; } $ stmt -> setFetchMode ( $ this -> defaultFetchMode ) ; if ( $ logger ) { $ logger -> stopQuery ( ) ; } return $ stmt ; }
Executes an optionally parametrized SQL query .
3,213
public function executeCacheQuery ( $ query , $ params , $ types , QueryCacheProfile $ qcp ) { $ resultCache = $ qcp -> getResultCacheDriver ( ) ?? $ this -> _config -> getResultCacheImpl ( ) ; if ( $ resultCache === null ) { throw CacheException :: noResultDriverConfigured ( ) ; } $ connectionParams = $ this -> getParams ( ) ; unset ( $ connectionParams [ 'platform' ] ) ; [ $ cacheKey , $ realKey ] = $ qcp -> generateCacheKeys ( $ query , $ params , $ types , $ connectionParams ) ; $ data = $ resultCache -> fetch ( $ cacheKey ) ; if ( $ data !== false ) { if ( isset ( $ data [ $ realKey ] ) ) { $ stmt = new ArrayStatement ( $ data [ $ realKey ] ) ; } elseif ( array_key_exists ( $ realKey , $ data ) ) { $ stmt = new ArrayStatement ( [ ] ) ; } } if ( ! isset ( $ stmt ) ) { $ stmt = new ResultCacheStatement ( $ this -> executeQuery ( $ query , $ params , $ types ) , $ resultCache , $ cacheKey , $ realKey , $ qcp -> getLifetime ( ) ) ; } $ stmt -> setFetchMode ( $ this -> defaultFetchMode ) ; return $ stmt ; }
Executes a caching query .
3,214
public function exec ( $ statement ) { $ connection = $ this -> getWrappedConnection ( ) ; $ logger = $ this -> _config -> getSQLLogger ( ) ; if ( $ logger ) { $ logger -> startQuery ( $ statement ) ; } try { $ result = $ connection -> exec ( $ statement ) ; } catch ( Throwable $ ex ) { throw DBALException :: driverExceptionDuringQuery ( $ this -> _driver , $ ex , $ statement ) ; } if ( $ logger ) { $ logger -> stopQuery ( ) ; } return $ result ; }
Executes an SQL statement and return the number of affected rows .
3,215
public function setNestTransactionsWithSavepoints ( $ nestTransactionsWithSavepoints ) { if ( $ this -> transactionNestingLevel > 0 ) { throw ConnectionException :: mayNotAlterNestedTransactionWithSavepointsInTransaction ( ) ; } if ( ! $ this -> getDatabasePlatform ( ) -> supportsSavepoints ( ) ) { throw ConnectionException :: savepointsNotSupported ( ) ; } $ this -> nestTransactionsWithSavepoints = ( bool ) $ nestTransactionsWithSavepoints ; }
Sets if nested transactions should use savepoints .
3,216
private function commitAll ( ) { while ( $ this -> transactionNestingLevel !== 0 ) { if ( $ this -> autoCommit === false && $ this -> transactionNestingLevel === 1 ) { $ this -> commit ( ) ; return ; } $ this -> commit ( ) ; } }
Commits all current nesting transactions .
3,217
public function rollBack ( ) { if ( $ this -> transactionNestingLevel === 0 ) { throw ConnectionException :: noActiveTransaction ( ) ; } $ connection = $ this -> getWrappedConnection ( ) ; $ logger = $ this -> _config -> getSQLLogger ( ) ; if ( $ this -> transactionNestingLevel === 1 ) { if ( $ logger ) { $ logger -> startQuery ( '"ROLLBACK"' ) ; } $ this -> transactionNestingLevel = 0 ; $ connection -> rollBack ( ) ; $ this -> isRollbackOnly = false ; if ( $ logger ) { $ logger -> stopQuery ( ) ; } if ( $ this -> autoCommit === false ) { $ this -> beginTransaction ( ) ; } } elseif ( $ this -> nestTransactionsWithSavepoints ) { if ( $ logger ) { $ logger -> startQuery ( '"ROLLBACK TO SAVEPOINT"' ) ; } $ this -> rollbackSavepoint ( $ this -> _getNestedTransactionSavePointName ( ) ) ; -- $ this -> transactionNestingLevel ; if ( $ logger ) { $ logger -> stopQuery ( ) ; } } else { $ this -> isRollbackOnly = true ; -- $ this -> transactionNestingLevel ; } }
Cancels any database changes done during the current transaction .
3,218
public function createSavepoint ( $ savepoint ) { if ( ! $ this -> getDatabasePlatform ( ) -> supportsSavepoints ( ) ) { throw ConnectionException :: savepointsNotSupported ( ) ; } $ this -> getWrappedConnection ( ) -> exec ( $ this -> platform -> createSavePoint ( $ savepoint ) ) ; }
Creates a new savepoint .
3,219
public function releaseSavepoint ( $ savepoint ) { if ( ! $ this -> getDatabasePlatform ( ) -> supportsSavepoints ( ) ) { throw ConnectionException :: savepointsNotSupported ( ) ; } if ( ! $ this -> platform -> supportsReleaseSavepoints ( ) ) { return ; } $ this -> getWrappedConnection ( ) -> exec ( $ this -> platform -> releaseSavePoint ( $ savepoint ) ) ; }
Releases the given savepoint .
3,220
public function rollbackSavepoint ( $ savepoint ) { if ( ! $ this -> getDatabasePlatform ( ) -> supportsSavepoints ( ) ) { throw ConnectionException :: savepointsNotSupported ( ) ; } $ this -> getWrappedConnection ( ) -> exec ( $ this -> platform -> rollbackSavePoint ( $ savepoint ) ) ; }
Rolls back to the given savepoint .
3,221
public function getSchemaManager ( ) { if ( $ this -> _schemaManager === null ) { $ this -> _schemaManager = $ this -> _driver -> getSchemaManager ( $ this ) ; } return $ this -> _schemaManager ; }
Gets the SchemaManager that can be used to inspect or change the database schema through the connection .
3,222
public function convertToDatabaseValue ( $ value , $ type ) { return Type :: getType ( $ type ) -> convertToDatabaseValue ( $ value , $ this -> getDatabasePlatform ( ) ) ; }
Converts a given value to its database representation according to the conversion rules of a specific DBAL mapping type .
3,223
private function _bindTypedValues ( $ stmt , array $ params , array $ types ) { if ( is_int ( key ( $ params ) ) ) { $ typeOffset = array_key_exists ( 0 , $ types ) ? - 1 : 0 ; $ bindIndex = 1 ; foreach ( $ params as $ value ) { $ typeIndex = $ bindIndex + $ typeOffset ; if ( isset ( $ types [ $ typeIndex ] ) ) { $ type = $ types [ $ typeIndex ] ; [ $ value , $ bindingType ] = $ this -> getBindingInfo ( $ value , $ type ) ; $ stmt -> bindValue ( $ bindIndex , $ value , $ bindingType ) ; } else { $ stmt -> bindValue ( $ bindIndex , $ value ) ; } ++ $ bindIndex ; } } else { foreach ( $ params as $ name => $ value ) { if ( isset ( $ types [ $ name ] ) ) { $ type = $ types [ $ name ] ; [ $ value , $ bindingType ] = $ this -> getBindingInfo ( $ value , $ type ) ; $ stmt -> bindValue ( $ name , $ value , $ bindingType ) ; } else { $ stmt -> bindValue ( $ name , $ value ) ; } } } }
Binds a set of parameters some or all of which are typed with a PDO binding type or DBAL mapping type to a given statement .
3,224
private function getBindingInfo ( $ value , $ type ) { if ( is_string ( $ type ) ) { $ type = Type :: getType ( $ type ) ; } if ( $ type instanceof Type ) { $ value = $ type -> convertToDatabaseValue ( $ value , $ this -> getDatabasePlatform ( ) ) ; $ bindingType = $ type -> getBindingType ( ) ; } else { $ bindingType = $ type ; } return [ $ value , $ bindingType ] ; }
Gets the binding type of a given type . The given type can be a PDO or DBAL mapping type .
3,225
public function resolveParams ( array $ params , array $ types ) { $ resolvedParams = [ ] ; if ( is_int ( key ( $ params ) ) ) { $ typeOffset = array_key_exists ( 0 , $ types ) ? - 1 : 0 ; $ bindIndex = 1 ; foreach ( $ params as $ value ) { $ typeIndex = $ bindIndex + $ typeOffset ; if ( isset ( $ types [ $ typeIndex ] ) ) { $ type = $ types [ $ typeIndex ] ; [ $ value ] = $ this -> getBindingInfo ( $ value , $ type ) ; $ resolvedParams [ $ bindIndex ] = $ value ; } else { $ resolvedParams [ $ bindIndex ] = $ value ; } ++ $ bindIndex ; } } else { foreach ( $ params as $ name => $ value ) { if ( isset ( $ types [ $ name ] ) ) { $ type = $ types [ $ name ] ; [ $ value ] = $ this -> getBindingInfo ( $ value , $ type ) ; $ resolvedParams [ $ name ] = $ value ; } else { $ resolvedParams [ $ name ] = $ value ; } } } return $ resolvedParams ; }
Resolves the parameters to a format which can be displayed .
3,226
private function gatherAlterColumnSQL ( Identifier $ table , ColumnDiff $ columnDiff , array & $ sql , array & $ queryParts ) { $ alterColumnClauses = $ this -> getAlterColumnClausesSQL ( $ columnDiff ) ; if ( empty ( $ alterColumnClauses ) ) { return ; } if ( count ( $ alterColumnClauses ) === 1 ) { $ queryParts [ ] = current ( $ alterColumnClauses ) ; return ; } foreach ( $ alterColumnClauses as $ alterColumnClause ) { $ sql [ ] = 'ALTER TABLE ' . $ table -> getQuotedName ( $ this ) . ' ' . $ alterColumnClause ; } }
Gathers the table alteration SQL for a given column diff .
3,227
private function getAlterColumnClausesSQL ( ColumnDiff $ columnDiff ) { $ column = $ columnDiff -> column -> toArray ( ) ; $ alterClause = 'ALTER COLUMN ' . $ columnDiff -> column -> getQuotedName ( $ this ) ; if ( $ column [ 'columnDefinition' ] ) { return [ $ alterClause . ' ' . $ column [ 'columnDefinition' ] ] ; } $ clauses = [ ] ; if ( $ columnDiff -> hasChanged ( 'type' ) || $ columnDiff -> hasChanged ( 'length' ) || $ columnDiff -> hasChanged ( 'precision' ) || $ columnDiff -> hasChanged ( 'scale' ) || $ columnDiff -> hasChanged ( 'fixed' ) ) { $ clauses [ ] = $ alterClause . ' SET DATA TYPE ' . $ column [ 'type' ] -> getSQLDeclaration ( $ column , $ this ) ; } if ( $ columnDiff -> hasChanged ( 'notnull' ) ) { $ clauses [ ] = $ column [ 'notnull' ] ? $ alterClause . ' SET NOT NULL' : $ alterClause . ' DROP NOT NULL' ; } if ( $ columnDiff -> hasChanged ( 'default' ) ) { if ( isset ( $ column [ 'default' ] ) ) { $ defaultClause = $ this -> getDefaultValueDeclarationSQL ( $ column ) ; if ( $ defaultClause ) { $ clauses [ ] = $ alterClause . ' SET' . $ defaultClause ; } } else { $ clauses [ ] = $ alterClause . ' DROP DEFAULT' ; } } return $ clauses ; }
Returns the ALTER COLUMN SQL clauses for altering a column described by the given column diff .
3,228
public function add ( $ part ) { if ( empty ( $ part ) ) { return $ this ; } if ( $ part instanceof self && count ( $ part ) === 0 ) { return $ this ; } $ this -> parts [ ] = $ part ; return $ this ; }
Adds an expression to composite expression .
3,229
private function initializeAllDoctrineTypeMappings ( ) { $ this -> initializeDoctrineTypeMappings ( ) ; foreach ( Type :: getTypesMap ( ) as $ typeName => $ className ) { foreach ( Type :: getType ( $ typeName ) -> getMappedDatabaseTypes ( $ this ) as $ dbType ) { $ this -> doctrineTypeMapping [ $ dbType ] = $ typeName ; } } }
Initializes Doctrine Type Mappings with the platform defaults and with all additional type mappings .
3,230
public function registerDoctrineTypeMapping ( $ dbType , $ doctrineType ) { if ( $ this -> doctrineTypeMapping === null ) { $ this -> initializeAllDoctrineTypeMappings ( ) ; } if ( ! Types \ Type :: hasType ( $ doctrineType ) ) { throw DBALException :: typeNotFound ( $ doctrineType ) ; } $ dbType = strtolower ( $ dbType ) ; $ this -> doctrineTypeMapping [ $ dbType ] = $ doctrineType ; $ doctrineType = Type :: getType ( $ doctrineType ) ; if ( ! $ doctrineType -> requiresSQLCommentHint ( $ this ) ) { return ; } $ this -> markDoctrineTypeCommented ( $ doctrineType ) ; }
Registers a doctrine type to be used in conjunction with a column type of this platform .
3,231
public function getDoctrineTypeMapping ( $ dbType ) { if ( $ this -> doctrineTypeMapping === null ) { $ this -> initializeAllDoctrineTypeMappings ( ) ; } $ dbType = strtolower ( $ dbType ) ; if ( ! isset ( $ this -> doctrineTypeMapping [ $ dbType ] ) ) { throw new DBALException ( 'Unknown database type ' . $ dbType . ' requested, ' . static :: class . ' may not support it.' ) ; } return $ this -> doctrineTypeMapping [ $ dbType ] ; }
Gets the Doctrine type that is mapped for the given database column type .
3,232
public function hasDoctrineTypeMappingFor ( $ dbType ) { if ( $ this -> doctrineTypeMapping === null ) { $ this -> initializeAllDoctrineTypeMappings ( ) ; } $ dbType = strtolower ( $ dbType ) ; return isset ( $ this -> doctrineTypeMapping [ $ dbType ] ) ; }
Checks if a database type is currently supported by this platform .
3,233
public function isCommentedDoctrineType ( Type $ doctrineType ) { if ( $ this -> doctrineTypeComments === null ) { $ this -> initializeCommentedDoctrineTypes ( ) ; } assert ( is_array ( $ this -> doctrineTypeComments ) ) ; return in_array ( $ doctrineType -> getName ( ) , $ this -> doctrineTypeComments ) ; }
Is it necessary for the platform to add a parsable type comment to allow reverse engineering the given type?
3,234
public function markDoctrineTypeCommented ( $ doctrineType ) { if ( $ this -> doctrineTypeComments === null ) { $ this -> initializeCommentedDoctrineTypes ( ) ; } assert ( is_array ( $ this -> doctrineTypeComments ) ) ; $ this -> doctrineTypeComments [ ] = $ doctrineType instanceof Type ? $ doctrineType -> getName ( ) : $ doctrineType ; }
Marks this type as to be commented in ALTER TABLE and CREATE TABLE statements .
3,235
public function getTrimExpression ( $ str , $ mode = TrimMode :: UNSPECIFIED , $ char = false ) { $ expression = '' ; switch ( $ mode ) { case TrimMode :: LEADING : $ expression = 'LEADING ' ; break ; case TrimMode :: TRAILING : $ expression = 'TRAILING ' ; break ; case TrimMode :: BOTH : $ expression = 'BOTH ' ; break ; } if ( $ char !== false ) { $ expression .= $ char . ' ' ; } if ( $ mode || $ char !== false ) { $ expression .= 'FROM ' ; } return 'TRIM(' . $ expression . $ str . ')' ; }
Returns the SQL snippet to trim a string .
3,236
public function getDropTableSQL ( $ table ) { $ tableArg = $ table ; if ( $ table instanceof Table ) { $ table = $ table -> getQuotedName ( $ this ) ; } if ( ! is_string ( $ table ) ) { throw new InvalidArgumentException ( 'getDropTableSQL() expects $table parameter to be string or \Doctrine\DBAL\Schema\Table.' ) ; } if ( $ this -> _eventManager !== null && $ this -> _eventManager -> hasListeners ( Events :: onSchemaDropTable ) ) { $ eventArgs = new SchemaDropTableEventArgs ( $ tableArg , $ this ) ; $ this -> _eventManager -> dispatchEvent ( Events :: onSchemaDropTable , $ eventArgs ) ; if ( $ eventArgs -> isDefaultPrevented ( ) ) { $ sql = $ eventArgs -> getSql ( ) ; if ( $ sql === null ) { throw new UnexpectedValueException ( 'Default implementation of DROP TABLE was overridden with NULL' ) ; } return $ sql ; } } return 'DROP TABLE ' . $ table ; }
Returns the SQL snippet to drop an existing table .
3,237
public function getDropIndexSQL ( $ index , $ table = null ) { if ( $ index instanceof Index ) { $ index = $ index -> getQuotedName ( $ this ) ; } elseif ( ! is_string ( $ index ) ) { throw new InvalidArgumentException ( 'AbstractPlatform::getDropIndexSQL() expects $index parameter to be string or \Doctrine\DBAL\Schema\Index.' ) ; } return 'DROP INDEX ' . $ index ; }
Returns the SQL to drop an index from a table .
3,238
public function getDropConstraintSQL ( $ constraint , $ table ) { if ( ! $ constraint instanceof Constraint ) { $ constraint = new Identifier ( $ constraint ) ; } if ( ! $ table instanceof Table ) { $ table = new Identifier ( $ table ) ; } $ constraint = $ constraint -> getQuotedName ( $ this ) ; $ table = $ table -> getQuotedName ( $ this ) ; return 'ALTER TABLE ' . $ table . ' DROP CONSTRAINT ' . $ constraint ; }
Returns the SQL to drop a constraint .
3,239
public function getDropForeignKeySQL ( $ foreignKey , $ table ) { if ( ! $ foreignKey instanceof ForeignKeyConstraint ) { $ foreignKey = new Identifier ( $ foreignKey ) ; } if ( ! $ table instanceof Table ) { $ table = new Identifier ( $ table ) ; } $ foreignKey = $ foreignKey -> getQuotedName ( $ this ) ; $ table = $ table -> getQuotedName ( $ this ) ; return 'ALTER TABLE ' . $ table . ' DROP FOREIGN KEY ' . $ foreignKey ; }
Returns the SQL to drop a foreign key .
3,240
public function getInlineColumnCommentSQL ( $ comment ) { if ( ! $ this -> supportsInlineColumnComments ( ) ) { throw DBALException :: notSupported ( __METHOD__ ) ; } return 'COMMENT ' . $ this -> quoteStringLiteral ( $ comment ) ; }
Returns the SQL to create inline comment on a column .
3,241
protected function _getCreateTableSQL ( $ tableName , array $ columns , array $ options = [ ] ) { $ columnListSql = $ this -> getColumnDeclarationListSQL ( $ columns ) ; if ( isset ( $ options [ 'uniqueConstraints' ] ) && ! empty ( $ options [ 'uniqueConstraints' ] ) ) { foreach ( $ options [ 'uniqueConstraints' ] as $ name => $ definition ) { $ columnListSql .= ', ' . $ this -> getUniqueConstraintDeclarationSQL ( $ name , $ definition ) ; } } if ( isset ( $ options [ 'primary' ] ) && ! empty ( $ options [ 'primary' ] ) ) { $ columnListSql .= ', PRIMARY KEY(' . implode ( ', ' , array_unique ( array_values ( $ options [ 'primary' ] ) ) ) . ')' ; } if ( isset ( $ options [ 'indexes' ] ) && ! empty ( $ options [ 'indexes' ] ) ) { foreach ( $ options [ 'indexes' ] as $ index => $ definition ) { $ columnListSql .= ', ' . $ this -> getIndexDeclarationSQL ( $ index , $ definition ) ; } } $ query = 'CREATE TABLE ' . $ tableName . ' (' . $ columnListSql ; $ check = $ this -> getCheckDeclarationSQL ( $ columns ) ; if ( ! empty ( $ check ) ) { $ query .= ', ' . $ check ; } $ query .= ')' ; $ sql [ ] = $ query ; if ( isset ( $ options [ 'foreignKeys' ] ) ) { foreach ( ( array ) $ options [ 'foreignKeys' ] as $ definition ) { $ sql [ ] = $ this -> getCreateForeignKeySQL ( $ definition , $ tableName ) ; } } return $ sql ; }
Returns the SQL used to create a table .
3,242
public function getCreateConstraintSQL ( Constraint $ constraint , $ table ) { if ( $ table instanceof Table ) { $ table = $ table -> getQuotedName ( $ this ) ; } $ query = 'ALTER TABLE ' . $ table . ' ADD CONSTRAINT ' . $ constraint -> getQuotedName ( $ this ) ; $ columnList = '(' . implode ( ', ' , $ constraint -> getQuotedColumns ( $ this ) ) . ')' ; $ referencesClause = '' ; if ( $ constraint instanceof Index ) { if ( $ constraint -> isPrimary ( ) ) { $ query .= ' PRIMARY KEY' ; } elseif ( $ constraint -> isUnique ( ) ) { $ query .= ' UNIQUE' ; } else { throw new InvalidArgumentException ( 'Can only create primary or unique constraints, no common indexes with getCreateConstraintSQL().' ) ; } } elseif ( $ constraint instanceof ForeignKeyConstraint ) { $ query .= ' FOREIGN KEY' ; $ referencesClause = ' REFERENCES ' . $ constraint -> getQuotedForeignTableName ( $ this ) . ' (' . implode ( ', ' , $ constraint -> getQuotedForeignColumns ( $ this ) ) . ')' ; } $ query .= ' ' . $ columnList . $ referencesClause ; return $ query ; }
Returns the SQL to create a constraint on a table on this platform .
3,243
public function getCreateIndexSQL ( Index $ index , $ table ) { if ( $ table instanceof Table ) { $ table = $ table -> getQuotedName ( $ this ) ; } $ name = $ index -> getQuotedName ( $ this ) ; $ columns = $ index -> getColumns ( ) ; if ( count ( $ columns ) === 0 ) { throw new InvalidArgumentException ( "Incomplete definition. 'columns' required." ) ; } if ( $ index -> isPrimary ( ) ) { return $ this -> getCreatePrimaryKeySQL ( $ index , $ table ) ; } $ query = 'CREATE ' . $ this -> getCreateIndexSQLFlags ( $ index ) . 'INDEX ' . $ name . ' ON ' . $ table ; $ query .= ' (' . $ this -> getIndexFieldDeclarationListSQL ( $ index ) . ')' . $ this -> getPartialIndexSQL ( $ index ) ; return $ query ; }
Returns the SQL to create an index on a table on this platform .
3,244
public function quoteIdentifier ( $ str ) { if ( strpos ( $ str , '.' ) !== false ) { $ parts = array_map ( [ $ this , 'quoteSingleIdentifier' ] , explode ( '.' , $ str ) ) ; return implode ( '.' , $ parts ) ; } return $ this -> quoteSingleIdentifier ( $ str ) ; }
Quotes a string so that it can be safely used as a table or column name even if it is a reserved word of the platform . This also detects identifier chains separated by dot and quotes them independently .
3,245
public function getCreateForeignKeySQL ( ForeignKeyConstraint $ foreignKey , $ table ) { if ( $ table instanceof Table ) { $ table = $ table -> getQuotedName ( $ this ) ; } return 'ALTER TABLE ' . $ table . ' ADD ' . $ this -> getForeignKeyDeclarationSQL ( $ foreignKey ) ; }
Returns the SQL to create a new foreign key .
3,246
protected function getRenameIndexSQL ( $ oldIndexName , Index $ index , $ tableName ) { return [ $ this -> getDropIndexSQL ( $ oldIndexName , $ tableName ) , $ this -> getCreateIndexSQL ( $ index , $ tableName ) , ] ; }
Returns the SQL for renaming an index on a table .
3,247
protected function _getAlterTableIndexForeignKeySQL ( TableDiff $ diff ) { return array_merge ( $ this -> getPreAlterTableIndexForeignKeySQL ( $ diff ) , $ this -> getPostAlterTableIndexForeignKeySQL ( $ diff ) ) ; }
Common code for alter table statement generation that updates the changed Index and Foreign Key definitions .
3,248
public function getColumnDeclarationListSQL ( array $ fields ) { $ queryFields = [ ] ; foreach ( $ fields as $ fieldName => $ field ) { $ queryFields [ ] = $ this -> getColumnDeclarationSQL ( $ fieldName , $ field ) ; } return implode ( ', ' , $ queryFields ) ; }
Gets declaration of a number of fields in bulk .
3,249
public function getColumnDeclarationSQL ( $ name , array $ field ) { if ( isset ( $ field [ 'columnDefinition' ] ) ) { $ columnDef = $ this -> getCustomTypeDeclarationSQL ( $ field ) ; } else { $ default = $ this -> getDefaultValueDeclarationSQL ( $ field ) ; $ charset = isset ( $ field [ 'charset' ] ) && $ field [ 'charset' ] ? ' ' . $ this -> getColumnCharsetDeclarationSQL ( $ field [ 'charset' ] ) : '' ; $ collation = isset ( $ field [ 'collation' ] ) && $ field [ 'collation' ] ? ' ' . $ this -> getColumnCollationDeclarationSQL ( $ field [ 'collation' ] ) : '' ; $ notnull = isset ( $ field [ 'notnull' ] ) && $ field [ 'notnull' ] ? ' NOT NULL' : '' ; $ unique = isset ( $ field [ 'unique' ] ) && $ field [ 'unique' ] ? ' ' . $ this -> getUniqueFieldDeclarationSQL ( ) : '' ; $ check = isset ( $ field [ 'check' ] ) && $ field [ 'check' ] ? ' ' . $ field [ 'check' ] : '' ; $ typeDecl = $ field [ 'type' ] -> getSQLDeclaration ( $ field , $ this ) ; $ columnDef = $ typeDecl . $ charset . $ default . $ notnull . $ unique . $ check . $ collation ; if ( $ this -> supportsInlineColumnComments ( ) && isset ( $ field [ 'comment' ] ) && $ field [ 'comment' ] !== '' ) { $ columnDef .= ' ' . $ this -> getInlineColumnCommentSQL ( $ field [ 'comment' ] ) ; } } return $ name . ' ' . $ columnDef ; }
Obtains DBMS specific SQL code portion needed to declare a generic type field to be used in statements like CREATE TABLE .
3,250
public function getDecimalTypeDeclarationSQL ( array $ columnDef ) { $ columnDef [ 'precision' ] = ! isset ( $ columnDef [ 'precision' ] ) || empty ( $ columnDef [ 'precision' ] ) ? 10 : $ columnDef [ 'precision' ] ; $ columnDef [ 'scale' ] = ! isset ( $ columnDef [ 'scale' ] ) || empty ( $ columnDef [ 'scale' ] ) ? 0 : $ columnDef [ 'scale' ] ; return 'NUMERIC(' . $ columnDef [ 'precision' ] . ', ' . $ columnDef [ 'scale' ] . ')' ; }
Returns the SQL snippet that declares a floating point column of arbitrary precision .
3,251
public function getDefaultValueDeclarationSQL ( $ field ) { if ( ! isset ( $ field [ 'default' ] ) ) { return empty ( $ field [ 'notnull' ] ) ? ' DEFAULT NULL' : '' ; } $ default = $ field [ 'default' ] ; if ( ! isset ( $ field [ 'type' ] ) ) { return " DEFAULT '" . $ default . "'" ; } $ type = $ field [ 'type' ] ; if ( $ type instanceof Types \ PhpIntegerMappingType ) { return ' DEFAULT ' . $ default ; } if ( $ type instanceof Types \ PhpDateTimeMappingType && $ default === $ this -> getCurrentTimestampSQL ( ) ) { return ' DEFAULT ' . $ this -> getCurrentTimestampSQL ( ) ; } if ( $ type instanceof Types \ TimeType && $ default === $ this -> getCurrentTimeSQL ( ) ) { return ' DEFAULT ' . $ this -> getCurrentTimeSQL ( ) ; } if ( $ type instanceof Types \ DateType && $ default === $ this -> getCurrentDateSQL ( ) ) { return ' DEFAULT ' . $ this -> getCurrentDateSQL ( ) ; } if ( $ type instanceof Types \ BooleanType ) { return " DEFAULT '" . $ this -> convertBooleans ( $ default ) . "'" ; } return ' DEFAULT ' . $ this -> quoteStringLiteral ( $ default ) ; }
Obtains DBMS specific SQL code portion needed to set a default value declaration to be used in statements like CREATE TABLE .
3,252
public function getCheckDeclarationSQL ( array $ definition ) { $ constraints = [ ] ; foreach ( $ definition as $ field => $ def ) { if ( is_string ( $ def ) ) { $ constraints [ ] = 'CHECK (' . $ def . ')' ; } else { if ( isset ( $ def [ 'min' ] ) ) { $ constraints [ ] = 'CHECK (' . $ field . ' >= ' . $ def [ 'min' ] . ')' ; } if ( isset ( $ def [ 'max' ] ) ) { $ constraints [ ] = 'CHECK (' . $ field . ' <= ' . $ def [ 'max' ] . ')' ; } } } return implode ( ', ' , $ constraints ) ; }
Obtains DBMS specific SQL code portion needed to set a CHECK constraint declaration to be used in statements like CREATE TABLE .
3,253
public function getUniqueConstraintDeclarationSQL ( $ name , Index $ index ) { $ columns = $ index -> getColumns ( ) ; $ name = new Identifier ( $ name ) ; if ( count ( $ columns ) === 0 ) { throw new InvalidArgumentException ( "Incomplete definition. 'columns' required." ) ; } return 'CONSTRAINT ' . $ name -> getQuotedName ( $ this ) . ' UNIQUE (' . $ this -> getIndexFieldDeclarationListSQL ( $ index ) . ')' . $ this -> getPartialIndexSQL ( $ index ) ; }
Obtains DBMS specific SQL code portion needed to set a unique constraint declaration to be used in statements like CREATE TABLE .
3,254
public function getIndexFieldDeclarationListSQL ( $ columnsOrIndex ) : string { if ( $ columnsOrIndex instanceof Index ) { return implode ( ', ' , $ columnsOrIndex -> getQuotedColumns ( $ this ) ) ; } if ( ! is_array ( $ columnsOrIndex ) ) { throw new InvalidArgumentException ( 'Fields argument should be an Index or array.' ) ; } $ ret = [ ] ; foreach ( $ columnsOrIndex as $ column => $ definition ) { if ( is_array ( $ definition ) ) { $ ret [ ] = $ column ; } else { $ ret [ ] = $ definition ; } } return implode ( ', ' , $ ret ) ; }
Obtains DBMS specific SQL code portion needed to set an index declaration to be used in statements like CREATE TABLE .
3,255
public function getForeignKeyDeclarationSQL ( ForeignKeyConstraint $ foreignKey ) { $ sql = $ this -> getForeignKeyBaseDeclarationSQL ( $ foreignKey ) ; $ sql .= $ this -> getAdvancedForeignKeyOptionsSQL ( $ foreignKey ) ; return $ sql ; }
Obtain DBMS specific SQL code portion needed to set the FOREIGN KEY constraint of a field declaration to be used in statements like CREATE TABLE .
3,256
public function getAdvancedForeignKeyOptionsSQL ( ForeignKeyConstraint $ foreignKey ) { $ query = '' ; if ( $ this -> supportsForeignKeyOnUpdate ( ) && $ foreignKey -> hasOption ( 'onUpdate' ) ) { $ query .= ' ON UPDATE ' . $ this -> getForeignKeyReferentialActionSQL ( $ foreignKey -> getOption ( 'onUpdate' ) ) ; } if ( $ foreignKey -> hasOption ( 'onDelete' ) ) { $ query .= ' ON DELETE ' . $ this -> getForeignKeyReferentialActionSQL ( $ foreignKey -> getOption ( 'onDelete' ) ) ; } return $ query ; }
Returns the FOREIGN KEY query section dealing with non - standard options as MATCH INITIALLY DEFERRED ON UPDATE ...
3,257
public function getForeignKeyBaseDeclarationSQL ( ForeignKeyConstraint $ foreignKey ) { $ sql = '' ; if ( strlen ( $ foreignKey -> getName ( ) ) ) { $ sql .= 'CONSTRAINT ' . $ foreignKey -> getQuotedName ( $ this ) . ' ' ; } $ sql .= 'FOREIGN KEY (' ; if ( count ( $ foreignKey -> getLocalColumns ( ) ) === 0 ) { throw new InvalidArgumentException ( "Incomplete definition. 'local' required." ) ; } if ( count ( $ foreignKey -> getForeignColumns ( ) ) === 0 ) { throw new InvalidArgumentException ( "Incomplete definition. 'foreign' required." ) ; } if ( strlen ( $ foreignKey -> getForeignTableName ( ) ) === 0 ) { throw new InvalidArgumentException ( "Incomplete definition. 'foreignTable' required." ) ; } return $ sql . implode ( ', ' , $ foreignKey -> getQuotedLocalColumns ( $ this ) ) . ') REFERENCES ' . $ foreignKey -> getQuotedForeignTableName ( $ this ) . ' (' . implode ( ', ' , $ foreignKey -> getQuotedForeignColumns ( $ this ) ) . ')' ; }
Obtains DBMS specific SQL code portion needed to set the FOREIGN KEY constraint of a field declaration to be used in statements like CREATE TABLE .
3,258
public function convertBooleans ( $ item ) { if ( is_array ( $ item ) ) { foreach ( $ item as $ k => $ value ) { if ( ! is_bool ( $ value ) ) { continue ; } $ item [ $ k ] = ( int ) $ value ; } } elseif ( is_bool ( $ item ) ) { $ item = ( int ) $ item ; } return $ item ; }
Some platforms need the boolean values to be converted .
3,259
final public function modifyLimitQuery ( $ query , $ limit , $ offset = null ) { if ( $ limit !== null ) { $ limit = ( int ) $ limit ; } $ offset = ( int ) $ offset ; if ( $ offset < 0 ) { throw new DBALException ( sprintf ( 'Offset must be a positive integer or zero, %d given' , $ offset ) ) ; } if ( $ offset > 0 && ! $ this -> supportsLimitOffset ( ) ) { throw new DBALException ( sprintf ( 'Platform %s does not support offset values in limit queries.' , $ this -> getName ( ) ) ) ; } return $ this -> doModifyLimitQuery ( $ query , $ limit , $ offset ) ; }
Adds an driver - specific LIMIT clause to the query .
3,260
protected function doModifyLimitQuery ( $ query , $ limit , $ offset ) { if ( $ limit !== null ) { $ query .= ' LIMIT ' . $ limit ; } if ( $ offset > 0 ) { $ query .= ' OFFSET ' . $ offset ; } return $ query ; }
Adds an platform - specific LIMIT clause to the query .
3,261
final public function getReservedKeywordsList ( ) { if ( $ this -> _keywords ) { return $ this -> _keywords ; } $ class = $ this -> getReservedKeywordsClass ( ) ; $ keywords = new $ class ( ) ; if ( ! $ keywords instanceof KeywordList ) { throw DBALException :: notSupported ( __METHOD__ ) ; } $ this -> _keywords = $ keywords ; return $ keywords ; }
Returns the keyword list instance of this platform .
3,262
public function quoteStringLiteral ( $ str ) { $ c = $ this -> getStringLiteralQuoteCharacter ( ) ; return $ c . str_replace ( $ c , $ c . $ c , $ str ) . $ c ; }
Quotes a literal string . This method is NOT meant to fix SQL injections! It is only meant to escape this platform s string literal quote character inside the given literal string .
3,263
final public function escapeStringForLike ( string $ inputString , string $ escapeChar ) : string { return preg_replace ( '~([' . preg_quote ( $ this -> getLikeWildcardCharacters ( ) . $ escapeChar , '~' ) . '])~u' , addcslashes ( $ escapeChar , '\\' ) . '$1' , $ inputString ) ; }
Escapes metacharacters in a string intended to be used with a LIKE operator .
3,264
public static function getConnection ( array $ params , ? Configuration $ config = null , ? EventManager $ eventManager = null ) : Connection { if ( ! $ config ) { $ config = new Configuration ( ) ; } if ( ! $ eventManager ) { $ eventManager = new EventManager ( ) ; } $ params = self :: parseDatabaseUrl ( $ params ) ; if ( isset ( $ params [ 'master' ] ) ) { $ params [ 'master' ] = self :: parseDatabaseUrl ( $ params [ 'master' ] ) ; } if ( isset ( $ params [ 'slaves' ] ) ) { foreach ( $ params [ 'slaves' ] as $ key => $ slaveParams ) { $ params [ 'slaves' ] [ $ key ] = self :: parseDatabaseUrl ( $ slaveParams ) ; } } if ( isset ( $ params [ 'global' ] ) ) { $ params [ 'global' ] = self :: parseDatabaseUrl ( $ params [ 'global' ] ) ; } if ( isset ( $ params [ 'shards' ] ) ) { foreach ( $ params [ 'shards' ] as $ key => $ shardParams ) { $ params [ 'shards' ] [ $ key ] = self :: parseDatabaseUrl ( $ shardParams ) ; } } if ( isset ( $ params [ 'pdo' ] ) && ! $ params [ 'pdo' ] instanceof PDO ) { throw DBALException :: invalidPdoInstance ( ) ; } if ( isset ( $ params [ 'pdo' ] ) ) { $ params [ 'pdo' ] -> setAttribute ( PDO :: ATTR_ERRMODE , PDO :: ERRMODE_EXCEPTION ) ; $ params [ 'driver' ] = 'pdo_' . $ params [ 'pdo' ] -> getAttribute ( PDO :: ATTR_DRIVER_NAME ) ; } else { self :: _checkParams ( $ params ) ; } $ className = $ params [ 'driverClass' ] ?? self :: $ _driverMap [ $ params [ 'driver' ] ] ; $ driver = new $ className ( ) ; $ wrapperClass = Connection :: class ; if ( isset ( $ params [ 'wrapperClass' ] ) ) { if ( ! is_subclass_of ( $ params [ 'wrapperClass' ] , $ wrapperClass ) ) { throw DBALException :: invalidWrapperClass ( $ params [ 'wrapperClass' ] ) ; } $ wrapperClass = $ params [ 'wrapperClass' ] ; } return new $ wrapperClass ( $ params , $ driver , $ config , $ eventManager ) ; }
Creates a connection object based on the specified parameters . This method returns a Doctrine \ DBAL \ Connection which wraps the underlying driver connection .
3,265
private static function _checkParams ( array $ params ) : void { if ( ! isset ( $ params [ 'driver' ] ) && ! isset ( $ params [ 'driverClass' ] ) ) { throw DBALException :: driverRequired ( ) ; } if ( isset ( $ params [ 'driver' ] ) && ! isset ( self :: $ _driverMap [ $ params [ 'driver' ] ] ) ) { throw DBALException :: unknownDriver ( $ params [ 'driver' ] , array_keys ( self :: $ _driverMap ) ) ; } if ( isset ( $ params [ 'driverClass' ] ) && ! in_array ( Driver :: class , class_implements ( $ params [ 'driverClass' ] , true ) ) ) { throw DBALException :: invalidDriverClass ( $ params [ 'driverClass' ] ) ; } }
Checks the list of parameters .
3,266
private static function parseDatabaseUrl ( array $ params ) : array { if ( ! isset ( $ params [ 'url' ] ) ) { return $ params ; } $ url = preg_replace ( '#^((?:pdo_)?sqlite3?):///#' , '$1://localhost/' , $ params [ 'url' ] ) ; assert ( is_string ( $ url ) ) ; $ url = parse_url ( $ url ) ; if ( $ url === false ) { throw new DBALException ( 'Malformed parameter "url".' ) ; } $ url = array_map ( 'rawurldecode' , $ url ) ; unset ( $ params [ 'pdo' ] ) ; $ params = self :: parseDatabaseUrlScheme ( $ url , $ params ) ; if ( isset ( $ url [ 'host' ] ) ) { $ params [ 'host' ] = $ url [ 'host' ] ; } if ( isset ( $ url [ 'port' ] ) ) { $ params [ 'port' ] = $ url [ 'port' ] ; } if ( isset ( $ url [ 'user' ] ) ) { $ params [ 'user' ] = $ url [ 'user' ] ; } if ( isset ( $ url [ 'pass' ] ) ) { $ params [ 'password' ] = $ url [ 'pass' ] ; } $ params = self :: parseDatabaseUrlPath ( $ url , $ params ) ; $ params = self :: parseDatabaseUrlQuery ( $ url , $ params ) ; return $ params ; }
Extracts parts from a database URL if present and returns an updated list of parameters .
3,267
private static function parseDatabaseUrlPath ( array $ url , array $ params ) : array { if ( ! isset ( $ url [ 'path' ] ) ) { return $ params ; } $ url [ 'path' ] = self :: normalizeDatabaseUrlPath ( $ url [ 'path' ] ) ; if ( ! isset ( $ params [ 'driver' ] ) ) { return self :: parseRegularDatabaseUrlPath ( $ url , $ params ) ; } if ( strpos ( $ params [ 'driver' ] , 'sqlite' ) !== false ) { return self :: parseSqliteDatabaseUrlPath ( $ url , $ params ) ; } return self :: parseRegularDatabaseUrlPath ( $ url , $ params ) ; }
Parses the given connection URL and resolves the given connection parameters .
3,268
private static function parseDatabaseUrlQuery ( array $ url , array $ params ) : array { if ( ! isset ( $ url [ 'query' ] ) ) { return $ params ; } $ query = [ ] ; parse_str ( $ url [ 'query' ] , $ query ) ; return array_merge ( $ params , $ query ) ; }
Parses the query part of the given connection URL and resolves the given connection parameters .
3,269
private static function parseSqliteDatabaseUrlPath ( array $ url , array $ params ) : array { if ( $ url [ 'path' ] === ':memory:' ) { $ params [ 'memory' ] = true ; return $ params ; } $ params [ 'path' ] = $ url [ 'path' ] ; return $ params ; }
Parses the given SQLite connection URL and resolves the given connection parameters .
3,270
private static function parseDatabaseUrlScheme ( array $ url , array $ params ) : array { if ( isset ( $ url [ 'scheme' ] ) ) { unset ( $ params [ 'driverClass' ] ) ; $ driver = str_replace ( '-' , '_' , $ url [ 'scheme' ] ) ; assert ( is_string ( $ driver ) ) ; $ params [ 'driver' ] = self :: $ driverSchemeAliases [ $ driver ] ?? $ driver ; return $ params ; } if ( ! isset ( $ params [ 'driverClass' ] ) && ! isset ( $ params [ 'driver' ] ) ) { throw DBALException :: driverRequired ( $ params [ 'url' ] ) ; } return $ params ; }
Parses the scheme part from given connection URL and resolves the given connection parameters .
3,271
private function killUserSessions ( $ user ) { $ sql = <<<SQLSELECT s.sid, s.serial#FROM gv\$session s, gv\$process pWHERE s.username = ? AND p.addr(+) = s.paddrSQL ; $ activeUserSessions = $ this -> _conn -> fetchAll ( $ sql , [ strtoupper ( $ user ) ] ) ; foreach ( $ activeUserSessions as $ activeUserSession ) { $ activeUserSession = array_change_key_case ( $ activeUserSession , CASE_LOWER ) ; $ this -> _execSql ( sprintf ( "ALTER SYSTEM KILL SESSION '%s, %s' IMMEDIATE" , $ activeUserSession [ 'sid' ] , $ activeUserSession [ 'serial#' ] ) ) ; } }
Kills sessions connected with the given user .
3,272
private function _constructPdoDsn ( array $ params ) { $ dsn = 'ibm:' ; if ( isset ( $ params [ 'host' ] ) ) { $ dsn .= 'HOSTNAME=' . $ params [ 'host' ] . ';' ; } if ( isset ( $ params [ 'port' ] ) ) { $ dsn .= 'PORT=' . $ params [ 'port' ] . ';' ; } $ dsn .= 'PROTOCOL=TCPIP;' ; if ( isset ( $ params [ 'dbname' ] ) ) { $ dsn .= 'DATABASE=' . $ params [ 'dbname' ] . ';' ; } return $ dsn ; }
Constructs the IBM PDO DSN .
3,273
public function getQueries ( ) { return array_merge ( $ this -> createNamespaceQueries , $ this -> createTableQueries , $ this -> createSequenceQueries , $ this -> createFkConstraintQueries ) ; }
Gets all queries collected so far .
3,274
public static function fromSqlSrvErrors ( ) { $ message = '' ; $ sqlState = null ; $ errorCode = null ; foreach ( ( array ) sqlsrv_errors ( SQLSRV_ERR_ERRORS ) as $ error ) { $ message .= 'SQLSTATE [' . $ error [ 'SQLSTATE' ] . ', ' . $ error [ 'code' ] . ']: ' . $ error [ 'message' ] . "\n" ; if ( $ sqlState === null ) { $ sqlState = $ error [ 'SQLSTATE' ] ; } if ( $ errorCode !== null ) { continue ; } $ errorCode = $ error [ 'code' ] ; } if ( ! $ message ) { $ message = 'SQL Server error occurred but no error message was retrieved from driver.' ; } return new self ( rtrim ( $ message ) , $ sqlState , $ errorCode ) ; }
Helper method to turn sql server errors into exception .
3,275
private function getRemainingForeignKeyConstraintsRequiringRenamedIndexes ( TableDiff $ diff ) { if ( empty ( $ diff -> renamedIndexes ) || ! $ diff -> fromTable instanceof Table ) { return [ ] ; } $ foreignKeys = [ ] ; $ remainingForeignKeys = array_diff_key ( $ diff -> fromTable -> getForeignKeys ( ) , $ diff -> removedForeignKeys ) ; foreach ( $ remainingForeignKeys as $ foreignKey ) { foreach ( $ diff -> renamedIndexes as $ index ) { if ( $ foreignKey -> intersectsIndexColumns ( $ index ) ) { $ foreignKeys [ ] = $ foreignKey ; break ; } } } return $ foreignKeys ; }
Returns the remaining foreign key constraints that require one of the renamed indexes .
3,276
private function prepare ( ) { $ params = [ ] ; foreach ( $ this -> variables as $ column => & $ variable ) { switch ( $ this -> types [ $ column ] ) { case ParameterType :: LARGE_OBJECT : $ params [ $ column - 1 ] = [ & $ variable , SQLSRV_PARAM_IN , SQLSRV_PHPTYPE_STREAM ( SQLSRV_ENC_BINARY ) , SQLSRV_SQLTYPE_VARBINARY ( 'max' ) , ] ; break ; case ParameterType :: BINARY : $ params [ $ column - 1 ] = [ & $ variable , SQLSRV_PARAM_IN , SQLSRV_PHPTYPE_STRING ( SQLSRV_ENC_BINARY ) , ] ; break ; default : $ params [ $ column - 1 ] = & $ variable ; break ; } } $ stmt = sqlsrv_prepare ( $ this -> conn , $ this -> sql , $ params ) ; if ( ! $ stmt ) { throw SQLSrvException :: fromSqlSrvErrors ( ) ; } return $ stmt ; }
Prepares SQL Server statement resource
3,277
public static function conversionFailed ( $ value , $ toType ) { $ value = strlen ( $ value ) > 32 ? substr ( $ value , 0 , 20 ) . '...' : $ value ; return new self ( 'Could not convert database value "' . $ value . '" to Doctrine Type ' . $ toType ) ; }
Thrown when a Database to Doctrine Type Conversion fails .
3,278
public static function conversionFailedFormat ( $ value , $ toType , $ expectedFormat , ? Throwable $ previous = null ) { $ value = strlen ( $ value ) > 32 ? substr ( $ value , 0 , 20 ) . '...' : $ value ; return new self ( 'Could not convert database value "' . $ value . '" to Doctrine Type ' . $ toType . '. Expected format: ' . $ expectedFormat , 0 , $ previous ) ; }
Thrown when a Database to Doctrine Type Conversion fails and we can make a statement about the expected format .
3,279
public function setFilterSchemaAssetsExpression ( $ filterExpression ) { $ this -> _attributes [ 'filterSchemaAssetsExpression' ] = $ filterExpression ; if ( $ filterExpression ) { $ this -> _attributes [ 'filterSchemaAssetsExpressionCallable' ] = $ this -> buildSchemaAssetsFilterFromExpression ( $ filterExpression ) ; } else { $ this -> _attributes [ 'filterSchemaAssetsExpressionCallable' ] = null ; } }
Sets the filter schema assets expression .
3,280
public function spansColumns ( array $ columnNames ) { $ columns = $ this -> getColumns ( ) ; $ numberOfColumns = count ( $ columns ) ; $ sameColumns = true ; for ( $ i = 0 ; $ i < $ numberOfColumns ; $ i ++ ) { if ( isset ( $ columnNames [ $ i ] ) && $ this -> trimQuotes ( strtolower ( $ columns [ $ i ] ) ) === $ this -> trimQuotes ( strtolower ( $ columnNames [ $ i ] ) ) ) { continue ; } $ sameColumns = false ; } return $ sameColumns ; }
Checks if this index exactly spans the given column names in the correct order .
3,281
public function isFullfilledBy ( Index $ other ) { if ( count ( $ other -> getColumns ( ) ) !== count ( $ this -> getColumns ( ) ) ) { return false ; } $ sameColumns = $ this -> spansColumns ( $ other -> getColumns ( ) ) ; if ( $ sameColumns ) { if ( ! $ this -> samePartialIndex ( $ other ) ) { return false ; } if ( ! $ this -> hasSameColumnLengths ( $ other ) ) { return false ; } if ( ! $ this -> isUnique ( ) && ! $ this -> isPrimary ( ) ) { return true ; } if ( $ other -> isPrimary ( ) !== $ this -> isPrimary ( ) ) { return false ; } return $ other -> isUnique ( ) === $ this -> isUnique ( ) ; } return false ; }
Checks if the other index already fulfills all the indexing and constraint needs of the current one .
3,282
public function overrules ( Index $ other ) { if ( $ other -> isPrimary ( ) ) { return false ; } if ( $ this -> isSimpleIndex ( ) && $ other -> isUnique ( ) ) { return false ; } return $ this -> spansColumns ( $ other -> getColumns ( ) ) && ( $ this -> isPrimary ( ) || $ this -> isUnique ( ) ) && $ this -> samePartialIndex ( $ other ) ; }
Detects if the other index is a non - unique non primary index that can be overwritten by this one .
3,283
private function samePartialIndex ( Index $ other ) { if ( $ this -> hasOption ( 'where' ) && $ other -> hasOption ( 'where' ) && $ this -> getOption ( 'where' ) === $ other -> getOption ( 'where' ) ) { return true ; } return ! $ this -> hasOption ( 'where' ) && ! $ other -> hasOption ( 'where' ) ; }
Return whether the two indexes have the same partial index
3,284
private function hasSameColumnLengths ( self $ other ) : bool { $ filter = static function ( ? int $ length ) : bool { return $ length !== null ; } ; return array_filter ( $ this -> options [ 'lengths' ] ?? [ ] , $ filter ) === array_filter ( $ other -> options [ 'lengths' ] ?? [ ] , $ filter ) ; }
Returns whether the index has the same column lengths as the other
3,285
private function getSequenceCacheSQL ( Sequence $ sequence ) { if ( $ sequence -> getCache ( ) === 0 ) { return ' NOCACHE' ; } if ( $ sequence -> getCache ( ) === 1 ) { return ' NOCACHE' ; } if ( $ sequence -> getCache ( ) > 1 ) { return ' CACHE ' . $ sequence -> getCache ( ) ; } return '' ; }
Cache definition for sequences
3,286
public function getDropAutoincrementSql ( $ table ) { $ table = $ this -> normalizeIdentifier ( $ table ) ; $ autoincrementIdentifierName = $ this -> getAutoincrementIdentifierName ( $ table ) ; $ identitySequenceName = $ this -> getIdentitySequenceName ( $ table -> isQuoted ( ) ? $ table -> getQuotedName ( $ this ) : $ table -> getName ( ) , '' ) ; return [ 'DROP TRIGGER ' . $ autoincrementIdentifierName , $ this -> getDropSequenceSQL ( $ identitySequenceName ) , $ this -> getDropConstraintSQL ( $ autoincrementIdentifierName , $ table -> getQuotedName ( $ this ) ) , ] ; }
Returns the SQL statements to drop the autoincrement for the given table name .
3,287
private function normalizeIdentifier ( $ name ) { $ identifier = new Identifier ( $ name ) ; return $ identifier -> isQuoted ( ) ? $ identifier : new Identifier ( strtoupper ( $ name ) ) ; }
Normalizes the given identifier .
3,288
private function getAutoincrementIdentifierName ( Identifier $ table ) { $ identifierName = $ table -> getName ( ) . '_AI_PK' ; return $ table -> isQuoted ( ) ? $ this -> quoteSingleIdentifier ( $ identifierName ) : $ identifierName ; }
Returns the autoincrement primary key identifier name for the given table identifier .
3,289
public function setPrimaryKey ( array $ columnNames , $ indexName = false ) { $ this -> _addIndex ( $ this -> _createIndex ( $ columnNames , $ indexName ? : 'primary' , true , true ) ) ; foreach ( $ columnNames as $ columnName ) { $ column = $ this -> getColumn ( $ columnName ) ; $ column -> setNotnull ( true ) ; } return $ this ; }
Sets the Primary Key .
3,290
public function columnsAreIndexed ( array $ columnNames ) { foreach ( $ this -> getIndexes ( ) as $ index ) { if ( $ index -> spansColumns ( $ columnNames ) ) { return true ; } } return false ; }
Checks if an index begins in the order of the given columns .
3,291
public function changeColumn ( $ columnName , array $ options ) { $ column = $ this -> getColumn ( $ columnName ) ; $ column -> setOptions ( $ options ) ; return $ this ; }
Change Column Details .
3,292
public function dropColumn ( $ columnName ) { $ columnName = $ this -> normalizeIdentifier ( $ columnName ) ; unset ( $ this -> _columns [ $ columnName ] ) ; return $ this ; }
Drops a Column from the Table .
3,293
public function addNamedForeignKeyConstraint ( $ name , $ foreignTable , array $ localColumnNames , array $ foreignColumnNames , array $ options = [ ] ) { if ( $ foreignTable instanceof Table ) { foreach ( $ foreignColumnNames as $ columnName ) { if ( ! $ foreignTable -> hasColumn ( $ columnName ) ) { throw SchemaException :: columnDoesNotExist ( $ columnName , $ foreignTable -> getName ( ) ) ; } } } foreach ( $ localColumnNames as $ columnName ) { if ( ! $ this -> hasColumn ( $ columnName ) ) { throw SchemaException :: columnDoesNotExist ( $ columnName , $ this -> _name ) ; } } $ constraint = new ForeignKeyConstraint ( $ localColumnNames , $ foreignTable , $ foreignColumnNames , $ name , $ options ) ; $ this -> _addForeignKeyConstraint ( $ constraint ) ; return $ this ; }
Adds a foreign key constraint with a given name .
3,294
public function hasForeignKey ( $ constraintName ) { $ constraintName = $ this -> normalizeIdentifier ( $ constraintName ) ; return isset ( $ this -> _fkConstraints [ $ constraintName ] ) ; }
Returns whether this table has a foreign key constraint with the given name .
3,295
public function getForeignKey ( $ constraintName ) { $ constraintName = $ this -> normalizeIdentifier ( $ constraintName ) ; if ( ! $ this -> hasForeignKey ( $ constraintName ) ) { throw SchemaException :: foreignKeyDoesNotExist ( $ constraintName , $ this -> _name ) ; } return $ this -> _fkConstraints [ $ constraintName ] ; }
Returns the foreign key constraint with the given name .
3,296
private function getForeignKeyColumns ( ) { $ foreignKeyColumns = [ ] ; foreach ( $ this -> getForeignKeys ( ) as $ foreignKey ) { $ foreignKeyColumns = array_merge ( $ foreignKeyColumns , $ foreignKey -> getColumns ( ) ) ; } return $ this -> filterColumns ( $ foreignKeyColumns ) ; }
Returns foreign key columns
3,297
private function filterColumns ( array $ columnNames ) { return array_filter ( $ this -> _columns , static function ( $ columnName ) use ( $ columnNames ) { return in_array ( $ columnName , $ columnNames , true ) ; } , ARRAY_FILTER_USE_KEY ) ; }
Returns only columns that have specified names
3,298
public function hasColumn ( $ columnName ) { $ columnName = $ this -> normalizeIdentifier ( $ columnName ) ; return isset ( $ this -> _columns [ $ columnName ] ) ; }
Returns whether this table has a Column with the given name .
3,299
public function getColumn ( $ columnName ) { $ columnName = $ this -> normalizeIdentifier ( $ columnName ) ; if ( ! $ this -> hasColumn ( $ columnName ) ) { throw SchemaException :: columnDoesNotExist ( $ columnName , $ this -> _name ) ; } return $ this -> _columns [ $ columnName ] ; }
Returns the Column with the given name .