init
This commit is contained in:
72
vendor/yiisoft/yii2/db/cubrid/ColumnSchemaBuilder.php
vendored
Normal file
72
vendor/yiisoft/yii2/db/cubrid/ColumnSchemaBuilder.php
vendored
Normal file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
/**
|
||||
* @link http://www.yiiframework.com/
|
||||
* @copyright Copyright (c) 2008 Yii Software LLC
|
||||
* @license http://www.yiiframework.com/license/
|
||||
*/
|
||||
|
||||
namespace yii\db\cubrid;
|
||||
|
||||
use yii\db\ColumnSchemaBuilder as AbstractColumnSchemaBuilder;
|
||||
|
||||
/**
|
||||
* ColumnSchemaBuilder is the schema builder for Cubrid databases.
|
||||
*
|
||||
* @author Chris Harris <chris@buckshotsoftware.com>
|
||||
* @since 2.0.8
|
||||
*/
|
||||
class ColumnSchemaBuilder extends AbstractColumnSchemaBuilder
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function buildUnsignedString()
|
||||
{
|
||||
return $this->isUnsigned ? ' UNSIGNED' : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function buildAfterString()
|
||||
{
|
||||
return $this->after !== null ?
|
||||
' AFTER ' . $this->db->quoteColumnName($this->after) :
|
||||
'';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function buildFirstString()
|
||||
{
|
||||
return $this->isFirst ? ' FIRST' : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function buildCommentString()
|
||||
{
|
||||
return $this->comment !== null ? ' COMMENT ' . $this->db->quoteValue($this->comment) : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
switch ($this->getTypeCategory()) {
|
||||
case self::CATEGORY_PK:
|
||||
$format = '{type}{check}{comment}{append}{pos}';
|
||||
break;
|
||||
case self::CATEGORY_NUMERIC:
|
||||
$format = '{type}{length}{unsigned}{notnull}{unique}{default}{check}{comment}{append}{pos}';
|
||||
break;
|
||||
default:
|
||||
$format = '{type}{length}{notnull}{unique}{default}{check}{comment}{append}{pos}';
|
||||
}
|
||||
|
||||
return $this->buildCompleteString($format);
|
||||
}
|
||||
}
|
||||
290
vendor/yiisoft/yii2/db/cubrid/QueryBuilder.php
vendored
Normal file
290
vendor/yiisoft/yii2/db/cubrid/QueryBuilder.php
vendored
Normal file
@@ -0,0 +1,290 @@
|
||||
<?php
|
||||
/**
|
||||
* @link http://www.yiiframework.com/
|
||||
* @copyright Copyright (c) 2008 Yii Software LLC
|
||||
* @license http://www.yiiframework.com/license/
|
||||
*/
|
||||
|
||||
namespace yii\db\cubrid;
|
||||
|
||||
use yii\base\InvalidArgumentException;
|
||||
use yii\base\NotSupportedException;
|
||||
use yii\db\Constraint;
|
||||
use yii\db\Exception;
|
||||
use yii\db\Expression;
|
||||
|
||||
/**
|
||||
* QueryBuilder is the query builder for CUBRID databases (version 9.3.x and higher).
|
||||
*
|
||||
* @author Carsten Brandt <mail@cebe.cc>
|
||||
* @since 2.0
|
||||
*/
|
||||
class QueryBuilder extends \yii\db\QueryBuilder
|
||||
{
|
||||
/**
|
||||
* @var array mapping from abstract column types (keys) to physical column types (values).
|
||||
*/
|
||||
public $typeMap = [
|
||||
Schema::TYPE_PK => 'int NOT NULL AUTO_INCREMENT PRIMARY KEY',
|
||||
Schema::TYPE_UPK => 'int UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY',
|
||||
Schema::TYPE_BIGPK => 'bigint NOT NULL AUTO_INCREMENT PRIMARY KEY',
|
||||
Schema::TYPE_UBIGPK => 'bigint UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY',
|
||||
Schema::TYPE_CHAR => 'char(1)',
|
||||
Schema::TYPE_STRING => 'varchar(255)',
|
||||
Schema::TYPE_TEXT => 'varchar',
|
||||
Schema::TYPE_TINYINT => 'smallint',
|
||||
Schema::TYPE_SMALLINT => 'smallint',
|
||||
Schema::TYPE_INTEGER => 'int',
|
||||
Schema::TYPE_BIGINT => 'bigint',
|
||||
Schema::TYPE_FLOAT => 'float(7)',
|
||||
Schema::TYPE_DOUBLE => 'double(15)',
|
||||
Schema::TYPE_DECIMAL => 'decimal(10,0)',
|
||||
Schema::TYPE_DATETIME => 'datetime',
|
||||
Schema::TYPE_TIMESTAMP => 'timestamp',
|
||||
Schema::TYPE_TIME => 'time',
|
||||
Schema::TYPE_DATE => 'date',
|
||||
Schema::TYPE_BINARY => 'blob',
|
||||
Schema::TYPE_BOOLEAN => 'smallint',
|
||||
Schema::TYPE_MONEY => 'decimal(19,4)',
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function defaultExpressionBuilders()
|
||||
{
|
||||
return array_merge(parent::defaultExpressionBuilders(), [
|
||||
'yii\db\conditions\LikeCondition' => 'yii\db\cubrid\conditions\LikeConditionBuilder',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* @see https://www.cubrid.org/manual/en/9.3.0/sql/query/merge.html
|
||||
*/
|
||||
public function upsert($table, $insertColumns, $updateColumns, &$params)
|
||||
{
|
||||
/** @var Constraint[] $constraints */
|
||||
list($uniqueNames, $insertNames, $updateNames) = $this->prepareUpsertColumns($table, $insertColumns, $updateColumns, $constraints);
|
||||
if (empty($uniqueNames)) {
|
||||
return $this->insert($table, $insertColumns, $params);
|
||||
}
|
||||
|
||||
$onCondition = ['or'];
|
||||
$quotedTableName = $this->db->quoteTableName($table);
|
||||
foreach ($constraints as $constraint) {
|
||||
$constraintCondition = ['and'];
|
||||
foreach ($constraint->columnNames as $name) {
|
||||
$quotedName = $this->db->quoteColumnName($name);
|
||||
$constraintCondition[] = "$quotedTableName.$quotedName=\"EXCLUDED\".$quotedName";
|
||||
}
|
||||
$onCondition[] = $constraintCondition;
|
||||
}
|
||||
$on = $this->buildCondition($onCondition, $params);
|
||||
list(, $placeholders, $values, $params) = $this->prepareInsertValues($table, $insertColumns, $params);
|
||||
$mergeSql = 'MERGE INTO ' . $this->db->quoteTableName($table) . ' '
|
||||
. 'USING (' . (!empty($placeholders) ? 'VALUES (' . implode(', ', $placeholders) . ')' : ltrim($values, ' ')) . ') AS "EXCLUDED" (' . implode(', ', $insertNames) . ') '
|
||||
. "ON ($on)";
|
||||
$insertValues = [];
|
||||
foreach ($insertNames as $name) {
|
||||
$quotedName = $this->db->quoteColumnName($name);
|
||||
if (strrpos($quotedName, '.') === false) {
|
||||
$quotedName = '"EXCLUDED".' . $quotedName;
|
||||
}
|
||||
$insertValues[] = $quotedName;
|
||||
}
|
||||
$insertSql = 'INSERT (' . implode(', ', $insertNames) . ')'
|
||||
. ' VALUES (' . implode(', ', $insertValues) . ')';
|
||||
if ($updateColumns === false) {
|
||||
return "$mergeSql WHEN NOT MATCHED THEN $insertSql";
|
||||
}
|
||||
|
||||
if ($updateColumns === true) {
|
||||
$updateColumns = [];
|
||||
foreach ($updateNames as $name) {
|
||||
$quotedName = $this->db->quoteColumnName($name);
|
||||
if (strrpos($quotedName, '.') === false) {
|
||||
$quotedName = '"EXCLUDED".' . $quotedName;
|
||||
}
|
||||
$updateColumns[$name] = new Expression($quotedName);
|
||||
}
|
||||
}
|
||||
list($updates, $params) = $this->prepareUpdateSets($table, $updateColumns, $params);
|
||||
$updateSql = 'UPDATE SET ' . implode(', ', $updates);
|
||||
return "$mergeSql WHEN MATCHED THEN $updateSql WHEN NOT MATCHED THEN $insertSql";
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a SQL statement for resetting the sequence value of a table's primary key.
|
||||
* The sequence will be reset such that the primary key of the next new row inserted
|
||||
* will have the specified value or 1.
|
||||
* @param string $tableName the name of the table whose primary key sequence will be reset
|
||||
* @param mixed $value the value for the primary key of the next new row inserted. If this is not set,
|
||||
* the next new row's primary key will have a value 1.
|
||||
* @return string the SQL statement for resetting sequence
|
||||
* @throws InvalidArgumentException if the table does not exist or there is no sequence associated with the table.
|
||||
*/
|
||||
public function resetSequence($tableName, $value = null)
|
||||
{
|
||||
$table = $this->db->getTableSchema($tableName);
|
||||
if ($table !== null && $table->sequenceName !== null) {
|
||||
$tableName = $this->db->quoteTableName($tableName);
|
||||
if ($value === null) {
|
||||
$key = reset($table->primaryKey);
|
||||
$value = (int) $this->db->createCommand("SELECT MAX(`$key`) FROM " . $this->db->schema->quoteTableName($tableName))->queryScalar() + 1;
|
||||
} else {
|
||||
$value = (int) $value;
|
||||
}
|
||||
|
||||
return 'ALTER TABLE ' . $this->db->schema->quoteTableName($tableName) . " AUTO_INCREMENT=$value;";
|
||||
} elseif ($table === null) {
|
||||
throw new InvalidArgumentException("Table not found: $tableName");
|
||||
}
|
||||
|
||||
throw new InvalidArgumentException("There is not sequence associated with table '$tableName'.");
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildLimit($limit, $offset)
|
||||
{
|
||||
$sql = '';
|
||||
// limit is not optional in CUBRID
|
||||
// http://www.cubrid.org/manual/90/en/LIMIT%20Clause
|
||||
// "You can specify a very big integer for row_count to display to the last row, starting from a specific row."
|
||||
if ($this->hasLimit($limit)) {
|
||||
$sql = 'LIMIT ' . $limit;
|
||||
if ($this->hasOffset($offset)) {
|
||||
$sql .= ' OFFSET ' . $offset;
|
||||
}
|
||||
} elseif ($this->hasOffset($offset)) {
|
||||
$sql = "LIMIT 9223372036854775807 OFFSET $offset"; // 2^63-1
|
||||
}
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* @since 2.0.8
|
||||
*/
|
||||
public function selectExists($rawSql)
|
||||
{
|
||||
return 'SELECT CASE WHEN EXISTS(' . $rawSql . ') THEN 1 ELSE 0 END';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* @see http://www.cubrid.org/manual/93/en/sql/schema/table.html#drop-index-clause
|
||||
*/
|
||||
public function dropIndex($name, $table)
|
||||
{
|
||||
/** @var Schema $schema */
|
||||
$schema = $this->db->getSchema();
|
||||
foreach ($schema->getTableUniques($table) as $unique) {
|
||||
if ($unique->name === $name) {
|
||||
return $this->dropUnique($name, $table);
|
||||
}
|
||||
}
|
||||
|
||||
return 'DROP INDEX ' . $this->db->quoteTableName($name) . ' ON ' . $this->db->quoteTableName($table);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* @throws NotSupportedException this is not supported by CUBRID.
|
||||
*/
|
||||
public function addCheck($name, $table, $expression)
|
||||
{
|
||||
throw new NotSupportedException(__METHOD__ . ' is not supported by CUBRID.');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* @throws NotSupportedException this is not supported by CUBRID.
|
||||
*/
|
||||
public function dropCheck($name, $table)
|
||||
{
|
||||
throw new NotSupportedException(__METHOD__ . ' is not supported by CUBRID.');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* @since 2.0.8
|
||||
*/
|
||||
public function addCommentOnColumn($table, $column, $comment)
|
||||
{
|
||||
$definition = $this->getColumnDefinition($table, $column);
|
||||
$definition = trim(preg_replace("/COMMENT '(.*?)'/i", '', $definition));
|
||||
|
||||
return 'ALTER TABLE ' . $this->db->quoteTableName($table)
|
||||
. ' CHANGE ' . $this->db->quoteColumnName($column)
|
||||
. ' ' . $this->db->quoteColumnName($column)
|
||||
. (empty($definition) ? '' : ' ' . $definition)
|
||||
. ' COMMENT ' . $this->db->quoteValue($comment);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* @since 2.0.8
|
||||
*/
|
||||
public function addCommentOnTable($table, $comment)
|
||||
{
|
||||
return 'ALTER TABLE ' . $this->db->quoteTableName($table) . ' COMMENT ' . $this->db->quoteValue($comment);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* @since 2.0.8
|
||||
*/
|
||||
public function dropCommentFromColumn($table, $column)
|
||||
{
|
||||
return $this->addCommentOnColumn($table, $column, '');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* @since 2.0.8
|
||||
*/
|
||||
public function dropCommentFromTable($table)
|
||||
{
|
||||
return $this->addCommentOnTable($table, '');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets column definition.
|
||||
*
|
||||
* @param string $table table name
|
||||
* @param string $column column name
|
||||
* @return null|string the column definition
|
||||
* @throws Exception in case when table does not contain column
|
||||
* @since 2.0.8
|
||||
*/
|
||||
private function getColumnDefinition($table, $column)
|
||||
{
|
||||
$row = $this->db->createCommand('SHOW CREATE TABLE ' . $this->db->quoteTableName($table))->queryOne();
|
||||
if ($row === false) {
|
||||
throw new Exception("Unable to find column '$column' in table '$table'.");
|
||||
}
|
||||
if (isset($row['Create Table'])) {
|
||||
$sql = $row['Create Table'];
|
||||
} else {
|
||||
$row = array_values($row);
|
||||
$sql = $row[1];
|
||||
}
|
||||
$sql = preg_replace('/^[^(]+\((.*)\).*$/', '\1', $sql);
|
||||
$sql = str_replace(', [', ",\n[", $sql);
|
||||
if (preg_match_all('/^\s*\[(.*?)\]\s+(.*?),?$/m', $sql, $matches)) {
|
||||
foreach ($matches[1] as $i => $c) {
|
||||
if ($c === $column) {
|
||||
return $matches[2][$i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
418
vendor/yiisoft/yii2/db/cubrid/Schema.php
vendored
Normal file
418
vendor/yiisoft/yii2/db/cubrid/Schema.php
vendored
Normal file
@@ -0,0 +1,418 @@
|
||||
<?php
|
||||
/**
|
||||
* @link http://www.yiiframework.com/
|
||||
* @copyright Copyright (c) 2008 Yii Software LLC
|
||||
* @license http://www.yiiframework.com/license/
|
||||
*/
|
||||
|
||||
namespace yii\db\cubrid;
|
||||
|
||||
use yii\base\NotSupportedException;
|
||||
use yii\db\Constraint;
|
||||
use yii\db\ConstraintFinderInterface;
|
||||
use yii\db\ConstraintFinderTrait;
|
||||
use yii\db\Expression;
|
||||
use yii\db\ForeignKeyConstraint;
|
||||
use yii\db\IndexConstraint;
|
||||
use yii\db\TableSchema;
|
||||
use yii\db\Transaction;
|
||||
use yii\helpers\ArrayHelper;
|
||||
|
||||
/**
|
||||
* Schema is the class for retrieving metadata from a CUBRID database (version 9.3.x and higher).
|
||||
*
|
||||
* @author Carsten Brandt <mail@cebe.cc>
|
||||
* @since 2.0
|
||||
*/
|
||||
class Schema extends \yii\db\Schema implements ConstraintFinderInterface
|
||||
{
|
||||
use ConstraintFinderTrait;
|
||||
|
||||
/**
|
||||
* @var array mapping from physical column types (keys) to abstract column types (values)
|
||||
* Please refer to [CUBRID manual](http://www.cubrid.org/manual/91/en/sql/datatype.html) for
|
||||
* details on data types.
|
||||
*/
|
||||
public $typeMap = [
|
||||
// Numeric data types
|
||||
'short' => self::TYPE_SMALLINT,
|
||||
'smallint' => self::TYPE_SMALLINT,
|
||||
'int' => self::TYPE_INTEGER,
|
||||
'integer' => self::TYPE_INTEGER,
|
||||
'bigint' => self::TYPE_BIGINT,
|
||||
'numeric' => self::TYPE_DECIMAL,
|
||||
'decimal' => self::TYPE_DECIMAL,
|
||||
'float' => self::TYPE_FLOAT,
|
||||
'real' => self::TYPE_FLOAT,
|
||||
'double' => self::TYPE_DOUBLE,
|
||||
'double precision' => self::TYPE_DOUBLE,
|
||||
'monetary' => self::TYPE_MONEY,
|
||||
// Date/Time data types
|
||||
'date' => self::TYPE_DATE,
|
||||
'time' => self::TYPE_TIME,
|
||||
'timestamp' => self::TYPE_TIMESTAMP,
|
||||
'datetime' => self::TYPE_DATETIME,
|
||||
// String data types
|
||||
'char' => self::TYPE_CHAR,
|
||||
'varchar' => self::TYPE_STRING,
|
||||
'char varying' => self::TYPE_STRING,
|
||||
'nchar' => self::TYPE_CHAR,
|
||||
'nchar varying' => self::TYPE_STRING,
|
||||
'string' => self::TYPE_STRING,
|
||||
// BLOB/CLOB data types
|
||||
'blob' => self::TYPE_BINARY,
|
||||
'clob' => self::TYPE_BINARY,
|
||||
// Bit string data types
|
||||
'bit' => self::TYPE_INTEGER,
|
||||
'bit varying' => self::TYPE_INTEGER,
|
||||
// Collection data types (considered strings for now)
|
||||
'set' => self::TYPE_STRING,
|
||||
'multiset' => self::TYPE_STRING,
|
||||
'list' => self::TYPE_STRING,
|
||||
'sequence' => self::TYPE_STRING,
|
||||
'enum' => self::TYPE_STRING,
|
||||
];
|
||||
/**
|
||||
* @var array map of DB errors and corresponding exceptions
|
||||
* If left part is found in DB error message exception class from the right part is used.
|
||||
*/
|
||||
public $exceptionMap = [
|
||||
'Operation would have caused one or more unique constraint violations' => 'yii\db\IntegrityException',
|
||||
];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $tableQuoteCharacter = '"';
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function findTableNames($schema = '')
|
||||
{
|
||||
$pdo = $this->db->getSlavePdo();
|
||||
$tables = $pdo->cubrid_schema(\PDO::CUBRID_SCH_TABLE);
|
||||
$tableNames = [];
|
||||
foreach ($tables as $table) {
|
||||
// do not list system tables
|
||||
if ($table['TYPE'] != 0) {
|
||||
$tableNames[] = $table['NAME'];
|
||||
}
|
||||
}
|
||||
|
||||
return $tableNames;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function loadTableSchema($name)
|
||||
{
|
||||
$pdo = $this->db->getSlavePdo();
|
||||
|
||||
$tableInfo = $pdo->cubrid_schema(\PDO::CUBRID_SCH_TABLE, $name);
|
||||
|
||||
if (!isset($tableInfo[0]['NAME'])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$table = new TableSchema();
|
||||
$table->fullName = $table->name = $tableInfo[0]['NAME'];
|
||||
|
||||
$sql = 'SHOW FULL COLUMNS FROM ' . $this->quoteSimpleTableName($table->name);
|
||||
$columns = $this->db->createCommand($sql)->queryAll();
|
||||
|
||||
foreach ($columns as $info) {
|
||||
$column = $this->loadColumnSchema($info);
|
||||
$table->columns[$column->name] = $column;
|
||||
}
|
||||
|
||||
$primaryKeys = $pdo->cubrid_schema(\PDO::CUBRID_SCH_PRIMARY_KEY, $table->name);
|
||||
foreach ($primaryKeys as $key) {
|
||||
$column = $table->columns[$key['ATTR_NAME']];
|
||||
$column->isPrimaryKey = true;
|
||||
$table->primaryKey[] = $column->name;
|
||||
if ($column->autoIncrement) {
|
||||
$table->sequenceName = '';
|
||||
}
|
||||
}
|
||||
|
||||
$foreignKeys = $pdo->cubrid_schema(\PDO::CUBRID_SCH_IMPORTED_KEYS, $table->name);
|
||||
foreach ($foreignKeys as $key) {
|
||||
if (isset($table->foreignKeys[$key['FK_NAME']])) {
|
||||
$table->foreignKeys[$key['FK_NAME']][$key['FKCOLUMN_NAME']] = $key['PKCOLUMN_NAME'];
|
||||
} else {
|
||||
$table->foreignKeys[$key['FK_NAME']] = [
|
||||
$key['PKTABLE_NAME'],
|
||||
$key['FKCOLUMN_NAME'] => $key['PKCOLUMN_NAME'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return $table;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function loadTablePrimaryKey($tableName)
|
||||
{
|
||||
$primaryKey = $this->db->getSlavePdo()->cubrid_schema(\PDO::CUBRID_SCH_PRIMARY_KEY, $tableName);
|
||||
if (empty($primaryKey)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
ArrayHelper::multisort($primaryKey, 'KEY_SEQ', SORT_ASC, SORT_NUMERIC);
|
||||
return new Constraint([
|
||||
'name' => $primaryKey[0]['KEY_NAME'],
|
||||
'columnNames' => ArrayHelper::getColumn($primaryKey, 'ATTR_NAME'),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function loadTableForeignKeys($tableName)
|
||||
{
|
||||
static $actionTypes = [
|
||||
0 => 'CASCADE',
|
||||
1 => 'RESTRICT',
|
||||
2 => 'NO ACTION',
|
||||
3 => 'SET NULL',
|
||||
];
|
||||
|
||||
$foreignKeys = $this->db->getSlavePdo()->cubrid_schema(\PDO::CUBRID_SCH_IMPORTED_KEYS, $tableName);
|
||||
$foreignKeys = ArrayHelper::index($foreignKeys, null, 'FK_NAME');
|
||||
ArrayHelper::multisort($foreignKeys, 'KEY_SEQ', SORT_ASC, SORT_NUMERIC);
|
||||
$result = [];
|
||||
foreach ($foreignKeys as $name => $foreignKey) {
|
||||
$result[] = new ForeignKeyConstraint([
|
||||
'name' => $name,
|
||||
'columnNames' => ArrayHelper::getColumn($foreignKey, 'FKCOLUMN_NAME'),
|
||||
'foreignTableName' => $foreignKey[0]['PKTABLE_NAME'],
|
||||
'foreignColumnNames' => ArrayHelper::getColumn($foreignKey, 'PKCOLUMN_NAME'),
|
||||
'onDelete' => isset($actionTypes[$foreignKey[0]['DELETE_RULE']]) ? $actionTypes[$foreignKey[0]['DELETE_RULE']] : null,
|
||||
'onUpdate' => isset($actionTypes[$foreignKey[0]['UPDATE_RULE']]) ? $actionTypes[$foreignKey[0]['UPDATE_RULE']] : null,
|
||||
]);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function loadTableIndexes($tableName)
|
||||
{
|
||||
return $this->loadTableConstraints($tableName, 'indexes');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function loadTableUniques($tableName)
|
||||
{
|
||||
return $this->loadTableConstraints($tableName, 'uniques');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* @throws NotSupportedException if this method is called.
|
||||
*/
|
||||
protected function loadTableChecks($tableName)
|
||||
{
|
||||
throw new NotSupportedException('CUBRID does not support check constraints.');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* @throws NotSupportedException if this method is called.
|
||||
*/
|
||||
protected function loadTableDefaultValues($tableName)
|
||||
{
|
||||
throw new NotSupportedException('CUBRID does not support default value constraints.');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function releaseSavepoint($name)
|
||||
{
|
||||
// does nothing as cubrid does not support this
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a query builder for the CUBRID database.
|
||||
* @return QueryBuilder query builder instance
|
||||
*/
|
||||
public function createQueryBuilder()
|
||||
{
|
||||
return new QueryBuilder($this->db);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the column information into a [[ColumnSchema]] object.
|
||||
* @param array $info column information
|
||||
* @return \yii\db\ColumnSchema the column schema object
|
||||
*/
|
||||
protected function loadColumnSchema($info)
|
||||
{
|
||||
$column = $this->createColumnSchema();
|
||||
|
||||
$column->name = $info['Field'];
|
||||
$column->allowNull = $info['Null'] === 'YES';
|
||||
$column->isPrimaryKey = false; // primary key will be set by loadTableSchema() later
|
||||
$column->autoIncrement = stripos($info['Extra'], 'auto_increment') !== false;
|
||||
|
||||
$column->dbType = $info['Type'];
|
||||
$column->unsigned = strpos($column->dbType, 'unsigned') !== false;
|
||||
|
||||
$column->type = self::TYPE_STRING;
|
||||
if (preg_match('/^([\w ]+)(?:\(([^\)]+)\))?$/', $column->dbType, $matches)) {
|
||||
$type = strtolower($matches[1]);
|
||||
$column->dbType = $type . (isset($matches[2]) ? "({$matches[2]})" : '');
|
||||
if (isset($this->typeMap[$type])) {
|
||||
$column->type = $this->typeMap[$type];
|
||||
}
|
||||
if (!empty($matches[2])) {
|
||||
if ($type === 'enum') {
|
||||
$values = preg_split('/\s*,\s*/', $matches[2]);
|
||||
foreach ($values as $i => $value) {
|
||||
$values[$i] = trim($value, "'");
|
||||
}
|
||||
$column->enumValues = $values;
|
||||
} else {
|
||||
$values = explode(',', $matches[2]);
|
||||
$column->size = $column->precision = (int) $values[0];
|
||||
if (isset($values[1])) {
|
||||
$column->scale = (int) $values[1];
|
||||
}
|
||||
if ($column->size === 1 && $type === 'bit') {
|
||||
$column->type = 'boolean';
|
||||
} elseif ($type === 'bit') {
|
||||
if ($column->size > 32) {
|
||||
$column->type = 'bigint';
|
||||
} elseif ($column->size === 32) {
|
||||
$column->type = 'integer';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$column->phpType = $this->getColumnPhpType($column);
|
||||
|
||||
if ($column->isPrimaryKey) {
|
||||
return $column;
|
||||
}
|
||||
|
||||
if ($column->type === 'timestamp' && $info['Default'] === 'SYS_TIMESTAMP' ||
|
||||
$column->type === 'datetime' && $info['Default'] === 'SYS_DATETIME' ||
|
||||
$column->type === 'date' && $info['Default'] === 'SYS_DATE' ||
|
||||
$column->type === 'time' && $info['Default'] === 'SYS_TIME'
|
||||
) {
|
||||
$column->defaultValue = new Expression($info['Default']);
|
||||
} elseif (isset($type) && $type === 'bit') {
|
||||
$column->defaultValue = hexdec(trim($info['Default'], 'X\''));
|
||||
} else {
|
||||
$column->defaultValue = $column->phpTypecast($info['Default']);
|
||||
}
|
||||
|
||||
return $column;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines the PDO type for the given PHP data value.
|
||||
* @param mixed $data the data whose PDO type is to be determined
|
||||
* @return int the PDO type
|
||||
* @see http://www.php.net/manual/en/pdo.constants.php
|
||||
*/
|
||||
public function getPdoType($data)
|
||||
{
|
||||
static $typeMap = [
|
||||
// php type => PDO type
|
||||
'boolean' => \PDO::PARAM_INT, // PARAM_BOOL is not supported by CUBRID PDO
|
||||
'integer' => \PDO::PARAM_INT,
|
||||
'string' => \PDO::PARAM_STR,
|
||||
'resource' => \PDO::PARAM_LOB,
|
||||
'NULL' => \PDO::PARAM_NULL,
|
||||
];
|
||||
$type = gettype($data);
|
||||
|
||||
return isset($typeMap[$type]) ? $typeMap[$type] : \PDO::PARAM_STR;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* @see http://www.cubrid.org/manual/91/en/sql/transaction.html#database-concurrency
|
||||
*/
|
||||
public function setTransactionIsolationLevel($level)
|
||||
{
|
||||
// translate SQL92 levels to CUBRID levels:
|
||||
switch ($level) {
|
||||
case Transaction::SERIALIZABLE:
|
||||
$level = '6'; // SERIALIZABLE
|
||||
break;
|
||||
case Transaction::REPEATABLE_READ:
|
||||
$level = '5'; // REPEATABLE READ CLASS with REPEATABLE READ INSTANCES
|
||||
break;
|
||||
case Transaction::READ_COMMITTED:
|
||||
$level = '4'; // REPEATABLE READ CLASS with READ COMMITTED INSTANCES
|
||||
break;
|
||||
case Transaction::READ_UNCOMMITTED:
|
||||
$level = '3'; // REPEATABLE READ CLASS with READ UNCOMMITTED INSTANCES
|
||||
break;
|
||||
}
|
||||
parent::setTransactionIsolationLevel($level);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function createColumnSchemaBuilder($type, $length = null)
|
||||
{
|
||||
return new ColumnSchemaBuilder($type, $length, $this->db);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads multiple types of constraints and returns the specified ones.
|
||||
* @param string $tableName table name.
|
||||
* @param string $returnType return type:
|
||||
* - indexes
|
||||
* - uniques
|
||||
* @return mixed constraints.
|
||||
*/
|
||||
private function loadTableConstraints($tableName, $returnType)
|
||||
{
|
||||
$constraints = $this->db->getSlavePdo()->cubrid_schema(\PDO::CUBRID_SCH_CONSTRAINT, $tableName);
|
||||
$constraints = ArrayHelper::index($constraints, null, ['TYPE', 'NAME']);
|
||||
ArrayHelper::multisort($constraints, 'KEY_ORDER', SORT_ASC, SORT_NUMERIC);
|
||||
$result = [
|
||||
'indexes' => [],
|
||||
'uniques' => [],
|
||||
];
|
||||
foreach ($constraints as $type => $names) {
|
||||
foreach ($names as $name => $constraint) {
|
||||
$isUnique = in_array((int) $type, [0, 2], true);
|
||||
$result['indexes'][] = new IndexConstraint([
|
||||
'isPrimary' => (bool) $constraint[0]['PRIMARY_KEY'],
|
||||
'isUnique' => $isUnique,
|
||||
'name' => $name,
|
||||
'columnNames' => ArrayHelper::getColumn($constraint, 'ATTR_NAME'),
|
||||
]);
|
||||
if ($isUnique) {
|
||||
$result['uniques'][] = new Constraint([
|
||||
'name' => $name,
|
||||
'columnNames' => ArrayHelper::getColumn($constraint, 'ATTR_NAME'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach ($result as $type => $data) {
|
||||
$this->setTableMetadata($tableName, $type, $data);
|
||||
}
|
||||
|
||||
return $result[$returnType];
|
||||
}
|
||||
}
|
||||
29
vendor/yiisoft/yii2/db/cubrid/conditions/LikeConditionBuilder.php
vendored
Normal file
29
vendor/yiisoft/yii2/db/cubrid/conditions/LikeConditionBuilder.php
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
/**
|
||||
* @link http://www.yiiframework.com/
|
||||
* @copyright Copyright (c) 2008 Yii Software LLC
|
||||
* @license http://www.yiiframework.com/license/
|
||||
*/
|
||||
|
||||
namespace yii\db\cubrid\conditions;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
class LikeConditionBuilder extends \yii\db\conditions\LikeConditionBuilder
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $escapeCharacter = '!';
|
||||
/**
|
||||
* `\` is initialized in [[buildLikeCondition()]] method since
|
||||
* we need to choose replacement value based on [[\yii\db\Schema::quoteValue()]].
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $escapingReplacements = [
|
||||
'%' => '!%',
|
||||
'_' => '!_',
|
||||
'!' => '!!',
|
||||
];
|
||||
}
|
||||
Reference in New Issue
Block a user