1 | <?php |
||
20 | class QueryBuilder extends \yii\db\QueryBuilder |
||
21 | { |
||
22 | /** |
||
23 | * @var array mapping from abstract column types (keys) to physical column types (values). |
||
24 | */ |
||
25 | public $typeMap = [ |
||
26 | Schema::TYPE_PK => 'int NOT NULL AUTO_INCREMENT PRIMARY KEY', |
||
27 | Schema::TYPE_UPK => 'int UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY', |
||
28 | Schema::TYPE_BIGPK => 'bigint NOT NULL AUTO_INCREMENT PRIMARY KEY', |
||
29 | Schema::TYPE_UBIGPK => 'bigint UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY', |
||
30 | Schema::TYPE_CHAR => 'char(1)', |
||
31 | Schema::TYPE_STRING => 'varchar(255)', |
||
32 | Schema::TYPE_TEXT => 'varchar', |
||
33 | Schema::TYPE_SMALLINT => 'smallint', |
||
34 | Schema::TYPE_INTEGER => 'int', |
||
35 | Schema::TYPE_BIGINT => 'bigint', |
||
36 | Schema::TYPE_FLOAT => 'float(7)', |
||
37 | Schema::TYPE_DOUBLE => 'double(15)', |
||
38 | Schema::TYPE_DECIMAL => 'decimal(10,0)', |
||
39 | Schema::TYPE_DATETIME => 'datetime', |
||
40 | Schema::TYPE_TIMESTAMP => 'timestamp', |
||
41 | Schema::TYPE_TIME => 'time', |
||
42 | Schema::TYPE_DATE => 'date', |
||
43 | Schema::TYPE_BINARY => 'blob', |
||
44 | Schema::TYPE_BOOLEAN => 'smallint', |
||
45 | Schema::TYPE_MONEY => 'decimal(19,4)', |
||
46 | ]; |
||
47 | |||
48 | /** |
||
49 | * @inheritdoc |
||
50 | */ |
||
51 | protected $likeEscapeCharacter = '!'; |
||
52 | /** |
||
53 | * @inheritdoc |
||
54 | */ |
||
55 | protected $likeEscapingReplacements = [ |
||
56 | '%' => '!%', |
||
57 | '_' => '!_', |
||
58 | '!' => '!!', |
||
59 | ]; |
||
60 | |||
61 | |||
62 | /** |
||
63 | * Creates a SQL statement for resetting the sequence value of a table's primary key. |
||
64 | * The sequence will be reset such that the primary key of the next new row inserted |
||
65 | * will have the specified value or 1. |
||
66 | * @param string $tableName the name of the table whose primary key sequence will be reset |
||
67 | * @param mixed $value the value for the primary key of the next new row inserted. If this is not set, |
||
68 | * the next new row's primary key will have a value 1. |
||
69 | * @return string the SQL statement for resetting sequence |
||
70 | * @throws InvalidParamException if the table does not exist or there is no sequence associated with the table. |
||
71 | */ |
||
72 | public function resetSequence($tableName, $value = null) |
||
91 | |||
92 | /** |
||
93 | * @inheritdoc |
||
94 | */ |
||
95 | public function buildLimit($limit, $offset) |
||
112 | |||
113 | /** |
||
114 | * @inheritdoc |
||
115 | * @since 2.0.8 |
||
116 | */ |
||
117 | public function selectExists($rawSql) |
||
121 | |||
122 | /** |
||
123 | * @inheritDoc |
||
124 | * @see http://www.cubrid.org/manual/93/en/sql/schema/table.html#drop-index-clause |
||
125 | */ |
||
126 | public function dropIndex($name, $table) |
||
127 | { |
||
128 | /** @var Schema $schema */ |
||
129 | $schema = $this->db->getSchema(); |
||
130 | foreach ($schema->getTableUniques($table) as $unique) { |
||
131 | if ($unique->name === $name) { |
||
132 | return $this->dropUnique($name, $table); |
||
133 | } |
||
134 | } |
||
135 | |||
136 | return 'DROP INDEX ' . $this->db->quoteTableName($name) . ' ON ' . $this->db->quoteTableName($table); |
||
137 | } |
||
138 | |||
139 | /** |
||
140 | * @inheritDoc |
||
141 | * @throws NotSupportedException this is not supported by CUBRID. |
||
142 | */ |
||
143 | public function addCheck($name, $table, $expression) |
||
144 | { |
||
145 | throw new NotSupportedException(__METHOD__ . ' is not supported by CUBRID.'); |
||
146 | } |
||
147 | |||
148 | /** |
||
149 | * @inheritDoc |
||
150 | * @throws NotSupportedException this is not supported by CUBRID. |
||
151 | */ |
||
152 | public function dropCheck($name, $table) |
||
153 | { |
||
154 | throw new NotSupportedException(__METHOD__ . ' is not supported by CUBRID.'); |
||
155 | } |
||
156 | |||
157 | /** |
||
158 | * @inheritdoc |
||
159 | * @since 2.0.8 |
||
160 | */ |
||
161 | public function addCommentOnColumn($table, $column, $comment) |
||
162 | { |
||
163 | $definition = $this->getColumnDefinition($table, $column); |
||
164 | $definition = trim(preg_replace("/COMMENT '(.*?)'/i", '', $definition)); |
||
165 | |||
166 | return 'ALTER TABLE ' . $this->db->quoteTableName($table) |
||
167 | . ' CHANGE ' . $this->db->quoteColumnName($column) |
||
168 | . ' ' . $this->db->quoteColumnName($column) |
||
169 | . (empty($definition) ? '' : ' ' . $definition) |
||
170 | . ' COMMENT ' . $this->db->quoteValue($comment); |
||
171 | } |
||
172 | |||
173 | /** |
||
174 | * @inheritdoc |
||
175 | * @since 2.0.8 |
||
176 | */ |
||
177 | public function addCommentOnTable($table, $comment) |
||
181 | |||
182 | /** |
||
183 | * @inheritdoc |
||
184 | * @since 2.0.8 |
||
185 | */ |
||
186 | public function dropCommentFromColumn($table, $column) |
||
190 | |||
191 | /** |
||
192 | * @inheritdoc |
||
193 | * @since 2.0.8 |
||
194 | */ |
||
195 | public function dropCommentFromTable($table) |
||
199 | |||
200 | |||
201 | /** |
||
202 | * Gets column definition. |
||
203 | * |
||
204 | * @param string $table table name |
||
205 | * @param string $column column name |
||
206 | * @return null|string the column definition |
||
207 | * @throws Exception in case when table does not contain column |
||
208 | * @since 2.0.8 |
||
209 | */ |
||
210 | private function getColumnDefinition($table, $column) |
||
233 | } |
||
234 |