Klimov Paul
7 years ago
47 changed files with 12 additions and 2171 deletions
@ -1,72 +0,0 @@
|
||||
<?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); |
||||
} |
||||
} |
@ -1,290 +0,0 @@
|
||||
<?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 */ |
||||
[$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); |
||||
[, $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); |
||||
} |
||||
} |
||||
[$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; |
||||
} |
||||
} |
@ -1,418 +0,0 @@
|
||||
<?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' => IntegrityException::class, |
||||
]; |
||||
|
||||
/** |
||||
* {@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]; |
||||
} |
||||
} |
@ -1,29 +0,0 @@
|
||||
<?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 = [ |
||||
'%' => '!%', |
||||
'_' => '!_', |
||||
'!' => '!!', |
||||
]; |
||||
} |
@ -1,31 +0,0 @@
|
||||
FROM php:5-fpm |
||||
|
||||
# /usr/local/lib/php/extensions/no-debug-non-zts-20131226/cubrid.so |
||||
RUN pecl install pdo_cubrid-9.3.0.0001 |
||||
RUN echo "extension=pdo_cubrid.so" > /usr/local/etc/php/conf.d/cubrid.ini |
||||
|
||||
|
||||
# Install system packages for composer (git) |
||||
RUN apt-get update && \ |
||||
apt-get -y install \ |
||||
git \ |
||||
--no-install-recommends && \ |
||||
apt-get clean && \ |
||||
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* |
||||
# Register the COMPOSER_HOME environment variable |
||||
ENV COMPOSER_HOME /composer |
||||
# Add global binary directory to PATH and make sure to re-export it |
||||
ENV PATH /usr/local/bin:$PATH |
||||
# Allow Composer to be run as root |
||||
ENV COMPOSER_ALLOW_SUPERUSER 1 |
||||
# Install composer |
||||
RUN curl -sS https://getcomposer.org/installer | php -- \ |
||||
--filename=composer.phar \ |
||||
--install-dir=/usr/local/bin |
||||
|
||||
|
||||
# Project source-code |
||||
WORKDIR /project |
||||
ADD composer.* /project/ |
||||
RUN /usr/local/bin/composer.phar install --prefer-dist |
||||
ADD ./ /project |
@ -1,17 +0,0 @@
|
||||
version: '2' |
||||
services: |
||||
|
||||
php: |
||||
build: |
||||
context: ../.. |
||||
dockerfile: tests/cubrid/Dockerfile |
||||
ports: |
||||
- 80 |
||||
#volumes: |
||||
# - ../..:/project |
||||
depends_on: |
||||
- cubrid |
||||
|
||||
cubrid: |
||||
image: lighthopper/cubrid:9.3.6.0002 |
||||
command: ./create-start-demodb.sh |
@ -1,310 +0,0 @@
|
||||
/** |
||||
* This is the database schema for testing CUBRID support of Yii DAO and Active Record. |
||||
* The database setup in config.php is required to perform then relevant tests: |
||||
*/ |
||||
|
||||
DROP TABLE IF EXISTS "composite_fk"; |
||||
DROP TABLE IF EXISTS "order_item"; |
||||
DROP TABLE IF EXISTS "order_item_with_null_fk"; |
||||
DROP TABLE IF EXISTS "item"; |
||||
DROP TABLE IF EXISTS "order"; |
||||
DROP TABLE IF EXISTS "order_with_null_fk"; |
||||
DROP TABLE IF EXISTS "category"; |
||||
DROP TABLE IF EXISTS "customer"; |
||||
DROP TABLE IF EXISTS "profile"; |
||||
DROP TABLE IF EXISTS "null_values"; |
||||
DROP TABLE IF EXISTS "negative_default_values"; |
||||
DROP TABLE IF EXISTS "type"; |
||||
DROP TABLE IF EXISTS "constraints"; |
||||
DROP TABLE IF EXISTS "animal"; |
||||
DROP TABLE IF EXISTS "default_pk"; |
||||
DROP TABLE IF EXISTS "document"; |
||||
DROP TABLE IF EXISTS "dossier"; |
||||
DROP TABLE IF EXISTS "employee"; |
||||
DROP TABLE IF EXISTS "department"; |
||||
DROP VIEW IF EXISTS "animal_view"; |
||||
DROP TABLE IF EXISTS "T_constraints_4"; |
||||
DROP TABLE IF EXISTS "T_constraints_3"; |
||||
DROP TABLE IF EXISTS "T_constraints_2"; |
||||
DROP TABLE IF EXISTS "T_constraints_1"; |
||||
DROP TABLE IF EXISTS "T_upsert"; |
||||
|
||||
CREATE TABLE "constraints" |
||||
( |
||||
"id" integer not null, |
||||
"field1" varchar(255) |
||||
); |
||||
|
||||
|
||||
CREATE TABLE "profile" ( |
||||
"id" int(11) NOT NULL AUTO_INCREMENT, |
||||
"description" varchar(128) NOT NULL, |
||||
PRIMARY KEY ("id") |
||||
); |
||||
|
||||
CREATE TABLE "customer" ( |
||||
"id" int(11) NOT NULL AUTO_INCREMENT, |
||||
"email" varchar(128) NOT NULL, |
||||
"name" varchar(128), |
||||
"address" string, |
||||
"status" int (11) DEFAULT 0, |
||||
"profile_id" int(11), |
||||
PRIMARY KEY ("id") |
||||
); |
||||
|
||||
CREATE TABLE "category" ( |
||||
"id" int(11) NOT NULL AUTO_INCREMENT, |
||||
"name" varchar(128) NOT NULL, |
||||
PRIMARY KEY ("id") |
||||
); |
||||
|
||||
CREATE TABLE "item" ( |
||||
"id" int(11) NOT NULL AUTO_INCREMENT, |
||||
"name" varchar(128) NOT NULL, |
||||
"category_id" int(11) NOT NULL, |
||||
PRIMARY KEY ("id"), |
||||
CONSTRAINT "FK_item_category_id" FOREIGN KEY ("category_id") REFERENCES "category" ("id") |
||||
); |
||||
|
||||
CREATE TABLE "order" ( |
||||
"id" int(11) NOT NULL AUTO_INCREMENT, |
||||
"customer_id" int(11) NOT NULL, |
||||
"created_at" int(11) NOT NULL, |
||||
"total" decimal(10,0) NOT NULL, |
||||
PRIMARY KEY ("id"), |
||||
CONSTRAINT "FK_order_customer_id" FOREIGN KEY ("customer_id") REFERENCES "customer" ("id") |
||||
); |
||||
|
||||
CREATE TABLE "order_with_null_fk" ( |
||||
"id" int(11) NOT NULL AUTO_INCREMENT, |
||||
"customer_id" int(11), |
||||
"created_at" int(11) NOT NULL, |
||||
"total" decimal(10,0) NOT NULL, |
||||
PRIMARY KEY ("id") |
||||
); |
||||
|
||||
CREATE TABLE "order_item" ( |
||||
"order_id" int(11) NOT NULL, |
||||
"item_id" int(11) NOT NULL, |
||||
"quantity" int(11) NOT NULL, |
||||
"subtotal" decimal(10,0) NOT NULL, |
||||
PRIMARY KEY ("order_id","item_id"), |
||||
CONSTRAINT "FK_order_item_order_id" FOREIGN KEY ("order_id") REFERENCES "order" ("id"), |
||||
CONSTRAINT "FK_order_item_item_id" FOREIGN KEY ("item_id") REFERENCES "item" ("id") |
||||
); |
||||
|
||||
CREATE TABLE "order_item_with_null_fk" ( |
||||
"order_id" int(11), |
||||
"item_id" int(11), |
||||
"quantity" int(11) NOT NULL, |
||||
"subtotal" decimal(10,0) NOT NULL |
||||
); |
||||
|
||||
CREATE TABLE null_values ( |
||||
"id" INT(11) NOT NULL AUTO_INCREMENT, |
||||
"var1" INT NULL, |
||||
"var2" INT NULL, |
||||
"var3" INT DEFAULT NULL, |
||||
"stringcol" VARCHAR (32) DEFAULT NULL, |
||||
PRIMARY KEY (id) |
||||
); |
||||
|
||||
CREATE TABLE "negative_default_values" ( |
||||
tinyint_col smallint default '-123', |
||||
smallint_col smallint default '-123', |
||||
int_col int default '-123', |
||||
bigint_col bigint default '-123', |
||||
float_col double default '-12345.6789', |
||||
numeric_col decimal(5,2) default '-33.22' |
||||
); |
||||
|
||||
|
||||
CREATE TABLE "type" ( |
||||
"int_col" int(11) NOT NULL, |
||||
"int_col2" int(11) DEFAULT '1', |
||||
"tinyint_col" smallint DEFAULT '1', |
||||
"smallint_col" smallint DEFAULT '1', |
||||
"char_col" char(100) NOT NULL, |
||||
"char_col2" varchar(100) DEFAULT 'something', |
||||
"char_col3" string, |
||||
"enum_col" enum('a','B','c,D'), |
||||
"float_col" double NOT NULL, |
||||
"float_col2" double DEFAULT '1.23', |
||||
"blob_col" blob, |
||||
"numeric_col" decimal(5,2) DEFAULT '33.22', |
||||
"time" timestamp NOT NULL DEFAULT '2002-01-01 00:00:00', |
||||
"bool_col" tinyint NOT NULL, |
||||
"bool_col2" tinyint DEFAULT '1', |
||||
"ts_default" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, |
||||
"bit_col" BIT(8) NOT NULL DEFAULT b'10000010' |
||||
); |
||||
|
||||
CREATE TABLE "composite_fk" ( |
||||
"id" int(11) NOT NULL, |
||||
"order_id" int(11) NOT NULL, |
||||
"item_id" int(11) NOT NULL, |
||||
PRIMARY KEY ("id"), |
||||
CONSTRAINT "FK_composite_fk_order_item" FOREIGN KEY ("order_id","item_id") REFERENCES "order_item" ("order_id","item_id") |
||||
); |
||||
|
||||
CREATE TABLE "animal" ( |
||||
"id" int(11) NOT NULL AUTO_INCREMENT, |
||||
"type" varchar(255) NOT NULL, |
||||
PRIMARY KEY ("id") |
||||
); |
||||
|
||||
CREATE TABLE "default_pk" ( |
||||
"id" int(11) NOT NULL DEFAULT 5, |
||||
"type" varchar(255) NOT NULL, |
||||
PRIMARY KEY ("id") |
||||
); |
||||
|
||||
CREATE TABLE "document" ( |
||||
"id" int(11) NOT NULL AUTO_INCREMENT, |
||||
"title" varchar(255) NOT NULL, |
||||
"content" string, |
||||
"version" int(11) NOT NULL DEFAULT 0, |
||||
PRIMARY KEY ("id") |
||||
); |
||||
|
||||
CREATE TABLE "department" ( |
||||
"id" int(11) NOT NULL AUTO_INCREMENT, |
||||
"title" VARCHAR(255) NOT NULL, |
||||
PRIMARY KEY ("id") |
||||
); |
||||
|
||||
CREATE TABLE "employee" ( |
||||
"id" int(11) NOT NULL, |
||||
"department_id" int(11) NOT NULL, |
||||
"first_name" VARCHAR(255) NOT NULL, |
||||
"last_name" VARCHAR(255) NOT NULL, |
||||
PRIMARY KEY ("id", "department_id") |
||||
); |
||||
|
||||
CREATE TABLE "dossier" ( |
||||
"id" int(11) NOT NULL AUTO_INCREMENT, |
||||
"department_id" int(11) NOT NULL, |
||||
"employee_id" int(11) NOT NULL, |
||||
"summary" VARCHAR(255) NOT NULL, |
||||
PRIMARY KEY ("id") |
||||
); |
||||
|
||||
CREATE VIEW "animal_view" AS SELECT * FROM "animal"; |
||||
|
||||
INSERT INTO "animal" ("type") VALUES ('yiiunit\data\ar\Cat'); |
||||
INSERT INTO "animal" ("type") VALUES ('yiiunit\data\ar\Dog'); |
||||
|
||||
INSERT INTO "profile" (description) VALUES ('profile customer 1'); |
||||
INSERT INTO "profile" (description) VALUES ('profile customer 3'); |
||||
|
||||
INSERT INTO "customer" (email, name, address, status, profile_id) VALUES ('user1@example.com', 'user1', 'address1', 1, 1); |
||||
INSERT INTO "customer" (email, name, address, status) VALUES ('user2@example.com', 'user2', 'address2', 1); |
||||
INSERT INTO "customer" (email, name, address, status, profile_id) VALUES ('user3@example.com', 'user3', 'address3', 2, 2); |
||||
|
||||
INSERT INTO "category" (name) VALUES ('Books'); |
||||
INSERT INTO "category" (name) VALUES ('Movies'); |
||||
|
||||
INSERT INTO "item" (name, category_id) VALUES ('Agile Web Application Development with Yii1.1 and PHP5', 1); |
||||
INSERT INTO "item" (name, category_id) VALUES ('Yii 1.1 Application Development Cookbook', 1); |
||||
INSERT INTO "item" (name, category_id) VALUES ('Ice Age', 2); |
||||
INSERT INTO "item" (name, category_id) VALUES ('Toy Story', 2); |
||||
INSERT INTO "item" (name, category_id) VALUES ('Cars', 2); |
||||
|
||||
INSERT INTO "order" (customer_id, created_at, total) VALUES (1, 1325282384, 110.0); |
||||
INSERT INTO "order" (customer_id, created_at, total) VALUES (2, 1325334482, 33.0); |
||||
INSERT INTO "order" (customer_id, created_at, total) VALUES (2, 1325502201, 40.0); |
||||
|
||||
INSERT INTO "order_with_null_fk" (customer_id, created_at, total) VALUES (1, 1325282384, 110.0); |
||||
INSERT INTO "order_with_null_fk" (customer_id, created_at, total) VALUES (2, 1325334482, 33.0); |
||||
INSERT INTO "order_with_null_fk" (customer_id, created_at, total) VALUES (2, 1325502201, 40.0); |
||||
|
||||
INSERT INTO "order_item" (order_id, item_id, quantity, subtotal) VALUES (1, 1, 1, 30.0); |
||||
INSERT INTO "order_item" (order_id, item_id, quantity, subtotal) VALUES (1, 2, 2, 40.0); |
||||
INSERT INTO "order_item" (order_id, item_id, quantity, subtotal) VALUES (2, 4, 1, 10.0); |
||||
INSERT INTO "order_item" (order_id, item_id, quantity, subtotal) VALUES (2, 5, 1, 15.0); |
||||
INSERT INTO "order_item" (order_id, item_id, quantity, subtotal) VALUES (2, 3, 1, 8.0); |
||||
INSERT INTO "order_item" (order_id, item_id, quantity, subtotal) VALUES (3, 2, 1, 40.0); |
||||
|
||||
INSERT INTO "order_item_with_null_fk" (order_id, item_id, quantity, subtotal) VALUES (1, 1, 1, 30.0); |
||||
INSERT INTO "order_item_with_null_fk" (order_id, item_id, quantity, subtotal) VALUES (1, 2, 2, 40.0); |
||||
INSERT INTO "order_item_with_null_fk" (order_id, item_id, quantity, subtotal) VALUES (2, 4, 1, 10.0); |
||||
INSERT INTO "order_item_with_null_fk" (order_id, item_id, quantity, subtotal) VALUES (2, 5, 1, 15.0); |
||||
INSERT INTO "order_item_with_null_fk" (order_id, item_id, quantity, subtotal) VALUES (2, 3, 1, 8.0); |
||||
INSERT INTO "order_item_with_null_fk" (order_id, item_id, quantity, subtotal) VALUES (3, 2, 1, 40.0); |
||||
|
||||
INSERT INTO "document" (title, content, version) VALUES ('Yii 2.0 guide', 'This is Yii 2.0 guide', 0); |
||||
|
||||
INSERT INTO "department" (id, title) VALUES (1, 'IT'); |
||||
INSERT INTO "department" (id, title) VALUES (2, 'accounting'); |
||||
|
||||
INSERT INTO "employee" (id, department_id, first_name, last_name) VALUES (1, 1, 'John', 'Doe'); |
||||
INSERT INTO "employee" (id, department_id, first_name, last_name) VALUES (1, 2, 'Ann', 'Smith'); |
||||
INSERT INTO "employee" (id, department_id, first_name, last_name) VALUES (2, 2, 'Will', 'Smith'); |
||||
|
||||
INSERT INTO "dossier" (id, department_id, employee_id, summary) VALUES (1, 1, 1, 'Excellent employee.'); |
||||
INSERT INTO "dossier" (id, department_id, employee_id, summary) VALUES (2, 2, 1, 'Brilliant employee.'); |
||||
INSERT INTO "dossier" (id, department_id, employee_id, summary) VALUES (3, 2, 2, 'Good employee.'); |
||||
|
||||
/* bit test, see https://github.com/yiisoft/yii2/issues/9006 */ |
||||
|
||||
DROP TABLE IF EXISTS `bit_values`; |
||||
|
||||
CREATE TABLE `bit_values` ( |
||||
`id` INT(11) NOT NULL AUTO_INCREMENT, |
||||
`val` bit(1) NOT NULL, |
||||
PRIMARY KEY (`id`) |
||||
); |
||||
|
||||
INSERT INTO `bit_values` (id, val) VALUES (1, b'0'), (2, b'1'); |
||||
|
||||
CREATE TABLE "T_constraints_1" |
||||
( |
||||
"C_id" INT NOT NULL PRIMARY KEY, |
||||
"C_not_null" INT NOT NULL, |
||||
"C_check" VARCHAR(255) NULL CHECK ("C_check" <> ''), |
||||
"C_unique" INT NOT NULL, |
||||
"C_default" INT NOT NULL DEFAULT 0, |
||||
CONSTRAINT "CN_unique" UNIQUE ("C_unique") |
||||
); |
||||
|
||||
CREATE TABLE "T_constraints_2" |
||||
( |
||||
"C_id_1" INT NOT NULL, |
||||
"C_id_2" INT NOT NULL, |
||||
"C_index_1" INT NULL, |
||||
"C_index_2_1" INT NULL, |
||||
"C_index_2_2" INT NULL, |
||||
CONSTRAINT "CN_constraints_2_multi" UNIQUE ("C_index_2_1", "C_index_2_2"), |
||||
CONSTRAINT "CN_pk" PRIMARY KEY ("C_id_1", "C_id_2") |
||||
); |
||||
|
||||
CREATE INDEX "CN_constraints_2_single" ON "T_constraints_2" ("C_index_1"); |
||||
|
||||
CREATE TABLE "T_constraints_3" |
||||
( |
||||
"C_id" INT NOT NULL, |
||||
"C_fk_id_1" INT NOT NULL, |
||||
"C_fk_id_2" INT NOT NULL, |
||||
CONSTRAINT "CN_constraints_3" FOREIGN KEY ("C_fk_id_1", "C_fk_id_2") REFERENCES "T_constraints_2" ("C_id_1", "C_id_2") ON DELETE RESTRICT ON UPDATE RESTRICT |
||||
); |
||||
|
||||
CREATE TABLE "T_constraints_4" |
||||
( |
||||
"C_id" INT NOT NULL PRIMARY KEY, |
||||
"C_col_1" INT NULL, |
||||
"C_col_2" INT NOT NULL, |
||||
CONSTRAINT "CN_constraints_4" UNIQUE ("C_col_1", "C_col_2") |
||||
); |
||||
|
||||
CREATE TABLE "T_upsert" |
||||
( |
||||
"id" INT NOT NULL PRIMARY KEY AUTO_INCREMENT, |
||||
"ts" INT NULL, |
||||
"email" VARCHAR(128) NOT NULL UNIQUE, |
||||
"recovery_email" VARCHAR(128) NULL, |
||||
"address" STRING NULL, |
||||
"status" TINYINT NOT NULL DEFAULT 0, |
||||
"orders" INT NOT NULL DEFAULT 0, |
||||
"profile_id" INT NULL, |
||||
UNIQUE ("email", "recovery_email") |
||||
); |
@ -1,74 +0,0 @@
|
||||
#!/bin/sh -e |
||||
# |
||||
# install CUBRID DBMS |
||||
|
||||
CWD=$(pwd) |
||||
|
||||
# cubrid dbms |
||||
mkdir -p cubrid/$CUBRID_VERSION |
||||
cd cubrid |
||||
if (test -f $CUBRID_VERSION-linux.x86_64.tar.gz); then |
||||
echo "CUBRID is already downloaded" |
||||
else |
||||
wget http://ftp.cubrid.org/CUBRID_Engine/$CUBRID_VERSION-linux.x86_64.tar.gz -O $CUBRID_VERSION-linux.x86_64.tar.gz |
||||
cd $CUBRID_VERSION |
||||
tar xzf ../../$CUBRID_VERSION-linux.x86_64.tar.gz |
||||
cd ../.. |
||||
fi |
||||
|
||||
echo "setting cubrid env" |
||||
CUBRID=$CWD/cubrid/$CUBRID_VERSION/CUBRID |
||||
CUBRID_DATABASES=$CUBRID/databases |
||||
CUBRID_LANG=en_US |
||||
|
||||
ld_lib_path=`printenv LD_LIBRARY_PATH` || echo "LD_LIBRARY_PATH is empty" |
||||
if [ "$ld_lib_path" = "" ] |
||||
then |
||||
LD_LIBRARY_PATH=$CUBRID/lib |
||||
else |
||||
LD_LIBRARY_PATH=$CUBRID/lib:$LD_LIBRARY_PATH |
||||
fi |
||||
|
||||
SHLIB_PATH=$LD_LIBRARY_PATH |
||||
LIBPATH=$LD_LIBRARY_PATH |
||||
PATH=$CUBRID/bin:$CUBRID/cubridmanager:$PATH |
||||
|
||||
export CUBRID |
||||
export CUBRID_DATABASES |
||||
export CUBRID_LANG |
||||
export LD_LIBRARY_PATH |
||||
export SHLIB_PATH |
||||
export LIBPATH |
||||
export PATH |
||||
|
||||
# start cubrid |
||||
echo "starting cubrid..." |
||||
cubrid service start || echo "starting CUBRID services failed with exit code $?" |
||||
# create and start the demo db |
||||
$CUBRID/demo/make_cubrid_demo.sh || echo "setting up CUBRID demodb failed with exit code $?" |
||||
cubrid server start demodb || (echo "starting CUBRID demodb failed with exit code $?" && cat demodb_loaddb.log) |
||||
|
||||
echo "" |
||||
echo "Installed CUBRID $CUBRID_VERSION" |
||||
echo "" |
||||
|
||||
# cubrid pdo |
||||
install_pdo_cubrid() { |
||||
if (test "! (-f PDO_CUBRID-$CUBRID_PDO_VERSION.tgz)"); then |
||||
wget "http://pecl.php.net/get/PDO_CUBRID-$CUBRID_PDO_VERSION.tgz" -O PDO_CUBRID-$CUBRID_PDO_VERSION.tgz |
||||
fi |
||||
tar -zxf "PDO_CUBRID-$CUBRID_PDO_VERSION.tgz" |
||||
sh -c "cd PDO_CUBRID-$CUBRID_PDO_VERSION && phpize && ./configure --prefix=$CWD/cubrid/PDO_CUBRID-$CUBRID_PDO_VERSION && make" |
||||
|
||||
echo "extension=$CWD/cubrid/PDO_CUBRID-$CUBRID_PDO_VERSION/modules/pdo_cubrid.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini |
||||
|
||||
return $? |
||||
} |
||||
|
||||
install_pdo_cubrid > ~/pdo_cubrid.log || ( echo "=== PDO CUBRID BUILD FAILED ==="; cat ~/pdo_cubrid.log; exit 1 ) |
||||
|
||||
echo "" |
||||
echo "Installed CUBRID PDO $CUBRID_PDO_VERSION" |
||||
echo "" |
||||
|
||||
cd .. |
@ -1,5 +0,0 @@
|
||||
file_cache_path "/tmp/chef-solo" |
||||
data_bag_path "/tmp/chef-solo/data_bags" |
||||
encrypted_data_bag_secret "/tmp/chef-solo/data_bag_key" |
||||
cookbook_path [ "/tmp/chef-solo/cookbooks" ] |
||||
role_path "/tmp/chef-solo/roles" |
@ -1,18 +0,0 @@
|
||||
<?php |
||||
/** |
||||
* @link http://www.yiiframework.com/ |
||||
* @copyright Copyright (c) 2008 Yii Software LLC |
||||
* @license http://www.yiiframework.com/license/ |
||||
*/ |
||||
|
||||
namespace yiiunit\framework\db\cubrid; |
||||
|
||||
/** |
||||
* @group db |
||||
* @group cubrid |
||||
* @group data |
||||
*/ |
||||
class ActiveDataProviderTest extends \yiiunit\framework\data\ActiveDataProviderTest |
||||
{ |
||||
public $driverName = 'cubrid'; |
||||
} |
@ -1,18 +0,0 @@
|
||||
<?php |
||||
/** |
||||
* @link http://www.yiiframework.com/ |
||||
* @copyright Copyright (c) 2008 Yii Software LLC |
||||
* @license http://www.yiiframework.com/license/ |
||||
*/ |
||||
|
||||
namespace yiiunit\framework\db\cubrid; |
||||
|
||||
/** |
||||
* @group db |
||||
* @group cubrid |
||||
* @group test |
||||
*/ |
||||
class ActiveFixtureTest extends \yiiunit\framework\test\ActiveFixtureTest |
||||
{ |
||||
public $driverName = 'cubrid'; |
||||
} |
@ -1,17 +0,0 @@
|
||||
<?php |
||||
/** |
||||
* @link http://www.yiiframework.com/ |
||||
* @copyright Copyright (c) 2008 Yii Software LLC |
||||
* @license http://www.yiiframework.com/license/ |
||||
*/ |
||||
|
||||
namespace yiiunit\framework\db\cubrid; |
||||
|
||||
/** |
||||
* @group db |
||||
* @group cubrid |
||||
*/ |
||||
class ActiveQueryTest extends \yiiunit\framework\db\ActiveQueryTest |
||||
{ |
||||
public $driverName = 'cubrid'; |
||||
} |
@ -1,17 +0,0 @@
|
||||
<?php |
||||
/** |
||||
* @link http://www.yiiframework.com/ |
||||
* @copyright Copyright (c) 2008 Yii Software LLC |
||||
* @license http://www.yiiframework.com/license/ |
||||
*/ |
||||
|
||||
namespace yiiunit\framework\db\cubrid; |
||||
|
||||
/** |
||||
* @group db |
||||
* @group cubrid |
||||
*/ |
||||
class ActiveRecordTest extends \yiiunit\framework\db\ActiveRecordTest |
||||
{ |
||||
public $driverName = 'cubrid'; |
||||
} |
@ -1,17 +0,0 @@
|
||||
<?php |
||||
/** |
||||
* @link http://www.yiiframework.com/ |
||||
* @copyright Copyright (c) 2008 Yii Software LLC |
||||
* @license http://www.yiiframework.com/license/ |
||||
*/ |
||||
|
||||
namespace yiiunit\framework\db\cubrid; |
||||
|
||||
/** |
||||
* @group db |
||||
* @group cubrid |
||||
*/ |
||||
class BatchQueryResultTest extends \yiiunit\framework\db\BatchQueryResultTest |
||||
{ |
||||
public $driverName = 'cubrid'; |
||||
} |
@ -1,49 +0,0 @@
|
||||
<?php |
||||
/** |
||||
* @link http://www.yiiframework.com/ |
||||
* @copyright Copyright (c) 2008 Yii Software LLC |
||||
* @license http://www.yiiframework.com/license/ |
||||
*/ |
||||
|
||||
namespace yiiunit\framework\db\cubrid; |
||||
|
||||
use yii\db\cubrid\ColumnSchemaBuilder; |
||||
use yii\db\Schema; |
||||
|
||||
/** |
||||
* ColumnSchemaBuilderTest tests ColumnSchemaBuilder for Cubrid. |
||||
* @group db |
||||
* @group cubrid |
||||
*/ |
||||
class ColumnSchemaBuilderTest extends \yiiunit\framework\db\ColumnSchemaBuilderTest |
||||
{ |
||||
public $driverName = 'cubrid'; |
||||
|
||||
/** |
||||
* @param string $type |
||||
* @param int $length |
||||
* @return ColumnSchemaBuilder |
||||
*/ |
||||
public function getColumnSchemaBuilder($type, $length = null) |
||||
{ |
||||
return new ColumnSchemaBuilder($type, $length, $this->getConnection()); |
||||
} |
||||
|
||||
/** |
||||
* @return array |
||||
*/ |
||||
public function typesProvider() |
||||
{ |
||||
return [ |
||||
['integer UNSIGNED', Schema::TYPE_INTEGER, null, [ |
||||
['unsigned'], |
||||
]], |
||||
['integer(10) UNSIGNED', Schema::TYPE_INTEGER, 10, [ |
||||
['unsigned'], |
||||
]], |
||||
['integer(10) COMMENT \'test\'', Schema::TYPE_INTEGER, 10, [ |
||||
['comment', 'test'], |
||||
]], |
||||
]; |
||||
} |
||||
} |
@ -1,100 +0,0 @@
|
||||
<?php |
||||
/** |
||||
* @link http://www.yiiframework.com/ |
||||
* @copyright Copyright (c) 2008 Yii Software LLC |
||||
* @license http://www.yiiframework.com/license/ |
||||
*/ |
||||
|
||||
namespace yiiunit\framework\db\cubrid; |
||||
|
||||
/** |
||||
* @group db |
||||
* @group cubrid |
||||
*/ |
||||
class CommandTest extends \yiiunit\framework\db\CommandTest |
||||
{ |
||||
public $driverName = 'cubrid'; |
||||
|
||||
public function testBindParamValue() |
||||
{ |
||||
$db = $this->getConnection(); |
||||
|
||||
// bindParam |
||||
$sql = 'INSERT INTO customer(email, name, address) VALUES (:email, :name, :address)'; |
||||
$command = $db->createCommand($sql); |
||||
$email = 'user4@example.com'; |
||||
$name = 'user4'; |
||||
$address = 'address4'; |
||||
$command->bindParam(':email', $email); |
||||
$command->bindParam(':name', $name); |
||||
$command->bindParam(':address', $address); |
||||
$command->execute(); |
||||
|
||||
$sql = 'SELECT name FROM customer WHERE email=:email'; |
||||
$command = $db->createCommand($sql); |
||||
$command->bindParam(':email', $email); |
||||
$this->assertEquals($name, $command->queryScalar()); |
||||
|
||||
$sql = "INSERT INTO type (int_col, char_col, char_col2, enum_col, float_col, blob_col, numeric_col, bool_col) VALUES (:int_col, '', :char_col, :enum_col, :float_col, CHAR_TO_BLOB(:blob_col), :numeric_col, :bool_col)"; |
||||
$command = $db->createCommand($sql); |
||||
$intCol = 123; |
||||
$charCol = 'abc'; |
||||
$enumCol = 'a'; |
||||
$floatCol = 1.23; |
||||
$blobCol = "\x10\x11\x12"; |
||||
$numericCol = '1.23'; |
||||
$boolCol = true; |
||||
$command->bindParam(':int_col', $intCol); |
||||
$command->bindParam(':char_col', $charCol); |
||||
$command->bindParam(':enum_col', $enumCol); |
||||
$command->bindParam(':float_col', $floatCol); |
||||
$command->bindParam(':blob_col', $blobCol); |
||||
$command->bindParam(':numeric_col', $numericCol); |
||||
$command->bindParam(':bool_col', $boolCol); |
||||
$this->assertEquals(1, $command->execute()); |
||||
|
||||
$sql = 'SELECT * FROM type'; |
||||
$row = $db->createCommand($sql)->queryOne(); |
||||
$this->assertEquals($intCol, $row['int_col']); |
||||
$this->assertEquals($enumCol, $row['enum_col']); |
||||
$this->assertEquals($charCol, $row['char_col2']); |
||||
$this->assertEquals($floatCol, $row['float_col']); |
||||
$this->assertEquals($blobCol, fread($row['blob_col'], 3)); |
||||
$this->assertEquals($numericCol, $row['numeric_col']); |
||||
$this->assertEquals($boolCol, $row['bool_col']); |
||||
|
||||
// bindValue |
||||
$sql = 'INSERT INTO customer(email, name, address) VALUES (:email, \'user5\', \'address5\')'; |
||||
$command = $db->createCommand($sql); |
||||
$command->bindValue(':email', 'user5@example.com'); |
||||
$command->execute(); |
||||
|
||||
$sql = 'SELECT email FROM customer WHERE name=:name'; |
||||
$command = $db->createCommand($sql); |
||||
$command->bindValue(':name', 'user5'); |
||||
$this->assertEquals('user5@example.com', $command->queryScalar()); |
||||
} |
||||
|
||||
public function testAutoQuoting() |
||||
{ |
||||
$db = $this->getConnection(false); |
||||
|
||||
$sql = 'SELECT [[id]], [[t.name]] FROM {{customer}} t'; |
||||
$command = $db->createCommand($sql); |
||||
$this->assertEquals('SELECT "id", "t"."name" FROM "customer" t', $command->sql); |
||||
} |
||||
|
||||
public function batchInsertSqlProvider() |
||||
{ |
||||
$data = parent::batchInsertSqlProvider(); |
||||
$data['issue11242']['expected'] = 'INSERT INTO "type" ("int_col", "float_col", "char_col") VALUES (NULL, NULL, \'Kyiv {{city}}, Ukraine\')'; |
||||
$data['wrongBehavior']['expected'] = 'INSERT INTO "type" ("int_col", "float_col", "char_col") VALUES (\'\', \'\', \'Kyiv {{city}}, Ukraine\')'; |
||||
|
||||
return $data; |
||||
} |
||||
|
||||
public function testAddDropCheck() |
||||
{ |
||||
$this->markTestSkipped('CUBRID does not support adding/dropping check constraints.'); |
||||
} |
||||
} |
@ -1,72 +0,0 @@
|
||||
<?php |
||||
/** |
||||
* @link http://www.yiiframework.com/ |
||||
* @copyright Copyright (c) 2008 Yii Software LLC |
||||
* @license http://www.yiiframework.com/license/ |
||||
*/ |
||||
|
||||
namespace yiiunit\framework\db\cubrid; |
||||
|
||||
/** |
||||
* @group db |
||||
* @group cubrid |
||||
*/ |
||||
class ConnectionTest extends \yiiunit\framework\db\ConnectionTest |
||||
{ |
||||
public $driverName = 'cubrid'; |
||||
|
||||
public function testQuoteValue() |
||||
{ |
||||
$connection = $this->getConnection(false); |
||||
$this->assertEquals(123, $connection->quoteValue(123)); |
||||
$this->assertEquals("'string'", $connection->quoteValue('string')); |
||||
$this->assertEquals("'It''s interesting'", $connection->quoteValue("It's interesting")); |
||||
} |
||||
|
||||
public function testQuoteTableName() |
||||
{ |
||||
$connection = $this->getConnection(false); |
||||
$this->assertEquals('"table"', $connection->quoteTableName('table')); |
||||
$this->assertEquals('"table"', $connection->quoteTableName('"table"')); |
||||
$this->assertEquals('"schema"."table"', $connection->quoteTableName('schema.table')); |
||||
$this->assertEquals('"schema"."table"', $connection->quoteTableName('schema."table"')); |
||||
$this->assertEquals('"schema"."table"', $connection->quoteTableName('"schema"."table"')); |
||||
$this->assertEquals('{{table}}', $connection->quoteTableName('{{table}}')); |
||||
$this->assertEquals('(table)', $connection->quoteTableName('(table)')); |
||||
} |
||||
|
||||
public function testQuoteColumnName() |
||||
{ |
||||
$connection = $this->getConnection(false); |
||||
$this->assertEquals('"column"', $connection->quoteColumnName('column')); |
||||
$this->assertEquals('"column"', $connection->quoteColumnName('"column"')); |
||||
$this->assertEquals('[[column]]', $connection->quoteColumnName('[[column]]')); |
||||
$this->assertEquals('{{column}}', $connection->quoteColumnName('{{column}}')); |
||||
$this->assertEquals('(column)', $connection->quoteColumnName('(column)')); |
||||
|
||||
$this->assertEquals('"column"', $connection->quoteSql('[[column]]')); |
||||
$this->assertEquals('"column"', $connection->quoteSql('{{column}}')); |
||||
} |
||||
|
||||
public function testQuoteFullColumnName() |
||||
{ |
||||
$connection = $this->getConnection(false, false); |
||||
$this->assertEquals('"table"."column"', $connection->quoteColumnName('table.column')); |
||||
$this->assertEquals('"table"."column"', $connection->quoteColumnName('table."column"')); |
||||
$this->assertEquals('"table"."column"', $connection->quoteColumnName('"table".column')); |
||||
$this->assertEquals('"table"."column"', $connection->quoteColumnName('"table"."column"')); |
||||
|
||||
$this->assertEquals('[[table.column]]', $connection->quoteColumnName('[[table.column]]')); |
||||
$this->assertEquals('{{table}}."column"', $connection->quoteColumnName('{{table}}.column')); |
||||
$this->assertEquals('{{table}}."column"', $connection->quoteColumnName('{{table}}."column"')); |
||||
$this->assertEquals('{{table}}.[[column]]', $connection->quoteColumnName('{{table}}.[[column]]')); |
||||
$this->assertEquals('{{%table}}."column"', $connection->quoteColumnName('{{%table}}.column')); |
||||
$this->assertEquals('{{%table}}."column"', $connection->quoteColumnName('{{%table}}."column"')); |
||||
|
||||
$this->assertEquals('"table"."column"', $connection->quoteSql('[[table.column]]')); |
||||
$this->assertEquals('"table"."column"', $connection->quoteSql('{{table}}.[[column]]')); |
||||
$this->assertEquals('"table"."column"', $connection->quoteSql('{{table}}."column"')); |
||||
$this->assertEquals('"table"."column"', $connection->quoteSql('{{%table}}.[[column]]')); |
||||
$this->assertEquals('"table"."column"', $connection->quoteSql('{{%table}}."column"')); |
||||
} |
||||
} |
@ -1,18 +0,0 @@
|
||||
<?php |
||||
/** |
||||
* @link http://www.yiiframework.com/ |
||||
* @copyright Copyright (c) 2008 Yii Software LLC |
||||
* @license http://www.yiiframework.com/license/ |
||||
*/ |
||||
|
||||
namespace yiiunit\framework\db\cubrid; |
||||
|
||||
/** |
||||
* @group db |
||||
* @group cubrid |
||||
* @group validators |
||||
*/ |
||||
class ExistValidatorTest extends \yiiunit\framework\validators\ExistValidatorTest |
||||
{ |
||||
public $driverName = 'cubrid'; |
||||
} |
@ -1,112 +0,0 @@
|
||||
<?php |
||||
/** |
||||
* @link http://www.yiiframework.com/ |
||||
* @copyright Copyright (c) 2008 Yii Software LLC |
||||
* @license http://www.yiiframework.com/license/ |
||||
*/ |
||||
|
||||
namespace yiiunit\framework\db\cubrid; |
||||
|
||||
/** |
||||
* @group db |
||||
* @group cubrid |
||||
*/ |
||||
class QueryBuilderTest extends \yiiunit\framework\db\QueryBuilderTest |
||||
{ |
||||
public $driverName = 'cubrid'; |
||||
|
||||
protected $likeEscapeCharSql = " ESCAPE '!'"; |
||||
protected $likeParameterReplacements = [ |
||||
'\%' => '!%', |
||||
'\_' => '!_', |
||||
'\!' => '!!', |
||||
'\\\\' => '\\', |
||||
]; |
||||
|
||||
/** |
||||
* This is not used as a dataprovider for testGetColumnType to speed up the test |
||||
* when used as dataprovider every single line will cause a reconnect with the database which is not needed here. |
||||
*/ |
||||
public function columnTypes() |
||||
{ |
||||
return array_merge(parent::columnTypes(), []); |
||||
} |
||||
|
||||
public function checksProvider() |
||||
{ |
||||
$this->markTestSkipped('Adding/dropping check constraints is not supported in CUBRID.'); |
||||
} |
||||
|
||||
public function defaultValuesProvider() |
||||
{ |
||||
$this->markTestSkipped('Adding/dropping default constraints is not supported in CUBRID.'); |
||||
} |
||||
|
||||
public function testResetSequence() |
||||
{ |
||||
$qb = $this->getQueryBuilder(); |
||||
|
||||
$expected = 'ALTER TABLE "item" AUTO_INCREMENT=6;'; |
||||
$sql = $qb->resetSequence('item'); |
||||
$this->assertEquals($expected, $sql); |
||||
|
||||
$expected = 'ALTER TABLE "item" AUTO_INCREMENT=4;'; |
||||
$sql = $qb->resetSequence('item', 4); |
||||
$this->assertEquals($expected, $sql); |
||||
} |
||||
|
||||
public function testCommentColumn() |
||||
{ |
||||
$version = $this->getQueryBuilder(false)->db->getSlavePdo()->getAttribute(\PDO::ATTR_SERVER_VERSION); |
||||
if (version_compare($version, '10.0', '<')) { |
||||
$this->markTestSkipped('Comments on columns are supported starting with CUBRID 10.0.'); |
||||
return; |
||||
} |
||||
|
||||
parent::testCommentColumn(); |
||||
} |
||||
|
||||
public function upsertProvider() |
||||
{ |
||||
$concreteData = [ |
||||
'regular values' => [ |
||||
3 => 'MERGE INTO "T_upsert" USING (VALUES (:qp0, :qp1, :qp2, :qp3)) AS "EXCLUDED" ("email", "address", "status", "profile_id") ON ("T_upsert"."email"="EXCLUDED"."email") WHEN MATCHED THEN UPDATE SET "address"="EXCLUDED"."address", "status"="EXCLUDED"."status", "profile_id"="EXCLUDED"."profile_id" WHEN NOT MATCHED THEN INSERT ("email", "address", "status", "profile_id") VALUES ("EXCLUDED"."email", "EXCLUDED"."address", "EXCLUDED"."status", "EXCLUDED"."profile_id")', |
||||
], |
||||
'regular values with update part' => [ |
||||
3 => 'MERGE INTO "T_upsert" USING (VALUES (:qp0, :qp1, :qp2, :qp3)) AS "EXCLUDED" ("email", "address", "status", "profile_id") ON ("T_upsert"."email"="EXCLUDED"."email") WHEN MATCHED THEN UPDATE SET "address"=:qp4, "status"=:qp5, "orders"=T_upsert.orders + 1 WHEN NOT MATCHED THEN INSERT ("email", "address", "status", "profile_id") VALUES ("EXCLUDED"."email", "EXCLUDED"."address", "EXCLUDED"."status", "EXCLUDED"."profile_id")', |
||||
], |
||||
'regular values without update part' => [ |
||||
3 => 'MERGE INTO "T_upsert" USING (VALUES (:qp0, :qp1, :qp2, :qp3)) AS "EXCLUDED" ("email", "address", "status", "profile_id") ON ("T_upsert"."email"="EXCLUDED"."email") WHEN NOT MATCHED THEN INSERT ("email", "address", "status", "profile_id") VALUES ("EXCLUDED"."email", "EXCLUDED"."address", "EXCLUDED"."status", "EXCLUDED"."profile_id")', |
||||
], |
||||
'query' => [ |
||||
3 => 'MERGE INTO "T_upsert" USING (SELECT "email", 2 AS "status" FROM "customer" WHERE "name"=:qp0 LIMIT 1) AS "EXCLUDED" ("email", "status") ON ("T_upsert"."email"="EXCLUDED"."email") WHEN MATCHED THEN UPDATE SET "status"="EXCLUDED"."status" WHEN NOT MATCHED THEN INSERT ("email", "status") VALUES ("EXCLUDED"."email", "EXCLUDED"."status")', |
||||
], |
||||
'query with update part' => [ |
||||
3 => 'MERGE INTO "T_upsert" USING (SELECT "email", 2 AS "status" FROM "customer" WHERE "name"=:qp0 LIMIT 1) AS "EXCLUDED" ("email", "status") ON ("T_upsert"."email"="EXCLUDED"."email") WHEN MATCHED THEN UPDATE SET "address"=:qp1, "status"=:qp2, "orders"=T_upsert.orders + 1 WHEN NOT MATCHED THEN INSERT ("email", "status") VALUES ("EXCLUDED"."email", "EXCLUDED"."status")', |
||||
], |
||||
'query without update part' => [ |
||||
3 => 'MERGE INTO "T_upsert" USING (SELECT "email", 2 AS "status" FROM "customer" WHERE "name"=:qp0 LIMIT 1) AS "EXCLUDED" ("email", "status") ON ("T_upsert"."email"="EXCLUDED"."email") WHEN NOT MATCHED THEN INSERT ("email", "status") VALUES ("EXCLUDED"."email", "EXCLUDED"."status")', |
||||
], |
||||
'values and expressions' => [ |
||||
3 => 'INSERT INTO {{%T_upsert}} ({{%T_upsert}}.[[email]], [[ts]]) VALUES (:qp0, now())', |
||||
], |
||||
'values and expressions with update part' => [ |
||||
3 => 'INSERT INTO {{%T_upsert}} ({{%T_upsert}}.[[email]], [[ts]]) VALUES (:qp0, now())', |
||||
], |
||||
'values and expressions without update part' => [ |
||||
3 => 'INSERT INTO {{%T_upsert}} ({{%T_upsert}}.[[email]], [[ts]]) VALUES (:qp0, now())', |
||||
], |
||||
'query, values and expressions with update part' => [ |
||||
3 => 'MERGE INTO {{%T_upsert}} USING (SELECT :phEmail AS "email", now() AS [[time]]) AS "EXCLUDED" ("email", [[time]]) ON ({{%T_upsert}}."email"="EXCLUDED"."email") WHEN MATCHED THEN UPDATE SET "ts"=:qp1, [[orders]]=T_upsert.orders + 1 WHEN NOT MATCHED THEN INSERT ("email", [[time]]) VALUES ("EXCLUDED"."email", "EXCLUDED".[[time]])', |
||||
], |
||||
'query, values and expressions without update part' => [ |
||||
3 => 'MERGE INTO {{%T_upsert}} USING (SELECT :phEmail AS "email", now() AS [[time]]) AS "EXCLUDED" ("email", [[time]]) ON ({{%T_upsert}}."email"="EXCLUDED"."email") WHEN MATCHED THEN UPDATE SET "ts"=:qp1, [[orders]]=T_upsert.orders + 1 WHEN NOT MATCHED THEN INSERT ("email", [[time]]) VALUES ("EXCLUDED"."email", "EXCLUDED".[[time]])', |
||||
], |
||||
]; |
||||
$newData = parent::upsertProvider(); |
||||
foreach ($concreteData as $testName => $data) { |
||||
$newData[$testName] = array_replace($newData[$testName], $data); |
||||
} |
||||
return $newData; |
||||
} |
||||
} |
@ -1,17 +0,0 @@
|
||||
<?php |
||||
/** |
||||
* @link http://www.yiiframework.com/ |
||||
* @copyright Copyright (c) 2008 Yii Software LLC |
||||
* @license http://www.yiiframework.com/license/ |
||||
*/ |
||||
|
||||
namespace yiiunit\framework\db\cubrid; |
||||
|
||||
/** |
||||
* @group db |
||||
* @group cubrid |
||||
*/ |
||||
class QueryTest extends \yiiunit\framework\db\QueryTest |
||||
{ |
||||
public $driverName = 'cubrid'; |
||||
} |
@ -1,146 +0,0 @@
|
||||
<?php |
||||
/** |
||||
* @link http://www.yiiframework.com/ |
||||
* @copyright Copyright (c) 2008 Yii Software LLC |
||||
* @license http://www.yiiframework.com/license/ |
||||
*/ |
||||
|
||||
namespace yiiunit\framework\db\cubrid; |
||||
|
||||
use yii\db\Expression; |
||||
use yiiunit\framework\db\AnyCaseValue; |
||||
|
||||
/** |
||||
* @group db |
||||
* @group cubrid |
||||
*/ |
||||
class SchemaTest extends \yiiunit\framework\db\SchemaTest |
||||
{ |
||||
public $driverName = 'cubrid'; |
||||
|
||||
public function testGetSchemaNames() |
||||
{ |
||||
$this->markTestSkipped('Schemas are not supported in CUBRID.'); |
||||
} |
||||
|
||||
public function testGetPDOType() |
||||
{ |
||||
$values = [ |
||||
[null, \PDO::PARAM_NULL], |
||||
['', \PDO::PARAM_STR], |
||||
['hello', \PDO::PARAM_STR], |
||||
[0, \PDO::PARAM_INT], |
||||
[1, \PDO::PARAM_INT], |
||||
[1337, \PDO::PARAM_INT], |
||||
[true, \PDO::PARAM_INT], |
||||
[false, \PDO::PARAM_INT], |
||||
[$fp = fopen(__FILE__, 'rb'), \PDO::PARAM_LOB], |
||||
]; |
||||
|
||||
$schema = $this->getConnection()->schema; |
||||
|
||||
foreach ($values as $value) { |
||||
$this->assertEquals($value[1], $schema->getPdoType($value[0])); |
||||
} |
||||
fclose($fp); |
||||
} |
||||
|
||||
|
||||
public function getExpectedColumns() |
||||
{ |
||||
$columns = parent::getExpectedColumns(); |
||||
unset($columns['json_col']); |
||||
$columns['int_col']['dbType'] = 'integer'; |
||||
$columns['int_col']['size'] = null; |
||||
$columns['int_col']['precision'] = null; |
||||
$columns['int_col2']['dbType'] = 'integer'; |
||||
$columns['int_col2']['size'] = null; |
||||
$columns['int_col2']['precision'] = null; |
||||
$columns['tinyint_col']['smallint'] = 'short'; |
||||
$columns['tinyint_col']['dbType'] = 'short'; |
||||
$columns['tinyint_col']['size'] = null; |
||||
$columns['tinyint_col']['precision'] = null; |
||||
$columns['smallint_col']['dbType'] = 'short'; |
||||
$columns['smallint_col']['size'] = null; |
||||
$columns['smallint_col']['precision'] = null; |
||||
$columns['char_col3']['type'] = 'string'; |
||||
$columns['char_col3']['dbType'] = 'varchar(1073741823)'; |
||||
$columns['char_col3']['size'] = 1073741823; |
||||
$columns['char_col3']['precision'] = 1073741823; |
||||
$columns['enum_col']['dbType'] = "enum('a', 'B')"; |
||||
$columns['float_col']['dbType'] = 'double'; |
||||
$columns['float_col']['size'] = null; |
||||
$columns['float_col']['precision'] = null; |
||||
$columns['float_col']['scale'] = null; |
||||
$columns['numeric_col']['dbType'] = 'numeric(5,2)'; |
||||
$columns['blob_col']['phpType'] = 'resource'; |
||||
$columns['blob_col']['type'] = 'binary'; |
||||
$columns['bool_col']['dbType'] = 'short'; |
||||
$columns['bool_col']['size'] = null; |
||||
$columns['bool_col']['precision'] = null; |
||||
$columns['bool_col2']['dbType'] = 'short'; |
||||
$columns['bool_col2']['size'] = null; |
||||
$columns['bool_col2']['precision'] = null; |
||||
$columns['time']['defaultValue'] = '12:00:00 AM 01/01/2002'; |
||||
$columns['ts_default']['defaultValue'] = new Expression('SYS_TIMESTAMP'); |
||||
return $columns; |
||||
} |
||||
|
||||
public function constraintsProvider() |
||||
{ |
||||
$result = parent::constraintsProvider(); |
||||
foreach ($result as $name => $constraints) { |
||||
$result[$name][2] = $this->convertPropertiesToAnycase($constraints[2]); |
||||
} |
||||
$result['1: check'][2] = false; |
||||
unset($result['1: index'][2][0]); |
||||
|
||||
$result['2: check'][2] = false; |
||||
unset($result['2: index'][2][0]); |
||||
|
||||
$result['3: foreign key'][2][0]->onDelete = 'RESTRICT'; |
||||
$result['3: foreign key'][2][0]->onUpdate = 'RESTRICT'; |
||||
$result['3: index'][2] = []; |
||||
$result['3: check'][2] = false; |
||||
|
||||
$result['4: check'][2] = false; |
||||
return $result; |
||||
} |
||||
|
||||
public function lowercaseConstraintsProvider() |
||||
{ |
||||
$this->markTestSkipped('This test hangs on CUBRID.'); |
||||
} |
||||
|
||||
public function uppercaseConstraintsProvider() |
||||
{ |
||||
$this->markTestSkipped('This test hangs on CUBRID.'); |
||||
} |
||||
|
||||
/** |
||||
* @param array|object|string $object |
||||
* @param bool $isProperty |
||||
* @return array|object|string |
||||
*/ |
||||
private function convertPropertiesToAnycase($object, $isProperty = false) |
||||
{ |
||||
if (!$isProperty && \is_array($object)) { |
||||
$result = []; |
||||
foreach ($object as $name => $value) { |
||||
$result[] = $this->convertPropertiesToAnycase($value); |
||||
} |
||||
|
||||
return $result; |
||||
} |
||||
|
||||
if (\is_object($object)) { |
||||
foreach (array_keys((array) $object) as $name) { |
||||
$object->$name = $this->convertPropertiesToAnycase($object->$name, true); |
||||
} |
||||
} elseif (\is_array($object) || \is_string($object)) { |
||||
$object = new AnyCaseValue($object); |
||||
} |
||||
|
||||
return $object; |
||||
} |
||||
} |
@ -1,18 +0,0 @@
|
||||
<?php |
||||
/** |
||||
* @link http://www.yiiframework.com/ |
||||
* @copyright Copyright (c) 2008 Yii Software LLC |
||||
* @license http://www.yiiframework.com/license/ |
||||
*/ |
||||
|
||||
namespace yiiunit\framework\db\cubrid; |
||||
|
||||
/** |
||||
* @group db |
||||
* @group cubrid |
||||
* @group validators |
||||
*/ |
||||
class UniqueValidatorTest extends \yiiunit\framework\validators\UniqueValidatorTest |
||||
{ |
||||
public $driverName = 'cubrid'; |
||||
} |
Loading…
Reference in new issue