Final Class Yiisoft\Db\Oracle\Command
| Inheritance | Yiisoft\Db\Oracle\Command » Yiisoft\Db\Driver\Pdo\AbstractPdoCommand |
|---|
Implements a database command that can be executed against a PDO (PHP Data Object) database connection for Oracle Server.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| insertReturningPks() | Yiisoft\Db\Oracle\Command | |
| showDatabases() | Yiisoft\Db\Oracle\Command |
Protected Methods
| Method | Description | Defined By |
|---|---|---|
| bindPendingParams() | Yiisoft\Db\Oracle\Command |
Constants
| Constant | Value | Description | Defined By |
|---|---|---|---|
| INTEGER_COLUMN_TYPES | [ \Yiisoft\Db\Constant\ColumnType::TINYINT, \Yiisoft\Db\Constant\ColumnType::SMALLINT, \Yiisoft\Db\Constant\ColumnType::INTEGER, \Yiisoft\Db\Constant\ColumnType::BIGINT, ] | Yiisoft\Db\Oracle\Command |
Method Details
| protected void bindPendingParams ( ) |
protected function bindPendingParams(): void
{
$paramsPassedByReference = [];
foreach ($this->params as $name => $param) {
if (PDO::PARAM_STR === $param->type) {
$paramsPassedByReference[$name] = $param->value;
$this->pdoStatement?->bindParam(
$name,
$paramsPassedByReference[$name],
$param->type,
strlen((string) $param->value),
);
} else {
$this->pdoStatement?->bindValue($name, $param->value, $param->type);
}
}
}
| public array insertReturningPks ( string $table, array|\Yiisoft\Db\Query\QueryInterface $columns ) | ||
| $table | string | |
| $columns | array|\Yiisoft\Db\Query\QueryInterface | |
public function insertReturningPks(string $table, array|QueryInterface $columns): array
{
$tableSchema = $this->db->getSchema()->getTableSchema($table);
$returnColumns = $tableSchema?->getPrimaryKey() ?? [];
if ($returnColumns === []) {
$this->insert($table, $columns)->execute();
return [];
}
/** @var TableSchema $tableSchema */
if ($columns instanceof QueryInterface) {
throw new NotSupportedException(
__METHOD__ . '() is not supported by Oracle when inserting sub-query.',
);
}
$params = [];
$sql = $this->getQueryBuilder()->insert($table, $columns, $params);
$tableColumns = $tableSchema->getColumns();
/**
* @psalm-var array<string, array{
* column: string,
* value: mixed,
* dataType: DataType::*,
* size: int,
* }> $returnParams
*/
$returnParams = [];
foreach ($returnColumns as $name) {
$phName = AbstractQueryBuilder::PARAM_PREFIX . (count($params) + count($returnParams));
$returnParams[$phName] = [
'column' => $name,
'value' => '',
];
$column = $tableColumns[$name];
$returnParams[$phName]['dataType'] = in_array($column->getType(), self::INTEGER_COLUMN_TYPES, true)
? PDO::PARAM_INT
: PDO::PARAM_STR;
$returnParams[$phName]['size'] = ($column->getSize() ?? 3998) + 2;
}
$quotedReturnColumns = array_map($this->db->getQuoter()->quoteColumnName(...), $returnColumns);
$sql .= ' RETURNING ' . implode(', ', $quotedReturnColumns) . ' INTO ' . implode(', ', array_keys($returnParams));
$this->setSql($sql)->bindValues($params);
$this->prepare(false);
foreach ($returnParams as $name => &$value) {
$this->bindParam($name, $value['value'], $value['dataType'], $value['size']);
}
unset($value);
$this->execute();
$result = [];
foreach ($returnParams as $value) {
$result[$value['column']] = $value['value'];
}
if ($this->phpTypecasting) {
foreach ($result as $column => &$value) {
$value = $tableColumns[$column]->phpTypecast($value);
}
}
return $result;
}
| public array showDatabases ( ) |
public function showDatabases(): array
{
$sql = <<<SQL
SELECT PDB_NAME FROM DBA_PDBS WHERE PDB_NAME NOT IN ('PDB\$SEED', 'PDB\$ROOT', 'ORCLPDB1', 'XEPDB1')
SQL;
return $this->setSql($sql)->queryColumn();
}
Signup or Login in order to comment.