repo
stringlengths 6
63
| path
stringlengths 5
140
| func_name
stringlengths 3
151
| original_string
stringlengths 84
13k
| language
stringclasses 1
value | code
stringlengths 84
13k
| code_tokens
list | docstring
stringlengths 3
47.2k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 91
247
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
doctrine/dbal | lib/Doctrine/DBAL/Connection.php | Connection.getDatabasePlatformVersion | private function getDatabasePlatformVersion()
{
// Driver does not support version specific platforms.
if (! $this->_driver instanceof VersionAwarePlatformDriver) {
return null;
}
// Explicit platform version requested (supersedes auto-detection).
if (isset($this->params['serverVersion'])) {
return $this->params['serverVersion'];
}
// If not connected, we need to connect now to determine the platform version.
if ($this->_conn === null) {
try {
$this->connect();
} catch (Throwable $originalException) {
if (empty($this->params['dbname'])) {
throw $originalException;
}
// The database to connect to might not yet exist.
// Retry detection without database name connection parameter.
$databaseName = $this->params['dbname'];
$this->params['dbname'] = null;
try {
$this->connect();
} catch (Throwable $fallbackException) {
// Either the platform does not support database-less connections
// or something else went wrong.
// Reset connection parameters and rethrow the original exception.
$this->params['dbname'] = $databaseName;
throw $originalException;
}
// Reset connection parameters.
$this->params['dbname'] = $databaseName;
$serverVersion = $this->getServerVersion();
// Close "temporary" connection to allow connecting to the real database again.
$this->close();
return $serverVersion;
}
}
return $this->getServerVersion();
} | php | private function getDatabasePlatformVersion()
{
// Driver does not support version specific platforms.
if (! $this->_driver instanceof VersionAwarePlatformDriver) {
return null;
}
// Explicit platform version requested (supersedes auto-detection).
if (isset($this->params['serverVersion'])) {
return $this->params['serverVersion'];
}
// If not connected, we need to connect now to determine the platform version.
if ($this->_conn === null) {
try {
$this->connect();
} catch (Throwable $originalException) {
if (empty($this->params['dbname'])) {
throw $originalException;
}
// The database to connect to might not yet exist.
// Retry detection without database name connection parameter.
$databaseName = $this->params['dbname'];
$this->params['dbname'] = null;
try {
$this->connect();
} catch (Throwable $fallbackException) {
// Either the platform does not support database-less connections
// or something else went wrong.
// Reset connection parameters and rethrow the original exception.
$this->params['dbname'] = $databaseName;
throw $originalException;
}
// Reset connection parameters.
$this->params['dbname'] = $databaseName;
$serverVersion = $this->getServerVersion();
// Close "temporary" connection to allow connecting to the real database again.
$this->close();
return $serverVersion;
}
}
return $this->getServerVersion();
} | [
"private",
"function",
"getDatabasePlatformVersion",
"(",
")",
"{",
"// Driver does not support version specific platforms.",
"if",
"(",
"!",
"$",
"this",
"->",
"_driver",
"instanceof",
"VersionAwarePlatformDriver",
")",
"{",
"return",
"null",
";",
"}",
"// Explicit platform version requested (supersedes auto-detection).",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"params",
"[",
"'serverVersion'",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"params",
"[",
"'serverVersion'",
"]",
";",
"}",
"// If not connected, we need to connect now to determine the platform version.",
"if",
"(",
"$",
"this",
"->",
"_conn",
"===",
"null",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"connect",
"(",
")",
";",
"}",
"catch",
"(",
"Throwable",
"$",
"originalException",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"params",
"[",
"'dbname'",
"]",
")",
")",
"{",
"throw",
"$",
"originalException",
";",
"}",
"// The database to connect to might not yet exist.",
"// Retry detection without database name connection parameter.",
"$",
"databaseName",
"=",
"$",
"this",
"->",
"params",
"[",
"'dbname'",
"]",
";",
"$",
"this",
"->",
"params",
"[",
"'dbname'",
"]",
"=",
"null",
";",
"try",
"{",
"$",
"this",
"->",
"connect",
"(",
")",
";",
"}",
"catch",
"(",
"Throwable",
"$",
"fallbackException",
")",
"{",
"// Either the platform does not support database-less connections",
"// or something else went wrong.",
"// Reset connection parameters and rethrow the original exception.",
"$",
"this",
"->",
"params",
"[",
"'dbname'",
"]",
"=",
"$",
"databaseName",
";",
"throw",
"$",
"originalException",
";",
"}",
"// Reset connection parameters.",
"$",
"this",
"->",
"params",
"[",
"'dbname'",
"]",
"=",
"$",
"databaseName",
";",
"$",
"serverVersion",
"=",
"$",
"this",
"->",
"getServerVersion",
"(",
")",
";",
"// Close \"temporary\" connection to allow connecting to the real database again.",
"$",
"this",
"->",
"close",
"(",
")",
";",
"return",
"$",
"serverVersion",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"getServerVersion",
"(",
")",
";",
"}"
]
| Returns the version of the related platform if applicable.
Returns null if either the driver is not capable to create version
specific platform instances, no explicit server version was specified
or the underlying driver connection cannot determine the platform
version without having to query it (performance reasons).
@return string|null
@throws Exception | [
"Returns",
"the",
"version",
"of",
"the",
"related",
"platform",
"if",
"applicable",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Connection.php#L403-L452 | train |
doctrine/dbal | lib/Doctrine/DBAL/Connection.php | Connection.getServerVersion | private function getServerVersion()
{
$connection = $this->getWrappedConnection();
// Automatic platform version detection.
if ($connection instanceof ServerInfoAwareConnection && ! $connection->requiresQueryForServerVersion()) {
return $connection->getServerVersion();
}
// Unable to detect platform version.
return null;
} | php | private function getServerVersion()
{
$connection = $this->getWrappedConnection();
// Automatic platform version detection.
if ($connection instanceof ServerInfoAwareConnection && ! $connection->requiresQueryForServerVersion()) {
return $connection->getServerVersion();
}
// Unable to detect platform version.
return null;
} | [
"private",
"function",
"getServerVersion",
"(",
")",
"{",
"$",
"connection",
"=",
"$",
"this",
"->",
"getWrappedConnection",
"(",
")",
";",
"// Automatic platform version detection.",
"if",
"(",
"$",
"connection",
"instanceof",
"ServerInfoAwareConnection",
"&&",
"!",
"$",
"connection",
"->",
"requiresQueryForServerVersion",
"(",
")",
")",
"{",
"return",
"$",
"connection",
"->",
"getServerVersion",
"(",
")",
";",
"}",
"// Unable to detect platform version.",
"return",
"null",
";",
"}"
]
| Returns the database server version if the underlying driver supports it.
@return string|null | [
"Returns",
"the",
"database",
"server",
"version",
"if",
"the",
"underlying",
"driver",
"supports",
"it",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Connection.php#L459-L470 | train |
doctrine/dbal | lib/Doctrine/DBAL/Connection.php | Connection.setAutoCommit | public function setAutoCommit($autoCommit)
{
$autoCommit = (bool) $autoCommit;
// Mode not changed, no-op.
if ($autoCommit === $this->autoCommit) {
return;
}
$this->autoCommit = $autoCommit;
// Commit all currently active transactions if any when switching auto-commit mode.
if ($this->isConnected !== true || $this->transactionNestingLevel === 0) {
return;
}
$this->commitAll();
} | php | public function setAutoCommit($autoCommit)
{
$autoCommit = (bool) $autoCommit;
// Mode not changed, no-op.
if ($autoCommit === $this->autoCommit) {
return;
}
$this->autoCommit = $autoCommit;
// Commit all currently active transactions if any when switching auto-commit mode.
if ($this->isConnected !== true || $this->transactionNestingLevel === 0) {
return;
}
$this->commitAll();
} | [
"public",
"function",
"setAutoCommit",
"(",
"$",
"autoCommit",
")",
"{",
"$",
"autoCommit",
"=",
"(",
"bool",
")",
"$",
"autoCommit",
";",
"// Mode not changed, no-op.",
"if",
"(",
"$",
"autoCommit",
"===",
"$",
"this",
"->",
"autoCommit",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"autoCommit",
"=",
"$",
"autoCommit",
";",
"// Commit all currently active transactions if any when switching auto-commit mode.",
"if",
"(",
"$",
"this",
"->",
"isConnected",
"!==",
"true",
"||",
"$",
"this",
"->",
"transactionNestingLevel",
"===",
"0",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"commitAll",
"(",
")",
";",
"}"
]
| Sets auto-commit mode for this connection.
If a connection is in auto-commit mode, then all its SQL statements will be executed and committed as individual
transactions. Otherwise, its SQL statements are grouped into transactions that are terminated by a call to either
the method commit or the method rollback. By default, new connections are in auto-commit mode.
NOTE: If this method is called during a transaction and the auto-commit mode is changed, the transaction is
committed. If this method is called and the auto-commit mode is not changed, the call is a no-op.
@see isAutoCommit
@param bool $autoCommit True to enable auto-commit mode; false to disable it. | [
"Sets",
"auto",
"-",
"commit",
"mode",
"for",
"this",
"connection",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Connection.php#L498-L515 | train |
doctrine/dbal | lib/Doctrine/DBAL/Connection.php | Connection.fetchAssoc | public function fetchAssoc($statement, array $params = [], array $types = [])
{
return $this->executeQuery($statement, $params, $types)->fetch(FetchMode::ASSOCIATIVE);
} | php | public function fetchAssoc($statement, array $params = [], array $types = [])
{
return $this->executeQuery($statement, $params, $types)->fetch(FetchMode::ASSOCIATIVE);
} | [
"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.
@param string $statement The SQL query.
@param mixed[] $params The query parameters.
@param int[]|string[] $types The query parameter types.
@return mixed[]|false False is returned if no rows are found.
@throws DBALException | [
"Prepares",
"and",
"executes",
"an",
"SQL",
"query",
"and",
"returns",
"the",
"first",
"row",
"of",
"the",
"result",
"as",
"an",
"associative",
"array",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Connection.php#L541-L544 | train |
doctrine/dbal | lib/Doctrine/DBAL/Connection.php | Connection.fetchArray | public function fetchArray($statement, array $params = [], array $types = [])
{
return $this->executeQuery($statement, $params, $types)->fetch(FetchMode::NUMERIC);
} | php | public function fetchArray($statement, array $params = [], array $types = [])
{
return $this->executeQuery($statement, $params, $types)->fetch(FetchMode::NUMERIC);
} | [
"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.
@param string $statement The SQL query to be executed.
@param mixed[] $params The prepared statement params.
@param int[]|string[] $types The query parameter types.
@return mixed[]|false False is returned if no rows are found. | [
"Prepares",
"and",
"executes",
"an",
"SQL",
"query",
"and",
"returns",
"the",
"first",
"row",
"of",
"the",
"result",
"as",
"a",
"numerically",
"indexed",
"array",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Connection.php#L556-L559 | train |
doctrine/dbal | lib/Doctrine/DBAL/Connection.php | Connection.addIdentifierCondition | 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 . ' = ?';
}
} | php | 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 . ' = ?';
}
} | [
"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
@param mixed[] $identifier Map of key columns to their values
@param string[] $columns Column names
@param mixed[] $values Column values
@param string[] $conditions Key conditions
@throws DBALException | [
"Adds",
"identifier",
"condition",
"to",
"the",
"query",
"components"
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Connection.php#L609-L627 | train |
doctrine/dbal | lib/Doctrine/DBAL/Connection.php | Connection.delete | 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
);
} | php | 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
);
} | [
"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.
Table expression and columns are not escaped and are not safe for user-input.
@param string $tableExpression The expression of the table on which to delete.
@param mixed[] $identifier The deletion criteria. An associative array containing column-value pairs.
@param int[]|string[] $types The types of identifiers.
@return int The number of affected rows.
@throws DBALException
@throws InvalidArgumentException | [
"Executes",
"an",
"SQL",
"DELETE",
"statement",
"on",
"a",
"table",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Connection.php#L643-L658 | train |
doctrine/dbal | lib/Doctrine/DBAL/Connection.php | Connection.setTransactionIsolation | public function setTransactionIsolation($level)
{
$this->transactionIsolationLevel = $level;
return $this->executeUpdate($this->getDatabasePlatform()->getSetTransactionIsolationSQL($level));
} | php | public function setTransactionIsolation($level)
{
$this->transactionIsolationLevel = $level;
return $this->executeUpdate($this->getDatabasePlatform()->getSetTransactionIsolationSQL($level));
} | [
"public",
"function",
"setTransactionIsolation",
"(",
"$",
"level",
")",
"{",
"$",
"this",
"->",
"transactionIsolationLevel",
"=",
"$",
"level",
";",
"return",
"$",
"this",
"->",
"executeUpdate",
"(",
"$",
"this",
"->",
"getDatabasePlatform",
"(",
")",
"->",
"getSetTransactionIsolationSQL",
"(",
"$",
"level",
")",
")",
";",
"}"
]
| Sets the transaction isolation level.
@param int $level The level to set.
@return int | [
"Sets",
"the",
"transaction",
"isolation",
"level",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Connection.php#L679-L684 | train |
doctrine/dbal | lib/Doctrine/DBAL/Connection.php | Connection.getTransactionIsolation | public function getTransactionIsolation()
{
if ($this->transactionIsolationLevel === null) {
$this->transactionIsolationLevel = $this->getDatabasePlatform()->getDefaultTransactionIsolationLevel();
}
return $this->transactionIsolationLevel;
} | php | public function getTransactionIsolation()
{
if ($this->transactionIsolationLevel === null) {
$this->transactionIsolationLevel = $this->getDatabasePlatform()->getDefaultTransactionIsolationLevel();
}
return $this->transactionIsolationLevel;
} | [
"public",
"function",
"getTransactionIsolation",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"transactionIsolationLevel",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"transactionIsolationLevel",
"=",
"$",
"this",
"->",
"getDatabasePlatform",
"(",
")",
"->",
"getDefaultTransactionIsolationLevel",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"transactionIsolationLevel",
";",
"}"
]
| Gets the currently active transaction isolation level.
@return int The current transaction isolation level. | [
"Gets",
"the",
"currently",
"active",
"transaction",
"isolation",
"level",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Connection.php#L691-L698 | train |
doctrine/dbal | lib/Doctrine/DBAL/Connection.php | Connection.update | 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);
} | php | 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);
} | [
"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.
Table expression and columns are not escaped and are not safe for user-input.
@param string $tableExpression The expression of the table to update quoted or unquoted.
@param mixed[] $data An associative array containing column-value pairs.
@param mixed[] $identifier The update criteria. An associative array containing column-value pairs.
@param int[]|string[] $types Types of the merged $data and $identifier arrays in that order.
@return int The number of affected rows.
@throws DBALException | [
"Executes",
"an",
"SQL",
"UPDATE",
"statement",
"on",
"a",
"table",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Connection.php#L714-L734 | train |
doctrine/dbal | lib/Doctrine/DBAL/Connection.php | Connection.extractTypeValues | private function extractTypeValues(array $columnList, array $types)
{
$typeValues = [];
foreach ($columnList as $columnIndex => $columnName) {
$typeValues[] = $types[$columnName] ?? ParameterType::STRING;
}
return $typeValues;
} | php | private function extractTypeValues(array $columnList, array $types)
{
$typeValues = [];
foreach ($columnList as $columnIndex => $columnName) {
$typeValues[] = $types[$columnName] ?? ParameterType::STRING;
}
return $typeValues;
} | [
"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.
@param int[]|string[] $columnList
@param int[]|string[] $types
@return int[]|string[] | [
"Extract",
"ordered",
"type",
"list",
"from",
"an",
"ordered",
"column",
"list",
"and",
"type",
"map",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Connection.php#L781-L790 | train |
doctrine/dbal | lib/Doctrine/DBAL/Connection.php | Connection.fetchAll | public function fetchAll($sql, array $params = [], $types = [])
{
return $this->executeQuery($sql, $params, $types)->fetchAll();
} | php | public function fetchAll($sql, array $params = [], $types = [])
{
return $this->executeQuery($sql, $params, $types)->fetchAll();
} | [
"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.
@param string $sql The SQL query.
@param mixed[] $params The query parameters.
@param int[]|string[] $types The query parameter types.
@return mixed[] | [
"Prepares",
"and",
"executes",
"an",
"SQL",
"query",
"and",
"returns",
"the",
"result",
"as",
"an",
"associative",
"array",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Connection.php#L832-L835 | train |
doctrine/dbal | lib/Doctrine/DBAL/Connection.php | Connection.executeQuery | 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;
} | php | 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;
} | [
"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.
If the query is parametrized, a prepared statement is used.
If an SQLLogger is configured, the execution is logged.
@param string $query The SQL query to execute.
@param mixed[] $params The parameters to bind to the query, if any.
@param int[]|string[] $types The types the previous parameters are in.
@param QueryCacheProfile|null $qcp The query cache profile, optional.
@return ResultStatement The executed statement.
@throws DBALException | [
"Executes",
"an",
"optionally",
"parametrized",
"SQL",
"query",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Connection.php#L874-L912 | train |
doctrine/dbal | lib/Doctrine/DBAL/Connection.php | Connection.executeCacheQuery | 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);
// fetch the row pointers entry
$data = $resultCache->fetch($cacheKey);
if ($data !== false) {
// is the real key part of this row pointers map or is the cache only pointing to other cache keys?
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;
} | php | 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);
// fetch the row pointers entry
$data = $resultCache->fetch($cacheKey);
if ($data !== false) {
// is the real key part of this row pointers map or is the cache only pointing to other cache keys?
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;
} | [
"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",
")",
";",
"// fetch the row pointers entry",
"$",
"data",
"=",
"$",
"resultCache",
"->",
"fetch",
"(",
"$",
"cacheKey",
")",
";",
"if",
"(",
"$",
"data",
"!==",
"false",
")",
"{",
"// is the real key part of this row pointers map or is the cache only pointing to other cache keys?",
"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.
@param string $query The SQL query to execute.
@param mixed[] $params The parameters to bind to the query, if any.
@param int[]|string[] $types The types the previous parameters are in.
@param QueryCacheProfile $qcp The query cache profile.
@return ResultStatement
@throws CacheException | [
"Executes",
"a",
"caching",
"query",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Connection.php#L926-L958 | train |
doctrine/dbal | lib/Doctrine/DBAL/Connection.php | Connection.exec | 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;
} | php | 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;
} | [
"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.
@param string $statement
@return int The number of affected rows.
@throws DBALException | [
"Executes",
"an",
"SQL",
"statement",
"and",
"return",
"the",
"number",
"of",
"affected",
"rows",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Connection.php#L1078-L1098 | train |
doctrine/dbal | lib/Doctrine/DBAL/Connection.php | Connection.setNestTransactionsWithSavepoints | public function setNestTransactionsWithSavepoints($nestTransactionsWithSavepoints)
{
if ($this->transactionNestingLevel > 0) {
throw ConnectionException::mayNotAlterNestedTransactionWithSavepointsInTransaction();
}
if (! $this->getDatabasePlatform()->supportsSavepoints()) {
throw ConnectionException::savepointsNotSupported();
}
$this->nestTransactionsWithSavepoints = (bool) $nestTransactionsWithSavepoints;
} | php | public function setNestTransactionsWithSavepoints($nestTransactionsWithSavepoints)
{
if ($this->transactionNestingLevel > 0) {
throw ConnectionException::mayNotAlterNestedTransactionWithSavepointsInTransaction();
}
if (! $this->getDatabasePlatform()->supportsSavepoints()) {
throw ConnectionException::savepointsNotSupported();
}
$this->nestTransactionsWithSavepoints = (bool) $nestTransactionsWithSavepoints;
} | [
"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.
@param bool $nestTransactionsWithSavepoints
@return void
@throws ConnectionException | [
"Sets",
"if",
"nested",
"transactions",
"should",
"use",
"savepoints",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Connection.php#L1186-L1197 | train |
doctrine/dbal | lib/Doctrine/DBAL/Connection.php | Connection.commitAll | private function commitAll()
{
while ($this->transactionNestingLevel !== 0) {
if ($this->autoCommit === false && $this->transactionNestingLevel === 1) {
// When in no auto-commit mode, the last nesting commit immediately starts a new transaction.
// Therefore we need to do the final commit here and then leave to avoid an infinite loop.
$this->commit();
return;
}
$this->commit();
}
} | php | private function commitAll()
{
while ($this->transactionNestingLevel !== 0) {
if ($this->autoCommit === false && $this->transactionNestingLevel === 1) {
// When in no auto-commit mode, the last nesting commit immediately starts a new transaction.
// Therefore we need to do the final commit here and then leave to avoid an infinite loop.
$this->commit();
return;
}
$this->commit();
}
} | [
"private",
"function",
"commitAll",
"(",
")",
"{",
"while",
"(",
"$",
"this",
"->",
"transactionNestingLevel",
"!==",
"0",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"autoCommit",
"===",
"false",
"&&",
"$",
"this",
"->",
"transactionNestingLevel",
"===",
"1",
")",
"{",
"// When in no auto-commit mode, the last nesting commit immediately starts a new transaction.",
"// Therefore we need to do the final commit here and then leave to avoid an infinite loop.",
"$",
"this",
"->",
"commit",
"(",
")",
";",
"return",
";",
"}",
"$",
"this",
"->",
"commit",
"(",
")",
";",
"}",
"}"
]
| Commits all current nesting transactions. | [
"Commits",
"all",
"current",
"nesting",
"transactions",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Connection.php#L1307-L1320 | train |
doctrine/dbal | lib/Doctrine/DBAL/Connection.php | Connection.rollBack | 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;
}
} | php | 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;
}
} | [
"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.
@throws ConnectionException If the rollback operation failed. | [
"Cancels",
"any",
"database",
"changes",
"done",
"during",
"the",
"current",
"transaction",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Connection.php#L1327-L1364 | train |
doctrine/dbal | lib/Doctrine/DBAL/Connection.php | Connection.createSavepoint | public function createSavepoint($savepoint)
{
if (! $this->getDatabasePlatform()->supportsSavepoints()) {
throw ConnectionException::savepointsNotSupported();
}
$this->getWrappedConnection()->exec($this->platform->createSavePoint($savepoint));
} | php | public function createSavepoint($savepoint)
{
if (! $this->getDatabasePlatform()->supportsSavepoints()) {
throw ConnectionException::savepointsNotSupported();
}
$this->getWrappedConnection()->exec($this->platform->createSavePoint($savepoint));
} | [
"public",
"function",
"createSavepoint",
"(",
"$",
"savepoint",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"getDatabasePlatform",
"(",
")",
"->",
"supportsSavepoints",
"(",
")",
")",
"{",
"throw",
"ConnectionException",
"::",
"savepointsNotSupported",
"(",
")",
";",
"}",
"$",
"this",
"->",
"getWrappedConnection",
"(",
")",
"->",
"exec",
"(",
"$",
"this",
"->",
"platform",
"->",
"createSavePoint",
"(",
"$",
"savepoint",
")",
")",
";",
"}"
]
| Creates a new savepoint.
@param string $savepoint The name of the savepoint to create.
@return void
@throws ConnectionException | [
"Creates",
"a",
"new",
"savepoint",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Connection.php#L1375-L1382 | train |
doctrine/dbal | lib/Doctrine/DBAL/Connection.php | Connection.releaseSavepoint | public function releaseSavepoint($savepoint)
{
if (! $this->getDatabasePlatform()->supportsSavepoints()) {
throw ConnectionException::savepointsNotSupported();
}
if (! $this->platform->supportsReleaseSavepoints()) {
return;
}
$this->getWrappedConnection()->exec($this->platform->releaseSavePoint($savepoint));
} | php | public function releaseSavepoint($savepoint)
{
if (! $this->getDatabasePlatform()->supportsSavepoints()) {
throw ConnectionException::savepointsNotSupported();
}
if (! $this->platform->supportsReleaseSavepoints()) {
return;
}
$this->getWrappedConnection()->exec($this->platform->releaseSavePoint($savepoint));
} | [
"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.
@param string $savepoint The name of the savepoint to release.
@return void
@throws ConnectionException | [
"Releases",
"the",
"given",
"savepoint",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Connection.php#L1393-L1404 | train |
doctrine/dbal | lib/Doctrine/DBAL/Connection.php | Connection.rollbackSavepoint | public function rollbackSavepoint($savepoint)
{
if (! $this->getDatabasePlatform()->supportsSavepoints()) {
throw ConnectionException::savepointsNotSupported();
}
$this->getWrappedConnection()->exec($this->platform->rollbackSavePoint($savepoint));
} | php | public function rollbackSavepoint($savepoint)
{
if (! $this->getDatabasePlatform()->supportsSavepoints()) {
throw ConnectionException::savepointsNotSupported();
}
$this->getWrappedConnection()->exec($this->platform->rollbackSavePoint($savepoint));
} | [
"public",
"function",
"rollbackSavepoint",
"(",
"$",
"savepoint",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"getDatabasePlatform",
"(",
")",
"->",
"supportsSavepoints",
"(",
")",
")",
"{",
"throw",
"ConnectionException",
"::",
"savepointsNotSupported",
"(",
")",
";",
"}",
"$",
"this",
"->",
"getWrappedConnection",
"(",
")",
"->",
"exec",
"(",
"$",
"this",
"->",
"platform",
"->",
"rollbackSavePoint",
"(",
"$",
"savepoint",
")",
")",
";",
"}"
]
| Rolls back to the given savepoint.
@param string $savepoint The name of the savepoint to rollback to.
@return void
@throws ConnectionException | [
"Rolls",
"back",
"to",
"the",
"given",
"savepoint",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Connection.php#L1415-L1422 | train |
doctrine/dbal | lib/Doctrine/DBAL/Connection.php | Connection.getSchemaManager | public function getSchemaManager()
{
if ($this->_schemaManager === null) {
$this->_schemaManager = $this->_driver->getSchemaManager($this);
}
return $this->_schemaManager;
} | php | public function getSchemaManager()
{
if ($this->_schemaManager === null) {
$this->_schemaManager = $this->_driver->getSchemaManager($this);
}
return $this->_schemaManager;
} | [
"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.
@return AbstractSchemaManager | [
"Gets",
"the",
"SchemaManager",
"that",
"can",
"be",
"used",
"to",
"inspect",
"or",
"change",
"the",
"database",
"schema",
"through",
"the",
"connection",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Connection.php#L1443-L1450 | train |
doctrine/dbal | lib/Doctrine/DBAL/Connection.php | Connection.convertToDatabaseValue | public function convertToDatabaseValue($value, $type)
{
return Type::getType($type)->convertToDatabaseValue($value, $this->getDatabasePlatform());
} | php | public function convertToDatabaseValue($value, $type)
{
return Type::getType($type)->convertToDatabaseValue($value, $this->getDatabasePlatform());
} | [
"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.
@param mixed $value The value to convert.
@param string $type The name of the DBAL mapping type.
@return mixed The converted value. | [
"Converts",
"a",
"given",
"value",
"to",
"its",
"database",
"representation",
"according",
"to",
"the",
"conversion",
"rules",
"of",
"a",
"specific",
"DBAL",
"mapping",
"type",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Connection.php#L1493-L1496 | train |
doctrine/dbal | lib/Doctrine/DBAL/Connection.php | Connection._bindTypedValues | private function _bindTypedValues($stmt, array $params, array $types)
{
// Check whether parameters are positional or named. Mixing is not allowed, just like in PDO.
if (is_int(key($params))) {
// Positional parameters
$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 {
// Named parameters
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);
}
}
}
} | php | private function _bindTypedValues($stmt, array $params, array $types)
{
// Check whether parameters are positional or named. Mixing is not allowed, just like in PDO.
if (is_int(key($params))) {
// Positional parameters
$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 {
// Named parameters
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);
}
}
}
} | [
"private",
"function",
"_bindTypedValues",
"(",
"$",
"stmt",
",",
"array",
"$",
"params",
",",
"array",
"$",
"types",
")",
"{",
"// Check whether parameters are positional or named. Mixing is not allowed, just like in PDO.",
"if",
"(",
"is_int",
"(",
"key",
"(",
"$",
"params",
")",
")",
")",
"{",
"// Positional parameters",
"$",
"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",
"{",
"// Named parameters",
"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.
@internal Duck-typing used on the $stmt parameter to support driver statements as well as
raw PDOStatement instances.
@param \Doctrine\DBAL\Driver\Statement $stmt The statement to bind the values to.
@param mixed[] $params The map/list of named/positional parameters.
@param int[]|string[] $types The parameter types (PDO binding types or DBAL mapping types).
@return void | [
"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",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Connection.php#L1525-L1555 | train |
doctrine/dbal | lib/Doctrine/DBAL/Connection.php | Connection.getBindingInfo | 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];
} | php | 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];
} | [
"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.
@param mixed $value The value to bind.
@param int|string|null $type The type to bind (PDO or DBAL).
@return mixed[] [0] => the (escaped) value, [1] => the binding type. | [
"Gets",
"the",
"binding",
"type",
"of",
"a",
"given",
"type",
".",
"The",
"given",
"type",
"can",
"be",
"a",
"PDO",
"or",
"DBAL",
"mapping",
"type",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Connection.php#L1565-L1578 | train |
doctrine/dbal | lib/Doctrine/DBAL/Connection.php | Connection.resolveParams | public function resolveParams(array $params, array $types)
{
$resolvedParams = [];
// Check whether parameters are positional or named. Mixing is not allowed, just like in PDO.
if (is_int(key($params))) {
// Positional parameters
$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 {
// Named parameters
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;
} | php | public function resolveParams(array $params, array $types)
{
$resolvedParams = [];
// Check whether parameters are positional or named. Mixing is not allowed, just like in PDO.
if (is_int(key($params))) {
// Positional parameters
$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 {
// Named parameters
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;
} | [
"public",
"function",
"resolveParams",
"(",
"array",
"$",
"params",
",",
"array",
"$",
"types",
")",
"{",
"$",
"resolvedParams",
"=",
"[",
"]",
";",
"// Check whether parameters are positional or named. Mixing is not allowed, just like in PDO.",
"if",
"(",
"is_int",
"(",
"key",
"(",
"$",
"params",
")",
")",
")",
"{",
"// Positional parameters",
"$",
"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",
"{",
"// Named parameters",
"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.
@internal This is a purely internal method. If you rely on this method, you are advised to
copy/paste the code as this method may change, or be removed without prior notice.
@param mixed[] $params
@param int[]|string[] $types
@return mixed[] | [
"Resolves",
"the",
"parameters",
"to",
"a",
"format",
"which",
"can",
"be",
"displayed",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Connection.php#L1591-L1625 | train |
doctrine/dbal | lib/Doctrine/DBAL/Platforms/DB2Platform.php | DB2Platform.gatherAlterColumnSQL | private function gatherAlterColumnSQL(Identifier $table, ColumnDiff $columnDiff, array &$sql, array &$queryParts)
{
$alterColumnClauses = $this->getAlterColumnClausesSQL($columnDiff);
if (empty($alterColumnClauses)) {
return;
}
// If we have a single column alteration, we can append the clause to the main query.
if (count($alterColumnClauses) === 1) {
$queryParts[] = current($alterColumnClauses);
return;
}
// We have multiple alterations for the same column,
// so we need to trigger a complete ALTER TABLE statement
// for each ALTER COLUMN clause.
foreach ($alterColumnClauses as $alterColumnClause) {
$sql[] = 'ALTER TABLE ' . $table->getQuotedName($this) . ' ' . $alterColumnClause;
}
} | php | private function gatherAlterColumnSQL(Identifier $table, ColumnDiff $columnDiff, array &$sql, array &$queryParts)
{
$alterColumnClauses = $this->getAlterColumnClausesSQL($columnDiff);
if (empty($alterColumnClauses)) {
return;
}
// If we have a single column alteration, we can append the clause to the main query.
if (count($alterColumnClauses) === 1) {
$queryParts[] = current($alterColumnClauses);
return;
}
// We have multiple alterations for the same column,
// so we need to trigger a complete ALTER TABLE statement
// for each ALTER COLUMN clause.
foreach ($alterColumnClauses as $alterColumnClause) {
$sql[] = 'ALTER TABLE ' . $table->getQuotedName($this) . ' ' . $alterColumnClause;
}
} | [
"private",
"function",
"gatherAlterColumnSQL",
"(",
"Identifier",
"$",
"table",
",",
"ColumnDiff",
"$",
"columnDiff",
",",
"array",
"&",
"$",
"sql",
",",
"array",
"&",
"$",
"queryParts",
")",
"{",
"$",
"alterColumnClauses",
"=",
"$",
"this",
"->",
"getAlterColumnClausesSQL",
"(",
"$",
"columnDiff",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"alterColumnClauses",
")",
")",
"{",
"return",
";",
"}",
"// If we have a single column alteration, we can append the clause to the main query.",
"if",
"(",
"count",
"(",
"$",
"alterColumnClauses",
")",
"===",
"1",
")",
"{",
"$",
"queryParts",
"[",
"]",
"=",
"current",
"(",
"$",
"alterColumnClauses",
")",
";",
"return",
";",
"}",
"// We have multiple alterations for the same column,",
"// so we need to trigger a complete ALTER TABLE statement",
"// for each ALTER COLUMN clause.",
"foreach",
"(",
"$",
"alterColumnClauses",
"as",
"$",
"alterColumnClause",
")",
"{",
"$",
"sql",
"[",
"]",
"=",
"'ALTER TABLE '",
".",
"$",
"table",
"->",
"getQuotedName",
"(",
"$",
"this",
")",
".",
"' '",
".",
"$",
"alterColumnClause",
";",
"}",
"}"
]
| Gathers the table alteration SQL for a given column diff.
@param Identifier $table The table to gather the SQL for.
@param ColumnDiff $columnDiff The column diff to evaluate.
@param string[] $sql The sequence of table alteration statements to fill.
@param mixed[] $queryParts The sequence of column alteration clauses to fill. | [
"Gathers",
"the",
"table",
"alteration",
"SQL",
"for",
"a",
"given",
"column",
"diff",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Platforms/DB2Platform.php#L631-L652 | train |
doctrine/dbal | lib/Doctrine/DBAL/Platforms/DB2Platform.php | DB2Platform.getAlterColumnClausesSQL | 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;
} | php | 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;
} | [
"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.
@param ColumnDiff $columnDiff The column diff to evaluate.
@return string[] | [
"Returns",
"the",
"ALTER",
"COLUMN",
"SQL",
"clauses",
"for",
"altering",
"a",
"column",
"described",
"by",
"the",
"given",
"column",
"diff",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Platforms/DB2Platform.php#L661-L699 | train |
doctrine/dbal | lib/Doctrine/DBAL/Query/Expression/CompositeExpression.php | CompositeExpression.add | public function add($part)
{
if (empty($part)) {
return $this;
}
if ($part instanceof self && count($part) === 0) {
return $this;
}
$this->parts[] = $part;
return $this;
} | php | public function add($part)
{
if (empty($part)) {
return $this;
}
if ($part instanceof self && count($part) === 0) {
return $this;
}
$this->parts[] = $part;
return $this;
} | [
"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.
@param mixed $part
@return \Doctrine\DBAL\Query\Expression\CompositeExpression | [
"Adds",
"an",
"expression",
"to",
"composite",
"expression",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Query/Expression/CompositeExpression.php#L72-L85 | train |
doctrine/dbal | lib/Doctrine/DBAL/Platforms/AbstractPlatform.php | AbstractPlatform.initializeAllDoctrineTypeMappings | private function initializeAllDoctrineTypeMappings()
{
$this->initializeDoctrineTypeMappings();
foreach (Type::getTypesMap() as $typeName => $className) {
foreach (Type::getType($typeName)->getMappedDatabaseTypes($this) as $dbType) {
$this->doctrineTypeMapping[$dbType] = $typeName;
}
}
} | php | private function initializeAllDoctrineTypeMappings()
{
$this->initializeDoctrineTypeMappings();
foreach (Type::getTypesMap() as $typeName => $className) {
foreach (Type::getType($typeName)->getMappedDatabaseTypes($this) as $dbType) {
$this->doctrineTypeMapping[$dbType] = $typeName;
}
}
} | [
"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.
@return void | [
"Initializes",
"Doctrine",
"Type",
"Mappings",
"with",
"the",
"platform",
"defaults",
"and",
"with",
"all",
"additional",
"type",
"mappings",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php#L233-L242 | train |
doctrine/dbal | lib/Doctrine/DBAL/Platforms/AbstractPlatform.php | AbstractPlatform.registerDoctrineTypeMapping | 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);
} | php | 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);
} | [
"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.
@param string $dbType
@param string $doctrineType
@throws DBALException If the type is not found. | [
"Registers",
"a",
"doctrine",
"type",
"to",
"be",
"used",
"in",
"conjunction",
"with",
"a",
"column",
"type",
"of",
"this",
"platform",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php#L396-L416 | train |
doctrine/dbal | lib/Doctrine/DBAL/Platforms/AbstractPlatform.php | AbstractPlatform.getDoctrineTypeMapping | 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];
} | php | 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];
} | [
"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.
@param string $dbType
@return string
@throws DBALException | [
"Gets",
"the",
"Doctrine",
"type",
"that",
"is",
"mapped",
"for",
"the",
"given",
"database",
"column",
"type",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php#L427-L440 | train |
doctrine/dbal | lib/Doctrine/DBAL/Platforms/AbstractPlatform.php | AbstractPlatform.hasDoctrineTypeMappingFor | public function hasDoctrineTypeMappingFor($dbType)
{
if ($this->doctrineTypeMapping === null) {
$this->initializeAllDoctrineTypeMappings();
}
$dbType = strtolower($dbType);
return isset($this->doctrineTypeMapping[$dbType]);
} | php | public function hasDoctrineTypeMappingFor($dbType)
{
if ($this->doctrineTypeMapping === null) {
$this->initializeAllDoctrineTypeMappings();
}
$dbType = strtolower($dbType);
return isset($this->doctrineTypeMapping[$dbType]);
} | [
"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.
@param string $dbType
@return bool | [
"Checks",
"if",
"a",
"database",
"type",
"is",
"currently",
"supported",
"by",
"this",
"platform",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php#L449-L458 | train |
doctrine/dbal | lib/Doctrine/DBAL/Platforms/AbstractPlatform.php | AbstractPlatform.isCommentedDoctrineType | public function isCommentedDoctrineType(Type $doctrineType)
{
if ($this->doctrineTypeComments === null) {
$this->initializeCommentedDoctrineTypes();
}
assert(is_array($this->doctrineTypeComments));
return in_array($doctrineType->getName(), $this->doctrineTypeComments);
} | php | public function isCommentedDoctrineType(Type $doctrineType)
{
if ($this->doctrineTypeComments === null) {
$this->initializeCommentedDoctrineTypes();
}
assert(is_array($this->doctrineTypeComments));
return in_array($doctrineType->getName(), $this->doctrineTypeComments);
} | [
"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?
@return bool | [
"Is",
"it",
"necessary",
"for",
"the",
"platform",
"to",
"add",
"a",
"parsable",
"type",
"comment",
"to",
"allow",
"reverse",
"engineering",
"the",
"given",
"type?"
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php#L485-L494 | train |
doctrine/dbal | lib/Doctrine/DBAL/Platforms/AbstractPlatform.php | AbstractPlatform.markDoctrineTypeCommented | public function markDoctrineTypeCommented($doctrineType)
{
if ($this->doctrineTypeComments === null) {
$this->initializeCommentedDoctrineTypes();
}
assert(is_array($this->doctrineTypeComments));
$this->doctrineTypeComments[] = $doctrineType instanceof Type ? $doctrineType->getName() : $doctrineType;
} | php | public function markDoctrineTypeCommented($doctrineType)
{
if ($this->doctrineTypeComments === null) {
$this->initializeCommentedDoctrineTypes();
}
assert(is_array($this->doctrineTypeComments));
$this->doctrineTypeComments[] = $doctrineType instanceof Type ? $doctrineType->getName() : $doctrineType;
} | [
"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.
@param string|Type $doctrineType
@return void | [
"Marks",
"this",
"type",
"as",
"to",
"be",
"commented",
"in",
"ALTER",
"TABLE",
"and",
"CREATE",
"TABLE",
"statements",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php#L503-L512 | train |
doctrine/dbal | lib/Doctrine/DBAL/Platforms/AbstractPlatform.php | AbstractPlatform.getTrimExpression | 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 . ')';
} | php | 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 . ')';
} | [
"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.
@param string $str The expression to apply the trim to.
@param int $mode The position of the trim (leading/trailing/both).
@param string|bool $char The char to trim, has to be quoted already. Defaults to space.
@return string | [
"Returns",
"the",
"SQL",
"snippet",
"to",
"trim",
"a",
"string",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php#L791-L818 | train |
doctrine/dbal | lib/Doctrine/DBAL/Platforms/AbstractPlatform.php | AbstractPlatform.getDropTableSQL | 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;
} | php | 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;
} | [
"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.
@param Table|string $table
@return string
@throws InvalidArgumentException | [
"Returns",
"the",
"SQL",
"snippet",
"to",
"drop",
"an",
"existing",
"table",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php#L1411-L1439 | train |
doctrine/dbal | lib/Doctrine/DBAL/Platforms/AbstractPlatform.php | AbstractPlatform.getDropIndexSQL | 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;
} | php | 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;
} | [
"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.
@param Index|string $index
@param Table|string $table
@return string
@throws InvalidArgumentException | [
"Returns",
"the",
"SQL",
"to",
"drop",
"an",
"index",
"from",
"a",
"table",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php#L1463-L1472 | train |
doctrine/dbal | lib/Doctrine/DBAL/Platforms/AbstractPlatform.php | AbstractPlatform.getDropConstraintSQL | 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;
} | php | 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;
} | [
"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.
@param Constraint|string $constraint
@param Table|string $table
@return string | [
"Returns",
"the",
"SQL",
"to",
"drop",
"a",
"constraint",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php#L1482-L1496 | train |
doctrine/dbal | lib/Doctrine/DBAL/Platforms/AbstractPlatform.php | AbstractPlatform.getDropForeignKeySQL | 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;
} | php | 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;
} | [
"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.
@param ForeignKeyConstraint|string $foreignKey
@param Table|string $table
@return string | [
"Returns",
"the",
"SQL",
"to",
"drop",
"a",
"foreign",
"key",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php#L1506-L1520 | train |
doctrine/dbal | lib/Doctrine/DBAL/Platforms/AbstractPlatform.php | AbstractPlatform.getInlineColumnCommentSQL | public function getInlineColumnCommentSQL($comment)
{
if (! $this->supportsInlineColumnComments()) {
throw DBALException::notSupported(__METHOD__);
}
return 'COMMENT ' . $this->quoteStringLiteral($comment);
} | php | public function getInlineColumnCommentSQL($comment)
{
if (! $this->supportsInlineColumnComments()) {
throw DBALException::notSupported(__METHOD__);
}
return 'COMMENT ' . $this->quoteStringLiteral($comment);
} | [
"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.
@param string $comment
@return string
@throws DBALException If not supported on this platform. | [
"Returns",
"the",
"SQL",
"to",
"create",
"inline",
"comment",
"on",
"a",
"column",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php#L1653-L1660 | train |
doctrine/dbal | lib/Doctrine/DBAL/Platforms/AbstractPlatform.php | AbstractPlatform._getCreateTableSQL | 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;
} | php | 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;
} | [
"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.
@param string $tableName
@param mixed[][] $columns
@param mixed[] $options
@return string[] | [
"Returns",
"the",
"SQL",
"used",
"to",
"create",
"a",
"table",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php#L1671-L1708 | train |
doctrine/dbal | lib/Doctrine/DBAL/Platforms/AbstractPlatform.php | AbstractPlatform.getCreateConstraintSQL | 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;
} | php | 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;
} | [
"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.
@param Table|string $table
@return string
@throws InvalidArgumentException | [
"Returns",
"the",
"SQL",
"to",
"create",
"a",
"constraint",
"on",
"a",
"table",
"on",
"this",
"platform",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php#L1751-L1781 | train |
doctrine/dbal | lib/Doctrine/DBAL/Platforms/AbstractPlatform.php | AbstractPlatform.getCreateIndexSQL | 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;
} | php | 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;
} | [
"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.
@param Table|string $table The name of the table on which the index is to be created.
@return string
@throws InvalidArgumentException | [
"Returns",
"the",
"SQL",
"to",
"create",
"an",
"index",
"on",
"a",
"table",
"on",
"this",
"platform",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php#L1792-L1812 | train |
doctrine/dbal | lib/Doctrine/DBAL/Platforms/AbstractPlatform.php | AbstractPlatform.quoteIdentifier | public function quoteIdentifier($str)
{
if (strpos($str, '.') !== false) {
$parts = array_map([$this, 'quoteSingleIdentifier'], explode('.', $str));
return implode('.', $parts);
}
return $this->quoteSingleIdentifier($str);
} | php | public function quoteIdentifier($str)
{
if (strpos($str, '.') !== false) {
$parts = array_map([$this, 'quoteSingleIdentifier'], explode('.', $str));
return implode('.', $parts);
}
return $this->quoteSingleIdentifier($str);
} | [
"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.
NOTE: Just because you CAN use quoted identifiers doesn't mean
you SHOULD use them. In general, they end up causing way more
problems than they solve.
@param string $str The identifier name to be quoted.
@return string The quoted identifier string. | [
"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",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php#L1881-L1890 | train |
doctrine/dbal | lib/Doctrine/DBAL/Platforms/AbstractPlatform.php | AbstractPlatform.getCreateForeignKeySQL | public function getCreateForeignKeySQL(ForeignKeyConstraint $foreignKey, $table)
{
if ($table instanceof Table) {
$table = $table->getQuotedName($this);
}
return 'ALTER TABLE ' . $table . ' ADD ' . $this->getForeignKeyDeclarationSQL($foreignKey);
} | php | public function getCreateForeignKeySQL(ForeignKeyConstraint $foreignKey, $table)
{
if ($table instanceof Table) {
$table = $table->getQuotedName($this);
}
return 'ALTER TABLE ' . $table . ' ADD ' . $this->getForeignKeyDeclarationSQL($foreignKey);
} | [
"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.
@param ForeignKeyConstraint $foreignKey The foreign key constraint.
@param Table|string $table The name of the table on which the foreign key is to be created.
@return string | [
"Returns",
"the",
"SQL",
"to",
"create",
"a",
"new",
"foreign",
"key",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php#L1914-L1921 | train |
doctrine/dbal | lib/Doctrine/DBAL/Platforms/AbstractPlatform.php | AbstractPlatform.getRenameIndexSQL | protected function getRenameIndexSQL($oldIndexName, Index $index, $tableName)
{
return [
$this->getDropIndexSQL($oldIndexName, $tableName),
$this->getCreateIndexSQL($index, $tableName),
];
} | php | protected function getRenameIndexSQL($oldIndexName, Index $index, $tableName)
{
return [
$this->getDropIndexSQL($oldIndexName, $tableName),
$this->getCreateIndexSQL($index, $tableName),
];
} | [
"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.
@param string $oldIndexName The name of the index to rename from.
@param Index $index The definition of the index to rename to.
@param string $tableName The table to rename the given index on.
@return string[] The sequence of SQL statements for renaming the given index. | [
"Returns",
"the",
"SQL",
"for",
"renaming",
"an",
"index",
"on",
"a",
"table",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php#L2132-L2138 | train |
doctrine/dbal | lib/Doctrine/DBAL/Platforms/AbstractPlatform.php | AbstractPlatform._getAlterTableIndexForeignKeySQL | protected function _getAlterTableIndexForeignKeySQL(TableDiff $diff)
{
return array_merge($this->getPreAlterTableIndexForeignKeySQL($diff), $this->getPostAlterTableIndexForeignKeySQL($diff));
} | php | protected function _getAlterTableIndexForeignKeySQL(TableDiff $diff)
{
return array_merge($this->getPreAlterTableIndexForeignKeySQL($diff), $this->getPostAlterTableIndexForeignKeySQL($diff));
} | [
"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.
@return string[] | [
"Common",
"code",
"for",
"alter",
"table",
"statement",
"generation",
"that",
"updates",
"the",
"changed",
"Index",
"and",
"Foreign",
"Key",
"definitions",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php#L2145-L2148 | train |
doctrine/dbal | lib/Doctrine/DBAL/Platforms/AbstractPlatform.php | AbstractPlatform.getColumnDeclarationListSQL | public function getColumnDeclarationListSQL(array $fields)
{
$queryFields = [];
foreach ($fields as $fieldName => $field) {
$queryFields[] = $this->getColumnDeclarationSQL($fieldName, $field);
}
return implode(', ', $queryFields);
} | php | public function getColumnDeclarationListSQL(array $fields)
{
$queryFields = [];
foreach ($fields as $fieldName => $field) {
$queryFields[] = $this->getColumnDeclarationSQL($fieldName, $field);
}
return implode(', ', $queryFields);
} | [
"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.
@param mixed[][] $fields A multidimensional associative array.
The first dimension determines the field name, while the second
dimension is keyed with the name of the properties
of the field being declared as array indexes. Currently, the types
of supported field properties are as follows:
length
Integer value that determines the maximum length of the text
field. If this argument is missing the field should be
declared to have the longest length allowed by the DBMS.
default
Text value to be used as default for this field.
notnull
Boolean flag that indicates whether this field is constrained
to not be set to null.
charset
Text value with the default CHARACTER SET for this field.
collation
Text value with the default COLLATION for this field.
unique
unique constraint
@return string | [
"Gets",
"declaration",
"of",
"a",
"number",
"of",
"fields",
"in",
"bulk",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php#L2179-L2188 | train |
doctrine/dbal | lib/Doctrine/DBAL/Platforms/AbstractPlatform.php | AbstractPlatform.getColumnDeclarationSQL | 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;
} | php | 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;
} | [
"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.
@param string $name The name the field to be declared.
@param mixed[] $field An associative array with the name of the properties
of the field being declared as array indexes. Currently, the types
of supported field properties are as follows:
length
Integer value that determines the maximum length of the text
field. If this argument is missing the field should be
declared to have the longest length allowed by the DBMS.
default
Text value to be used as default for this field.
notnull
Boolean flag that indicates whether this field is constrained
to not be set to null.
charset
Text value with the default CHARACTER SET for this field.
collation
Text value with the default COLLATION for this field.
unique
unique constraint
check
column check constraint
columnDefinition
a string that defines the complete column
@return string DBMS specific SQL code portion that should be used to declare the column. | [
"Obtains",
"DBMS",
"specific",
"SQL",
"code",
"portion",
"needed",
"to",
"declare",
"a",
"generic",
"type",
"field",
"to",
"be",
"used",
"in",
"statements",
"like",
"CREATE",
"TABLE",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php#L2223-L2253 | train |
doctrine/dbal | lib/Doctrine/DBAL/Platforms/AbstractPlatform.php | AbstractPlatform.getDecimalTypeDeclarationSQL | 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'] . ')';
} | php | 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'] . ')';
} | [
"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.
@param mixed[] $columnDef
@return string | [
"Returns",
"the",
"SQL",
"snippet",
"that",
"declares",
"a",
"floating",
"point",
"column",
"of",
"arbitrary",
"precision",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php#L2262-L2270 | train |
doctrine/dbal | lib/Doctrine/DBAL/Platforms/AbstractPlatform.php | AbstractPlatform.getDefaultValueDeclarationSQL | 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);
} | php | 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);
} | [
"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.
@param mixed[] $field The field definition array.
@return string DBMS specific SQL code portion needed to set a default value. | [
"Obtains",
"DBMS",
"specific",
"SQL",
"code",
"portion",
"needed",
"to",
"set",
"a",
"default",
"value",
"declaration",
"to",
"be",
"used",
"in",
"statements",
"like",
"CREATE",
"TABLE",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php#L2280-L2315 | train |
doctrine/dbal | lib/Doctrine/DBAL/Platforms/AbstractPlatform.php | AbstractPlatform.getCheckDeclarationSQL | 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);
} | php | 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);
} | [
"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.
@param string[]|mixed[][] $definition The check definition.
@return string DBMS specific SQL code portion needed to set a CHECK constraint. | [
"Obtains",
"DBMS",
"specific",
"SQL",
"code",
"portion",
"needed",
"to",
"set",
"a",
"CHECK",
"constraint",
"declaration",
"to",
"be",
"used",
"in",
"statements",
"like",
"CREATE",
"TABLE",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php#L2325-L2343 | train |
doctrine/dbal | lib/Doctrine/DBAL/Platforms/AbstractPlatform.php | AbstractPlatform.getUniqueConstraintDeclarationSQL | 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);
} | php | 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);
} | [
"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.
@param string $name The name of the unique constraint.
@param Index $index The index definition.
@return string DBMS specific SQL code portion needed to set a constraint.
@throws InvalidArgumentException | [
"Obtains",
"DBMS",
"specific",
"SQL",
"code",
"portion",
"needed",
"to",
"set",
"a",
"unique",
"constraint",
"declaration",
"to",
"be",
"used",
"in",
"statements",
"like",
"CREATE",
"TABLE",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php#L2356-L2368 | train |
doctrine/dbal | lib/Doctrine/DBAL/Platforms/AbstractPlatform.php | AbstractPlatform.getIndexFieldDeclarationListSQL | 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);
} | php | 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);
} | [
"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.
@param mixed[]|Index $columnsOrIndex array declaration is deprecated, prefer passing Index to this method | [
"Obtains",
"DBMS",
"specific",
"SQL",
"code",
"portion",
"needed",
"to",
"set",
"an",
"index",
"declaration",
"to",
"be",
"used",
"in",
"statements",
"like",
"CREATE",
"TABLE",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php#L2415-L2436 | train |
doctrine/dbal | lib/Doctrine/DBAL/Platforms/AbstractPlatform.php | AbstractPlatform.getForeignKeyDeclarationSQL | public function getForeignKeyDeclarationSQL(ForeignKeyConstraint $foreignKey)
{
$sql = $this->getForeignKeyBaseDeclarationSQL($foreignKey);
$sql .= $this->getAdvancedForeignKeyOptionsSQL($foreignKey);
return $sql;
} | php | public function getForeignKeyDeclarationSQL(ForeignKeyConstraint $foreignKey)
{
$sql = $this->getForeignKeyBaseDeclarationSQL($foreignKey);
$sql .= $this->getAdvancedForeignKeyOptionsSQL($foreignKey);
return $sql;
} | [
"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.
@return string DBMS specific SQL code portion needed to set the FOREIGN KEY constraint
of a field declaration. | [
"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",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php#L2476-L2482 | train |
doctrine/dbal | lib/Doctrine/DBAL/Platforms/AbstractPlatform.php | AbstractPlatform.getAdvancedForeignKeyOptionsSQL | 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;
} | php | 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;
} | [
"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, ...
@param ForeignKeyConstraint $foreignKey The foreign key definition.
@return string | [
"Returns",
"the",
"FOREIGN",
"KEY",
"query",
"section",
"dealing",
"with",
"non",
"-",
"standard",
"options",
"as",
"MATCH",
"INITIALLY",
"DEFERRED",
"ON",
"UPDATE",
"..."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php#L2492-L2503 | train |
doctrine/dbal | lib/Doctrine/DBAL/Platforms/AbstractPlatform.php | AbstractPlatform.getForeignKeyBaseDeclarationSQL | 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)) . ')';
} | php | 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)) . ')';
} | [
"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.
@return string
@throws InvalidArgumentException | [
"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",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php#L2537-L2559 | train |
doctrine/dbal | lib/Doctrine/DBAL/Platforms/AbstractPlatform.php | AbstractPlatform.convertBooleans | 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;
} | php | 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;
} | [
"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.
The default conversion in this implementation converts to integers (false => 0, true => 1).
Note: if the input is not a boolean the original input might be returned.
There are two contexts when converting booleans: Literals and Prepared Statements.
This method should handle the literal case
@param mixed $item A boolean or an array of them.
@return mixed A boolean database value or an array of them. | [
"Some",
"platforms",
"need",
"the",
"boolean",
"values",
"to",
"be",
"converted",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php#L2637-L2652 | train |
doctrine/dbal | lib/Doctrine/DBAL/Platforms/AbstractPlatform.php | AbstractPlatform.modifyLimitQuery | 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);
} | php | 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);
} | [
"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.
@param string $query
@param int|null $limit
@param int|null $offset
@return string
@throws DBALException | [
"Adds",
"an",
"driver",
"-",
"specific",
"LIMIT",
"clause",
"to",
"the",
"query",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php#L3360-L3383 | train |
doctrine/dbal | lib/Doctrine/DBAL/Platforms/AbstractPlatform.php | AbstractPlatform.doModifyLimitQuery | protected function doModifyLimitQuery($query, $limit, $offset)
{
if ($limit !== null) {
$query .= ' LIMIT ' . $limit;
}
if ($offset > 0) {
$query .= ' OFFSET ' . $offset;
}
return $query;
} | php | protected function doModifyLimitQuery($query, $limit, $offset)
{
if ($limit !== null) {
$query .= ' LIMIT ' . $limit;
}
if ($offset > 0) {
$query .= ' OFFSET ' . $offset;
}
return $query;
} | [
"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.
@param string $query
@param int|null $limit
@param int|null $offset
@return string | [
"Adds",
"an",
"platform",
"-",
"specific",
"LIMIT",
"clause",
"to",
"the",
"query",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php#L3394-L3405 | train |
doctrine/dbal | lib/Doctrine/DBAL/Platforms/AbstractPlatform.php | AbstractPlatform.getReservedKeywordsList | final public function getReservedKeywordsList()
{
// Check for an existing instantiation of the keywords class.
if ($this->_keywords) {
return $this->_keywords;
}
$class = $this->getReservedKeywordsClass();
$keywords = new $class();
if (! $keywords instanceof KeywordList) {
throw DBALException::notSupported(__METHOD__);
}
// Store the instance so it doesn't need to be generated on every request.
$this->_keywords = $keywords;
return $keywords;
} | php | final public function getReservedKeywordsList()
{
// Check for an existing instantiation of the keywords class.
if ($this->_keywords) {
return $this->_keywords;
}
$class = $this->getReservedKeywordsClass();
$keywords = new $class();
if (! $keywords instanceof KeywordList) {
throw DBALException::notSupported(__METHOD__);
}
// Store the instance so it doesn't need to be generated on every request.
$this->_keywords = $keywords;
return $keywords;
} | [
"final",
"public",
"function",
"getReservedKeywordsList",
"(",
")",
"{",
"// Check for an existing instantiation of the keywords class.",
"if",
"(",
"$",
"this",
"->",
"_keywords",
")",
"{",
"return",
"$",
"this",
"->",
"_keywords",
";",
"}",
"$",
"class",
"=",
"$",
"this",
"->",
"getReservedKeywordsClass",
"(",
")",
";",
"$",
"keywords",
"=",
"new",
"$",
"class",
"(",
")",
";",
"if",
"(",
"!",
"$",
"keywords",
"instanceof",
"KeywordList",
")",
"{",
"throw",
"DBALException",
"::",
"notSupported",
"(",
"__METHOD__",
")",
";",
"}",
"// Store the instance so it doesn't need to be generated on every request.",
"$",
"this",
"->",
"_keywords",
"=",
"$",
"keywords",
";",
"return",
"$",
"keywords",
";",
"}"
]
| Returns the keyword list instance of this platform.
@return KeywordList
@throws DBALException If no keyword list is specified. | [
"Returns",
"the",
"keyword",
"list",
"instance",
"of",
"this",
"platform",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php#L3538-L3555 | train |
doctrine/dbal | lib/Doctrine/DBAL/Platforms/AbstractPlatform.php | AbstractPlatform.quoteStringLiteral | public function quoteStringLiteral($str)
{
$c = $this->getStringLiteralQuoteCharacter();
return $c . str_replace($c, $c . $c, $str) . $c;
} | php | public function quoteStringLiteral($str)
{
$c = $this->getStringLiteralQuoteCharacter();
return $c . str_replace($c, $c . $c, $str) . $c;
} | [
"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.
@param string $str The literal string to be quoted.
@return string The quoted literal string. | [
"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",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php#L3579-L3584 | train |
doctrine/dbal | lib/Doctrine/DBAL/Platforms/AbstractPlatform.php | AbstractPlatform.escapeStringForLike | final public function escapeStringForLike(string $inputString, string $escapeChar) : string
{
return preg_replace(
'~([' . preg_quote($this->getLikeWildcardCharacters() . $escapeChar, '~') . '])~u',
addcslashes($escapeChar, '\\') . '$1',
$inputString
);
} | php | final public function escapeStringForLike(string $inputString, string $escapeChar) : string
{
return preg_replace(
'~([' . preg_quote($this->getLikeWildcardCharacters() . $escapeChar, '~') . '])~u',
addcslashes($escapeChar, '\\') . '$1',
$inputString
);
} | [
"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.
@param string $inputString a literal, unquoted string
@param string $escapeChar should be reused by the caller in the LIKE
expression. | [
"Escapes",
"metacharacters",
"in",
"a",
"string",
"intended",
"to",
"be",
"used",
"with",
"a",
"LIKE",
"operator",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php#L3604-L3611 | train |
doctrine/dbal | lib/Doctrine/DBAL/DriverManager.php | DriverManager.getConnection | public static function getConnection(
array $params,
?Configuration $config = null,
?EventManager $eventManager = null
) : Connection {
// create default config and event manager, if not set
if (! $config) {
$config = new Configuration();
}
if (! $eventManager) {
$eventManager = new EventManager();
}
$params = self::parseDatabaseUrl($params);
// URL support for MasterSlaveConnection
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);
}
}
// URL support for PoolingShardConnection
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);
}
}
// check for existing pdo object
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);
} | php | public static function getConnection(
array $params,
?Configuration $config = null,
?EventManager $eventManager = null
) : Connection {
// create default config and event manager, if not set
if (! $config) {
$config = new Configuration();
}
if (! $eventManager) {
$eventManager = new EventManager();
}
$params = self::parseDatabaseUrl($params);
// URL support for MasterSlaveConnection
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);
}
}
// URL support for PoolingShardConnection
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);
}
}
// check for existing pdo object
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);
} | [
"public",
"static",
"function",
"getConnection",
"(",
"array",
"$",
"params",
",",
"?",
"Configuration",
"$",
"config",
"=",
"null",
",",
"?",
"EventManager",
"$",
"eventManager",
"=",
"null",
")",
":",
"Connection",
"{",
"// create default config and event manager, if not set",
"if",
"(",
"!",
"$",
"config",
")",
"{",
"$",
"config",
"=",
"new",
"Configuration",
"(",
")",
";",
"}",
"if",
"(",
"!",
"$",
"eventManager",
")",
"{",
"$",
"eventManager",
"=",
"new",
"EventManager",
"(",
")",
";",
"}",
"$",
"params",
"=",
"self",
"::",
"parseDatabaseUrl",
"(",
"$",
"params",
")",
";",
"// URL support for MasterSlaveConnection",
"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",
")",
";",
"}",
"}",
"// URL support for PoolingShardConnection",
"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",
")",
";",
"}",
"}",
"// check for existing pdo object",
"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.
$params must contain at least one of the following.
Either 'driver' with one of the following values:
pdo_mysql
pdo_sqlite
pdo_pgsql
pdo_oci (unstable)
pdo_sqlsrv
pdo_sqlsrv
mysqli
sqlanywhere
sqlsrv
ibm_db2 (unstable)
drizzle_pdo_mysql
OR 'driverClass' that contains the full class name (with namespace) of the
driver class to instantiate.
Other (optional) parameters:
<b>user (string)</b>:
The username to use when connecting.
<b>password (string)</b>:
The password to use when connecting.
<b>driverOptions (array)</b>:
Any additional driver-specific options for the driver. These are just passed
through to the driver.
<b>pdo</b>:
You can pass an existing PDO instance through this parameter. The PDO
instance will be wrapped in a Doctrine\DBAL\Connection.
<b>wrapperClass</b>:
You may specify a custom wrapper class through the 'wrapperClass'
parameter but this class MUST inherit from Doctrine\DBAL\Connection.
<b>driverClass</b>:
The driver class to use.
@param mixed[] $params The parameters.
@param Configuration|null $config The configuration to use.
@param EventManager|null $eventManager The event manager to use.
@throws DBALException | [
"Creates",
"a",
"connection",
"object",
"based",
"on",
"the",
"specified",
"parameters",
".",
"This",
"method",
"returns",
"a",
"Doctrine",
"\\",
"DBAL",
"\\",
"Connection",
"which",
"wraps",
"the",
"underlying",
"driver",
"connection",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/DriverManager.php#L137-L200 | train |
doctrine/dbal | lib/Doctrine/DBAL/DriverManager.php | DriverManager._checkParams | private static function _checkParams(array $params) : void
{
// check existence of mandatory parameters
// driver
if (! isset($params['driver']) && ! isset($params['driverClass'])) {
throw DBALException::driverRequired();
}
// check validity of parameters
// driver
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']);
}
} | php | private static function _checkParams(array $params) : void
{
// check existence of mandatory parameters
// driver
if (! isset($params['driver']) && ! isset($params['driverClass'])) {
throw DBALException::driverRequired();
}
// check validity of parameters
// driver
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']);
}
} | [
"private",
"static",
"function",
"_checkParams",
"(",
"array",
"$",
"params",
")",
":",
"void",
"{",
"// check existence of mandatory parameters",
"// driver",
"if",
"(",
"!",
"isset",
"(",
"$",
"params",
"[",
"'driver'",
"]",
")",
"&&",
"!",
"isset",
"(",
"$",
"params",
"[",
"'driverClass'",
"]",
")",
")",
"{",
"throw",
"DBALException",
"::",
"driverRequired",
"(",
")",
";",
"}",
"// check validity of parameters",
"// driver",
"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.
@param mixed[] $params The list of parameters.
@throws DBALException | [
"Checks",
"the",
"list",
"of",
"parameters",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/DriverManager.php#L219-L238 | train |
doctrine/dbal | lib/Doctrine/DBAL/DriverManager.php | DriverManager.parseDatabaseUrl | private static function parseDatabaseUrl(array $params) : array
{
if (! isset($params['url'])) {
return $params;
}
// (pdo_)?sqlite3?:///... => (pdo_)?sqlite3?://localhost/... or else the URL will be invalid
$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);
// If we have a connection URL, we have to unset the default PDO instance connection parameter (if any)
// as we cannot merge connection details from the URL into the PDO instance (URL takes precedence).
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;
} | php | private static function parseDatabaseUrl(array $params) : array
{
if (! isset($params['url'])) {
return $params;
}
// (pdo_)?sqlite3?:///... => (pdo_)?sqlite3?://localhost/... or else the URL will be invalid
$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);
// If we have a connection URL, we have to unset the default PDO instance connection parameter (if any)
// as we cannot merge connection details from the URL into the PDO instance (URL takes precedence).
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;
} | [
"private",
"static",
"function",
"parseDatabaseUrl",
"(",
"array",
"$",
"params",
")",
":",
"array",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"params",
"[",
"'url'",
"]",
")",
")",
"{",
"return",
"$",
"params",
";",
"}",
"// (pdo_)?sqlite3?:///... => (pdo_)?sqlite3?://localhost/... or else the URL will be invalid",
"$",
"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",
")",
";",
"// If we have a connection URL, we have to unset the default PDO instance connection parameter (if any)",
"// as we cannot merge connection details from the URL into the PDO instance (URL takes precedence).",
"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.
@param mixed[] $params The list of parameters.
@return mixed[] A modified list of parameters with info from a database
URL extracted into indidivual parameter parts.
@throws DBALException | [
"Extracts",
"parts",
"from",
"a",
"database",
"URL",
"if",
"present",
"and",
"returns",
"an",
"updated",
"list",
"of",
"parameters",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/DriverManager.php#L262-L303 | train |
doctrine/dbal | lib/Doctrine/DBAL/DriverManager.php | DriverManager.parseDatabaseUrlPath | private static function parseDatabaseUrlPath(array $url, array $params) : array
{
if (! isset($url['path'])) {
return $params;
}
$url['path'] = self::normalizeDatabaseUrlPath($url['path']);
// If we do not have a known DBAL driver, we do not know any connection URL path semantics to evaluate
// and therefore treat the path as regular DBAL connection 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);
} | php | private static function parseDatabaseUrlPath(array $url, array $params) : array
{
if (! isset($url['path'])) {
return $params;
}
$url['path'] = self::normalizeDatabaseUrlPath($url['path']);
// If we do not have a known DBAL driver, we do not know any connection URL path semantics to evaluate
// and therefore treat the path as regular DBAL connection 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);
} | [
"private",
"static",
"function",
"parseDatabaseUrlPath",
"(",
"array",
"$",
"url",
",",
"array",
"$",
"params",
")",
":",
"array",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"url",
"[",
"'path'",
"]",
")",
")",
"{",
"return",
"$",
"params",
";",
"}",
"$",
"url",
"[",
"'path'",
"]",
"=",
"self",
"::",
"normalizeDatabaseUrlPath",
"(",
"$",
"url",
"[",
"'path'",
"]",
")",
";",
"// If we do not have a known DBAL driver, we do not know any connection URL path semantics to evaluate",
"// and therefore treat the path as regular DBAL connection 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.
Assumes that the connection URL scheme is already parsed and resolved into the given connection parameters
via {@link parseDatabaseUrlScheme}.
@see parseDatabaseUrlScheme
@param mixed[] $url The URL parts to evaluate.
@param mixed[] $params The connection parameters to resolve.
@return mixed[] The resolved connection parameters. | [
"Parses",
"the",
"given",
"connection",
"URL",
"and",
"resolves",
"the",
"given",
"connection",
"parameters",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/DriverManager.php#L318-L337 | train |
doctrine/dbal | lib/Doctrine/DBAL/DriverManager.php | DriverManager.parseDatabaseUrlQuery | private static function parseDatabaseUrlQuery(array $url, array $params) : array
{
if (! isset($url['query'])) {
return $params;
}
$query = [];
parse_str($url['query'], $query); // simply ingest query as extra params, e.g. charset or sslmode
return array_merge($params, $query); // parse_str wipes existing array elements
} | php | private static function parseDatabaseUrlQuery(array $url, array $params) : array
{
if (! isset($url['query'])) {
return $params;
}
$query = [];
parse_str($url['query'], $query); // simply ingest query as extra params, e.g. charset or sslmode
return array_merge($params, $query); // parse_str wipes existing array elements
} | [
"private",
"static",
"function",
"parseDatabaseUrlQuery",
"(",
"array",
"$",
"url",
",",
"array",
"$",
"params",
")",
":",
"array",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"url",
"[",
"'query'",
"]",
")",
")",
"{",
"return",
"$",
"params",
";",
"}",
"$",
"query",
"=",
"[",
"]",
";",
"parse_str",
"(",
"$",
"url",
"[",
"'query'",
"]",
",",
"$",
"query",
")",
";",
"// simply ingest query as extra params, e.g. charset or sslmode",
"return",
"array_merge",
"(",
"$",
"params",
",",
"$",
"query",
")",
";",
"// parse_str wipes existing array elements",
"}"
]
| Parses the query part of the given connection URL and resolves the given connection parameters.
@param mixed[] $url The connection URL parts to evaluate.
@param mixed[] $params The connection parameters to resolve.
@return mixed[] The resolved connection parameters. | [
"Parses",
"the",
"query",
"part",
"of",
"the",
"given",
"connection",
"URL",
"and",
"resolves",
"the",
"given",
"connection",
"parameters",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/DriverManager.php#L347-L358 | train |
doctrine/dbal | lib/Doctrine/DBAL/DriverManager.php | DriverManager.parseSqliteDatabaseUrlPath | private static function parseSqliteDatabaseUrlPath(array $url, array $params) : array
{
if ($url['path'] === ':memory:') {
$params['memory'] = true;
return $params;
}
$params['path'] = $url['path']; // pdo_sqlite driver uses 'path' instead of 'dbname' key
return $params;
} | php | private static function parseSqliteDatabaseUrlPath(array $url, array $params) : array
{
if ($url['path'] === ':memory:') {
$params['memory'] = true;
return $params;
}
$params['path'] = $url['path']; // pdo_sqlite driver uses 'path' instead of 'dbname' key
return $params;
} | [
"private",
"static",
"function",
"parseSqliteDatabaseUrlPath",
"(",
"array",
"$",
"url",
",",
"array",
"$",
"params",
")",
":",
"array",
"{",
"if",
"(",
"$",
"url",
"[",
"'path'",
"]",
"===",
"':memory:'",
")",
"{",
"$",
"params",
"[",
"'memory'",
"]",
"=",
"true",
";",
"return",
"$",
"params",
";",
"}",
"$",
"params",
"[",
"'path'",
"]",
"=",
"$",
"url",
"[",
"'path'",
"]",
";",
"// pdo_sqlite driver uses 'path' instead of 'dbname' key",
"return",
"$",
"params",
";",
"}"
]
| Parses the given SQLite connection URL and resolves the given connection parameters.
Assumes that the "path" URL part is already normalized via {@link normalizeDatabaseUrlPath}.
@see normalizeDatabaseUrlPath
@param mixed[] $url The SQLite connection URL parts to evaluate.
@param mixed[] $params The connection parameters to resolve.
@return mixed[] The resolved connection parameters. | [
"Parses",
"the",
"given",
"SQLite",
"connection",
"URL",
"and",
"resolves",
"the",
"given",
"connection",
"parameters",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/DriverManager.php#L391-L402 | train |
doctrine/dbal | lib/Doctrine/DBAL/DriverManager.php | DriverManager.parseDatabaseUrlScheme | private static function parseDatabaseUrlScheme(array $url, array $params) : array
{
if (isset($url['scheme'])) {
// The requested driver from the URL scheme takes precedence
// over the default custom driver from the connection parameters (if any).
unset($params['driverClass']);
// URL schemes must not contain underscores, but dashes are ok
$driver = str_replace('-', '_', $url['scheme']);
assert(is_string($driver));
// The requested driver from the URL scheme takes precedence over the
// default driver from the connection parameters. If the driver is
// an alias (e.g. "postgres"), map it to the actual name ("pdo-pgsql").
// Otherwise, let checkParams decide later if the driver exists.
$params['driver'] = self::$driverSchemeAliases[$driver] ?? $driver;
return $params;
}
// If a schemeless connection URL is given, we require a default driver or default custom driver
// as connection parameter.
if (! isset($params['driverClass']) && ! isset($params['driver'])) {
throw DBALException::driverRequired($params['url']);
}
return $params;
} | php | private static function parseDatabaseUrlScheme(array $url, array $params) : array
{
if (isset($url['scheme'])) {
// The requested driver from the URL scheme takes precedence
// over the default custom driver from the connection parameters (if any).
unset($params['driverClass']);
// URL schemes must not contain underscores, but dashes are ok
$driver = str_replace('-', '_', $url['scheme']);
assert(is_string($driver));
// The requested driver from the URL scheme takes precedence over the
// default driver from the connection parameters. If the driver is
// an alias (e.g. "postgres"), map it to the actual name ("pdo-pgsql").
// Otherwise, let checkParams decide later if the driver exists.
$params['driver'] = self::$driverSchemeAliases[$driver] ?? $driver;
return $params;
}
// If a schemeless connection URL is given, we require a default driver or default custom driver
// as connection parameter.
if (! isset($params['driverClass']) && ! isset($params['driver'])) {
throw DBALException::driverRequired($params['url']);
}
return $params;
} | [
"private",
"static",
"function",
"parseDatabaseUrlScheme",
"(",
"array",
"$",
"url",
",",
"array",
"$",
"params",
")",
":",
"array",
"{",
"if",
"(",
"isset",
"(",
"$",
"url",
"[",
"'scheme'",
"]",
")",
")",
"{",
"// The requested driver from the URL scheme takes precedence",
"// over the default custom driver from the connection parameters (if any).",
"unset",
"(",
"$",
"params",
"[",
"'driverClass'",
"]",
")",
";",
"// URL schemes must not contain underscores, but dashes are ok",
"$",
"driver",
"=",
"str_replace",
"(",
"'-'",
",",
"'_'",
",",
"$",
"url",
"[",
"'scheme'",
"]",
")",
";",
"assert",
"(",
"is_string",
"(",
"$",
"driver",
")",
")",
";",
"// The requested driver from the URL scheme takes precedence over the",
"// default driver from the connection parameters. If the driver is",
"// an alias (e.g. \"postgres\"), map it to the actual name (\"pdo-pgsql\").",
"// Otherwise, let checkParams decide later if the driver exists.",
"$",
"params",
"[",
"'driver'",
"]",
"=",
"self",
"::",
"$",
"driverSchemeAliases",
"[",
"$",
"driver",
"]",
"??",
"$",
"driver",
";",
"return",
"$",
"params",
";",
"}",
"// If a schemeless connection URL is given, we require a default driver or default custom driver",
"// as connection parameter.",
"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.
@param mixed[] $url The connection URL parts to evaluate.
@param mixed[] $params The connection parameters to resolve.
@return mixed[] The resolved connection parameters.
@throws DBALException If parsing failed or resolution is not possible. | [
"Parses",
"the",
"scheme",
"part",
"from",
"given",
"connection",
"URL",
"and",
"resolves",
"the",
"given",
"connection",
"parameters",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/DriverManager.php#L414-L441 | train |
doctrine/dbal | lib/Doctrine/DBAL/Schema/OracleSchemaManager.php | OracleSchemaManager.killUserSessions | private function killUserSessions($user)
{
$sql = <<<SQL
SELECT
s.sid,
s.serial#
FROM
gv\$session s,
gv\$process p
WHERE
s.username = ?
AND p.addr(+) = s.paddr
SQL;
$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#']
)
);
}
} | php | private function killUserSessions($user)
{
$sql = <<<SQL
SELECT
s.sid,
s.serial#
FROM
gv\$session s,
gv\$process p
WHERE
s.username = ?
AND p.addr(+) = s.paddr
SQL;
$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#']
)
);
}
} | [
"private",
"function",
"killUserSessions",
"(",
"$",
"user",
")",
"{",
"$",
"sql",
"=",
" <<<SQL\nSELECT\n s.sid,\n s.serial#\nFROM\n gv\\$session s,\n gv\\$process p\nWHERE\n s.username = ?\n AND p.addr(+) = s.paddr\nSQL",
";",
"$",
"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.
This is useful to force DROP USER operations which could fail because of active user sessions.
@param string $user The name of the user to kill sessions for.
@return void | [
"Kills",
"sessions",
"connected",
"with",
"the",
"given",
"user",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Schema/OracleSchemaManager.php#L360-L387 | train |
doctrine/dbal | lib/Doctrine/DBAL/Driver/PDOIbm/Driver.php | Driver._constructPdoDsn | 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;
} | php | 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;
} | [
"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.
@param mixed[] $params
@return string The DSN. | [
"Constructs",
"the",
"IBM",
"PDO",
"DSN",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Driver/PDOIbm/Driver.php#L33-L48 | train |
doctrine/dbal | lib/Doctrine/DBAL/Schema/Visitor/CreateSchemaSqlCollector.php | CreateSchemaSqlCollector.getQueries | public function getQueries()
{
return array_merge(
$this->createNamespaceQueries,
$this->createTableQueries,
$this->createSequenceQueries,
$this->createFkConstraintQueries
);
} | php | public function getQueries()
{
return array_merge(
$this->createNamespaceQueries,
$this->createTableQueries,
$this->createSequenceQueries,
$this->createFkConstraintQueries
);
} | [
"public",
"function",
"getQueries",
"(",
")",
"{",
"return",
"array_merge",
"(",
"$",
"this",
"->",
"createNamespaceQueries",
",",
"$",
"this",
"->",
"createTableQueries",
",",
"$",
"this",
"->",
"createSequenceQueries",
",",
"$",
"this",
"->",
"createFkConstraintQueries",
")",
";",
"}"
]
| Gets all queries collected so far.
@return string[] | [
"Gets",
"all",
"queries",
"collected",
"so",
"far",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Schema/Visitor/CreateSchemaSqlCollector.php#L89-L97 | train |
doctrine/dbal | lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvException.php | SQLSrvException.fromSqlSrvErrors | 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);
} | php | 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);
} | [
"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.
@return \Doctrine\DBAL\Driver\SQLSrv\SQLSrvException | [
"Helper",
"method",
"to",
"turn",
"sql",
"server",
"errors",
"into",
"exception",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvException.php#L17-L42 | train |
doctrine/dbal | lib/Doctrine/DBAL/Platforms/MySqlPlatform.php | MySqlPlatform.getRemainingForeignKeyConstraintsRequiringRenamedIndexes | private function getRemainingForeignKeyConstraintsRequiringRenamedIndexes(TableDiff $diff)
{
if (empty($diff->renamedIndexes) || ! $diff->fromTable instanceof Table) {
return [];
}
$foreignKeys = [];
/** @var ForeignKeyConstraint[] $remainingForeignKeys */
$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;
} | php | private function getRemainingForeignKeyConstraintsRequiringRenamedIndexes(TableDiff $diff)
{
if (empty($diff->renamedIndexes) || ! $diff->fromTable instanceof Table) {
return [];
}
$foreignKeys = [];
/** @var ForeignKeyConstraint[] $remainingForeignKeys */
$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;
} | [
"private",
"function",
"getRemainingForeignKeyConstraintsRequiringRenamedIndexes",
"(",
"TableDiff",
"$",
"diff",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"diff",
"->",
"renamedIndexes",
")",
"||",
"!",
"$",
"diff",
"->",
"fromTable",
"instanceof",
"Table",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"foreignKeys",
"=",
"[",
"]",
";",
"/** @var ForeignKeyConstraint[] $remainingForeignKeys */",
"$",
"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.
"Remaining" here refers to the diff between the foreign keys currently defined in the associated
table and the foreign keys to be removed.
@param TableDiff $diff The table diff to evaluate.
@return ForeignKeyConstraint[] | [
"Returns",
"the",
"remaining",
"foreign",
"key",
"constraints",
"that",
"require",
"one",
"of",
"the",
"renamed",
"indexes",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php#L816-L840 | train |
doctrine/dbal | lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php | SQLSrvStatement.prepare | 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;
} | php | 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;
} | [
"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
@return resource
@throws SQLSrvException | [
"Prepares",
"SQL",
"Server",
"statement",
"resource"
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php#L273-L309 | train |
doctrine/dbal | lib/Doctrine/DBAL/Types/ConversionException.php | ConversionException.conversionFailed | 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);
} | php | 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);
} | [
"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.
@param string $value
@param string $toType
@return \Doctrine\DBAL\Types\ConversionException | [
"Thrown",
"when",
"a",
"Database",
"to",
"Doctrine",
"Type",
"Conversion",
"fails",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Types/ConversionException.php#L29-L34 | train |
doctrine/dbal | lib/Doctrine/DBAL/Types/ConversionException.php | ConversionException.conversionFailedFormat | 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
);
} | php | 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
);
} | [
"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.
@param string $value
@param string $toType
@param string $expectedFormat
@return \Doctrine\DBAL\Types\ConversionException | [
"Thrown",
"when",
"a",
"Database",
"to",
"Doctrine",
"Type",
"Conversion",
"fails",
"and",
"we",
"can",
"make",
"a",
"statement",
"about",
"the",
"expected",
"format",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Types/ConversionException.php#L46-L56 | train |
doctrine/dbal | lib/Doctrine/DBAL/Configuration.php | Configuration.setFilterSchemaAssetsExpression | public function setFilterSchemaAssetsExpression($filterExpression)
{
$this->_attributes['filterSchemaAssetsExpression'] = $filterExpression;
if ($filterExpression) {
$this->_attributes['filterSchemaAssetsExpressionCallable'] = $this->buildSchemaAssetsFilterFromExpression($filterExpression);
} else {
$this->_attributes['filterSchemaAssetsExpressionCallable'] = null;
}
} | php | public function setFilterSchemaAssetsExpression($filterExpression)
{
$this->_attributes['filterSchemaAssetsExpression'] = $filterExpression;
if ($filterExpression) {
$this->_attributes['filterSchemaAssetsExpressionCallable'] = $this->buildSchemaAssetsFilterFromExpression($filterExpression);
} else {
$this->_attributes['filterSchemaAssetsExpressionCallable'] = null;
}
} | [
"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.
Only include tables/sequences matching the filter expression regexp in
schema instances generated for the active connection when calling
{AbstractSchemaManager#createSchema()}.
@deprecated Use Configuration::setSchemaAssetsFilter() instead
@param string $filterExpression
@return void | [
"Sets",
"the",
"filter",
"schema",
"assets",
"expression",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Configuration.php#L79-L87 | train |
doctrine/dbal | lib/Doctrine/DBAL/Schema/Index.php | Index.spansColumns | 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;
} | php | 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;
} | [
"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.
@param string[] $columnNames
@return bool | [
"Checks",
"if",
"this",
"index",
"exactly",
"spans",
"the",
"given",
"column",
"names",
"in",
"the",
"correct",
"order",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Schema/Index.php#L177-L192 | train |
doctrine/dbal | lib/Doctrine/DBAL/Schema/Index.php | Index.isFullfilledBy | public function isFullfilledBy(Index $other)
{
// allow the other index to be equally large only. It being larger is an option
// but it creates a problem with scenarios of the kind PRIMARY KEY(foo,bar) UNIQUE(foo)
if (count($other->getColumns()) !== count($this->getColumns())) {
return false;
}
// Check if columns are the same, and even in the same order
$sameColumns = $this->spansColumns($other->getColumns());
if ($sameColumns) {
if (! $this->samePartialIndex($other)) {
return false;
}
if (! $this->hasSameColumnLengths($other)) {
return false;
}
if (! $this->isUnique() && ! $this->isPrimary()) {
// this is a special case: If the current key is neither primary or unique, any unique or
// primary key will always have the same effect for the index and there cannot be any constraint
// overlaps. This means a primary or unique index can always fulfill the requirements of just an
// index that has no constraints.
return true;
}
if ($other->isPrimary() !== $this->isPrimary()) {
return false;
}
return $other->isUnique() === $this->isUnique();
}
return false;
} | php | public function isFullfilledBy(Index $other)
{
// allow the other index to be equally large only. It being larger is an option
// but it creates a problem with scenarios of the kind PRIMARY KEY(foo,bar) UNIQUE(foo)
if (count($other->getColumns()) !== count($this->getColumns())) {
return false;
}
// Check if columns are the same, and even in the same order
$sameColumns = $this->spansColumns($other->getColumns());
if ($sameColumns) {
if (! $this->samePartialIndex($other)) {
return false;
}
if (! $this->hasSameColumnLengths($other)) {
return false;
}
if (! $this->isUnique() && ! $this->isPrimary()) {
// this is a special case: If the current key is neither primary or unique, any unique or
// primary key will always have the same effect for the index and there cannot be any constraint
// overlaps. This means a primary or unique index can always fulfill the requirements of just an
// index that has no constraints.
return true;
}
if ($other->isPrimary() !== $this->isPrimary()) {
return false;
}
return $other->isUnique() === $this->isUnique();
}
return false;
} | [
"public",
"function",
"isFullfilledBy",
"(",
"Index",
"$",
"other",
")",
"{",
"// allow the other index to be equally large only. It being larger is an option",
"// but it creates a problem with scenarios of the kind PRIMARY KEY(foo,bar) UNIQUE(foo)",
"if",
"(",
"count",
"(",
"$",
"other",
"->",
"getColumns",
"(",
")",
")",
"!==",
"count",
"(",
"$",
"this",
"->",
"getColumns",
"(",
")",
")",
")",
"{",
"return",
"false",
";",
"}",
"// Check if columns are the same, and even in the same order",
"$",
"sameColumns",
"=",
"$",
"this",
"->",
"spansColumns",
"(",
"$",
"other",
"->",
"getColumns",
"(",
")",
")",
";",
"if",
"(",
"$",
"sameColumns",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"samePartialIndex",
"(",
"$",
"other",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"hasSameColumnLengths",
"(",
"$",
"other",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"isUnique",
"(",
")",
"&&",
"!",
"$",
"this",
"->",
"isPrimary",
"(",
")",
")",
"{",
"// this is a special case: If the current key is neither primary or unique, any unique or",
"// primary key will always have the same effect for the index and there cannot be any constraint",
"// overlaps. This means a primary or unique index can always fulfill the requirements of just an",
"// index that has no constraints.",
"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.
@return bool | [
"Checks",
"if",
"the",
"other",
"index",
"already",
"fulfills",
"all",
"the",
"indexing",
"and",
"constraint",
"needs",
"of",
"the",
"current",
"one",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Schema/Index.php#L199-L235 | train |
doctrine/dbal | lib/Doctrine/DBAL/Schema/Index.php | Index.overrules | 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);
} | php | 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);
} | [
"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.
@return bool | [
"Detects",
"if",
"the",
"other",
"index",
"is",
"a",
"non",
"-",
"unique",
"non",
"primary",
"index",
"that",
"can",
"be",
"overwritten",
"by",
"this",
"one",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Schema/Index.php#L242-L253 | train |
doctrine/dbal | lib/Doctrine/DBAL/Schema/Index.php | Index.samePartialIndex | 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');
} | php | 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');
} | [
"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
@return bool | [
"Return",
"whether",
"the",
"two",
"indexes",
"have",
"the",
"same",
"partial",
"index"
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Schema/Index.php#L338-L345 | train |
doctrine/dbal | lib/Doctrine/DBAL/Schema/Index.php | Index.hasSameColumnLengths | 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);
} | php | 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);
} | [
"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 | [
"Returns",
"whether",
"the",
"index",
"has",
"the",
"same",
"column",
"lengths",
"as",
"the",
"other"
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Schema/Index.php#L350-L358 | train |
doctrine/dbal | lib/Doctrine/DBAL/Platforms/OraclePlatform.php | OraclePlatform.getSequenceCacheSQL | 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 '';
} | php | 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 '';
} | [
"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
@return string | [
"Cache",
"definition",
"for",
"sequences"
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Platforms/OraclePlatform.php#L200-L215 | train |
doctrine/dbal | lib/Doctrine/DBAL/Platforms/OraclePlatform.php | OraclePlatform.getDropAutoincrementSql | 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)),
];
} | php | 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)),
];
} | [
"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.
@param string $table The table name to drop the autoincrement for.
@return string[] | [
"Returns",
"the",
"SQL",
"statements",
"to",
"drop",
"the",
"autoincrement",
"for",
"the",
"given",
"table",
"name",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Platforms/OraclePlatform.php#L549-L563 | train |
doctrine/dbal | lib/Doctrine/DBAL/Platforms/OraclePlatform.php | OraclePlatform.normalizeIdentifier | private function normalizeIdentifier($name)
{
$identifier = new Identifier($name);
return $identifier->isQuoted() ? $identifier : new Identifier(strtoupper($name));
} | php | private function normalizeIdentifier($name)
{
$identifier = new Identifier($name);
return $identifier->isQuoted() ? $identifier : new Identifier(strtoupper($name));
} | [
"private",
"function",
"normalizeIdentifier",
"(",
"$",
"name",
")",
"{",
"$",
"identifier",
"=",
"new",
"Identifier",
"(",
"$",
"name",
")",
";",
"return",
"$",
"identifier",
"->",
"isQuoted",
"(",
")",
"?",
"$",
"identifier",
":",
"new",
"Identifier",
"(",
"strtoupper",
"(",
"$",
"name",
")",
")",
";",
"}"
]
| Normalizes the given identifier.
Uppercases the given identifier if it is not quoted by intention
to reflect Oracle's internal auto uppercasing strategy of unquoted identifiers.
@param string $name The identifier to normalize.
@return Identifier The normalized identifier. | [
"Normalizes",
"the",
"given",
"identifier",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Platforms/OraclePlatform.php#L575-L580 | train |
doctrine/dbal | lib/Doctrine/DBAL/Platforms/OraclePlatform.php | OraclePlatform.getAutoincrementIdentifierName | private function getAutoincrementIdentifierName(Identifier $table)
{
$identifierName = $table->getName() . '_AI_PK';
return $table->isQuoted()
? $this->quoteSingleIdentifier($identifierName)
: $identifierName;
} | php | private function getAutoincrementIdentifierName(Identifier $table)
{
$identifierName = $table->getName() . '_AI_PK';
return $table->isQuoted()
? $this->quoteSingleIdentifier($identifierName)
: $identifierName;
} | [
"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.
Quotes the autoincrement primary key identifier name
if the given table name is quoted by intention.
@param Identifier $table The table identifier to return the autoincrement primary key identifier name for.
@return string | [
"Returns",
"the",
"autoincrement",
"primary",
"key",
"identifier",
"name",
"for",
"the",
"given",
"table",
"identifier",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Platforms/OraclePlatform.php#L592-L599 | train |
doctrine/dbal | lib/Doctrine/DBAL/Schema/Table.php | Table.setPrimaryKey | 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;
} | php | 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;
} | [
"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.
@param string[] $columnNames
@param string|false $indexName
@return self | [
"Sets",
"the",
"Primary",
"Key",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Schema/Table.php#L103-L113 | train |
doctrine/dbal | lib/Doctrine/DBAL/Schema/Table.php | Table.columnsAreIndexed | public function columnsAreIndexed(array $columnNames)
{
foreach ($this->getIndexes() as $index) {
/** @var $index Index */
if ($index->spansColumns($columnNames)) {
return true;
}
}
return false;
} | php | public function columnsAreIndexed(array $columnNames)
{
foreach ($this->getIndexes() as $index) {
/** @var $index Index */
if ($index->spansColumns($columnNames)) {
return true;
}
}
return false;
} | [
"public",
"function",
"columnsAreIndexed",
"(",
"array",
"$",
"columnNames",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"getIndexes",
"(",
")",
"as",
"$",
"index",
")",
"{",
"/** @var $index Index */",
"if",
"(",
"$",
"index",
"->",
"spansColumns",
"(",
"$",
"columnNames",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
]
| Checks if an index begins in the order of the given columns.
@param string[] $columnNames
@return bool | [
"Checks",
"if",
"an",
"index",
"begins",
"in",
"the",
"order",
"of",
"the",
"given",
"columns",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Schema/Table.php#L238-L248 | train |
doctrine/dbal | lib/Doctrine/DBAL/Schema/Table.php | Table.changeColumn | public function changeColumn($columnName, array $options)
{
$column = $this->getColumn($columnName);
$column->setOptions($options);
return $this;
} | php | public function changeColumn($columnName, array $options)
{
$column = $this->getColumn($columnName);
$column->setOptions($options);
return $this;
} | [
"public",
"function",
"changeColumn",
"(",
"$",
"columnName",
",",
"array",
"$",
"options",
")",
"{",
"$",
"column",
"=",
"$",
"this",
"->",
"getColumn",
"(",
"$",
"columnName",
")",
";",
"$",
"column",
"->",
"setOptions",
"(",
"$",
"options",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Change Column Details.
@param string $columnName
@param mixed[] $options
@return self | [
"Change",
"Column",
"Details",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Schema/Table.php#L318-L324 | train |
doctrine/dbal | lib/Doctrine/DBAL/Schema/Table.php | Table.dropColumn | public function dropColumn($columnName)
{
$columnName = $this->normalizeIdentifier($columnName);
unset($this->_columns[$columnName]);
return $this;
} | php | public function dropColumn($columnName)
{
$columnName = $this->normalizeIdentifier($columnName);
unset($this->_columns[$columnName]);
return $this;
} | [
"public",
"function",
"dropColumn",
"(",
"$",
"columnName",
")",
"{",
"$",
"columnName",
"=",
"$",
"this",
"->",
"normalizeIdentifier",
"(",
"$",
"columnName",
")",
";",
"unset",
"(",
"$",
"this",
"->",
"_columns",
"[",
"$",
"columnName",
"]",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Drops a Column from the Table.
@param string $columnName
@return self | [
"Drops",
"a",
"Column",
"from",
"the",
"Table",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Schema/Table.php#L333-L339 | train |
doctrine/dbal | lib/Doctrine/DBAL/Schema/Table.php | Table.addNamedForeignKeyConstraint | 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;
} | php | 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;
} | [
"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.
@deprecated Use {@link addForeignKeyConstraint}
@param string $name
@param Table|string $foreignTable Table schema instance or table name
@param string[] $localColumnNames
@param string[] $foreignColumnNames
@param mixed[] $options
@return self
@throws SchemaException | [
"Adds",
"a",
"foreign",
"key",
"constraint",
"with",
"a",
"given",
"name",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Schema/Table.php#L395-L421 | train |
doctrine/dbal | lib/Doctrine/DBAL/Schema/Table.php | Table.hasForeignKey | public function hasForeignKey($constraintName)
{
$constraintName = $this->normalizeIdentifier($constraintName);
return isset($this->_fkConstraints[$constraintName]);
} | php | public function hasForeignKey($constraintName)
{
$constraintName = $this->normalizeIdentifier($constraintName);
return isset($this->_fkConstraints[$constraintName]);
} | [
"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.
@param string $constraintName
@return bool | [
"Returns",
"whether",
"this",
"table",
"has",
"a",
"foreign",
"key",
"constraint",
"with",
"the",
"given",
"name",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Schema/Table.php#L540-L545 | train |
doctrine/dbal | lib/Doctrine/DBAL/Schema/Table.php | Table.getForeignKey | public function getForeignKey($constraintName)
{
$constraintName = $this->normalizeIdentifier($constraintName);
if (! $this->hasForeignKey($constraintName)) {
throw SchemaException::foreignKeyDoesNotExist($constraintName, $this->_name);
}
return $this->_fkConstraints[$constraintName];
} | php | public function getForeignKey($constraintName)
{
$constraintName = $this->normalizeIdentifier($constraintName);
if (! $this->hasForeignKey($constraintName)) {
throw SchemaException::foreignKeyDoesNotExist($constraintName, $this->_name);
}
return $this->_fkConstraints[$constraintName];
} | [
"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.
@param string $constraintName The constraint name.
@return ForeignKeyConstraint
@throws SchemaException If the foreign key does not exist. | [
"Returns",
"the",
"foreign",
"key",
"constraint",
"with",
"the",
"given",
"name",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Schema/Table.php#L556-L564 | train |
doctrine/dbal | lib/Doctrine/DBAL/Schema/Table.php | Table.getForeignKeyColumns | private function getForeignKeyColumns()
{
$foreignKeyColumns = [];
foreach ($this->getForeignKeys() as $foreignKey) {
$foreignKeyColumns = array_merge($foreignKeyColumns, $foreignKey->getColumns());
}
return $this->filterColumns($foreignKeyColumns);
} | php | private function getForeignKeyColumns()
{
$foreignKeyColumns = [];
foreach ($this->getForeignKeys() as $foreignKey) {
$foreignKeyColumns = array_merge($foreignKeyColumns, $foreignKey->getColumns());
}
return $this->filterColumns($foreignKeyColumns);
} | [
"private",
"function",
"getForeignKeyColumns",
"(",
")",
"{",
"$",
"foreignKeyColumns",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"getForeignKeys",
"(",
")",
"as",
"$",
"foreignKey",
")",
"{",
"$",
"foreignKeyColumns",
"=",
"array_merge",
"(",
"$",
"foreignKeyColumns",
",",
"$",
"foreignKey",
"->",
"getColumns",
"(",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"filterColumns",
"(",
"$",
"foreignKeyColumns",
")",
";",
"}"
]
| Returns foreign key columns
@return Column[] | [
"Returns",
"foreign",
"key",
"columns"
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Schema/Table.php#L607-L615 | train |
doctrine/dbal | lib/Doctrine/DBAL/Schema/Table.php | Table.filterColumns | 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);
} | php | 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);
} | [
"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
@param string[] $columnNames
@return Column[] | [
"Returns",
"only",
"columns",
"that",
"have",
"specified",
"names"
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Schema/Table.php#L624-L629 | train |
doctrine/dbal | lib/Doctrine/DBAL/Schema/Table.php | Table.hasColumn | public function hasColumn($columnName)
{
$columnName = $this->normalizeIdentifier($columnName);
return isset($this->_columns[$columnName]);
} | php | public function hasColumn($columnName)
{
$columnName = $this->normalizeIdentifier($columnName);
return isset($this->_columns[$columnName]);
} | [
"public",
"function",
"hasColumn",
"(",
"$",
"columnName",
")",
"{",
"$",
"columnName",
"=",
"$",
"this",
"->",
"normalizeIdentifier",
"(",
"$",
"columnName",
")",
";",
"return",
"isset",
"(",
"$",
"this",
"->",
"_columns",
"[",
"$",
"columnName",
"]",
")",
";",
"}"
]
| Returns whether this table has a Column with the given name.
@param string $columnName The column name.
@return bool | [
"Returns",
"whether",
"this",
"table",
"has",
"a",
"Column",
"with",
"the",
"given",
"name",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Schema/Table.php#L638-L643 | train |
doctrine/dbal | lib/Doctrine/DBAL/Schema/Table.php | Table.getColumn | public function getColumn($columnName)
{
$columnName = $this->normalizeIdentifier($columnName);
if (! $this->hasColumn($columnName)) {
throw SchemaException::columnDoesNotExist($columnName, $this->_name);
}
return $this->_columns[$columnName];
} | php | public function getColumn($columnName)
{
$columnName = $this->normalizeIdentifier($columnName);
if (! $this->hasColumn($columnName)) {
throw SchemaException::columnDoesNotExist($columnName, $this->_name);
}
return $this->_columns[$columnName];
} | [
"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.
@param string $columnName The column name.
@return Column
@throws SchemaException If the column does not exist. | [
"Returns",
"the",
"Column",
"with",
"the",
"given",
"name",
"."
]
| e4978c2299d4d8e4f39da94f4d567e698e9bdbeb | https://github.com/doctrine/dbal/blob/e4978c2299d4d8e4f39da94f4d567e698e9bdbeb/lib/Doctrine/DBAL/Schema/Table.php#L654-L662 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.