Complex classes like Schema often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Schema, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
38 | abstract class Schema extends Object |
||
39 | { |
||
40 | /** |
||
41 | * The following are the supported abstract column data types. |
||
42 | */ |
||
43 | const TYPE_PK = 'pk'; |
||
44 | const TYPE_UPK = 'upk'; |
||
45 | const TYPE_BIGPK = 'bigpk'; |
||
46 | const TYPE_UBIGPK = 'ubigpk'; |
||
47 | const TYPE_CHAR = 'char'; |
||
48 | const TYPE_STRING = 'string'; |
||
49 | const TYPE_TEXT = 'text'; |
||
50 | const TYPE_SMALLINT = 'smallint'; |
||
51 | const TYPE_INTEGER = 'integer'; |
||
52 | const TYPE_BIGINT = 'bigint'; |
||
53 | const TYPE_FLOAT = 'float'; |
||
54 | const TYPE_DOUBLE = 'double'; |
||
55 | const TYPE_DECIMAL = 'decimal'; |
||
56 | const TYPE_DATETIME = 'datetime'; |
||
57 | const TYPE_TIMESTAMP = 'timestamp'; |
||
58 | const TYPE_TIME = 'time'; |
||
59 | const TYPE_DATE = 'date'; |
||
60 | const TYPE_BINARY = 'binary'; |
||
61 | const TYPE_BOOLEAN = 'boolean'; |
||
62 | const TYPE_MONEY = 'money'; |
||
63 | |||
64 | /** |
||
65 | * @var Connection the database connection |
||
66 | */ |
||
67 | public $db; |
||
68 | /** |
||
69 | * @var string the default schema name used for the current session. |
||
70 | */ |
||
71 | public $defaultSchema; |
||
72 | /** |
||
73 | * @var array map of DB errors and corresponding exceptions |
||
74 | * If left part is found in DB error message exception class from the right part is used. |
||
75 | */ |
||
76 | public $exceptionMap = [ |
||
77 | 'SQLSTATE[23' => IntegrityException::class, |
||
78 | ]; |
||
79 | |||
80 | /** |
||
81 | * @var array list of ALL schema names in the database, except system schemas |
||
82 | */ |
||
83 | private $_schemaNames; |
||
84 | /** |
||
85 | * @var array list of ALL table names in the database |
||
86 | */ |
||
87 | private $_tableNames = []; |
||
88 | /** |
||
89 | * @var array list of loaded table metadata (table name => TableSchema) |
||
90 | */ |
||
91 | private $_tables = []; |
||
92 | /** |
||
93 | * @var QueryBuilder the query builder for this database |
||
94 | */ |
||
95 | private $_builder; |
||
96 | |||
97 | |||
98 | /** |
||
99 | * @return \yii\db\ColumnSchema |
||
100 | * @throws \yii\base\InvalidConfigException |
||
101 | */ |
||
102 | 366 | protected function createColumnSchema() |
|
103 | { |
||
104 | 366 | return Yii::createObject(ColumnSchema::class); |
|
105 | } |
||
106 | |||
107 | /** |
||
108 | * Loads the metadata for the specified table. |
||
109 | * @param string $name table name |
||
110 | * @return null|TableSchema DBMS-dependent table metadata, null if the table does not exist. |
||
111 | */ |
||
112 | abstract protected function loadTableSchema($name); |
||
113 | |||
114 | /** |
||
115 | * Obtains the metadata for the named table. |
||
116 | * @param string $name table name. The table name may contain schema name if any. Do not quote the table name. |
||
117 | * @param boolean $refresh whether to reload the table schema even if it is found in the cache. |
||
118 | * @return null|TableSchema table metadata. Null if the named table does not exist. |
||
119 | */ |
||
120 | 440 | public function getTableSchema($name, $refresh = false) |
|
121 | { |
||
122 | 440 | if (array_key_exists($name, $this->_tables) && !$refresh) { |
|
123 | 383 | return $this->_tables[$name]; |
|
124 | } |
||
125 | |||
126 | 376 | $db = $this->db; |
|
127 | 376 | $realName = $this->getRawTableName($name); |
|
128 | |||
129 | 376 | if ($db->enableSchemaCache && !in_array($name, $db->schemaCacheExclude, true)) { |
|
130 | /* @var $cache Cache */ |
||
131 | 7 | $cache = is_string($db->schemaCache) ? Yii::$app->get($db->schemaCache, false) : $db->schemaCache; |
|
132 | 7 | if ($cache instanceof Cache) { |
|
133 | 7 | $key = $this->getCacheKey($name); |
|
134 | 7 | if ($refresh || ($table = $cache->get($key)) === false) { |
|
135 | 7 | $this->_tables[$name] = $table = $this->loadTableSchema($realName); |
|
136 | 7 | if ($table !== null) { |
|
137 | 7 | $cache->set($key, $table, $db->schemaCacheDuration, new TagDependency([ |
|
138 | 7 | 'tags' => $this->getCacheTag(), |
|
139 | 7 | ])); |
|
140 | 7 | } |
|
141 | 7 | } else { |
|
142 | $this->_tables[$name] = $table; |
||
143 | } |
||
144 | |||
145 | 7 | return $this->_tables[$name]; |
|
146 | } |
||
147 | } |
||
148 | |||
149 | 369 | return $this->_tables[$name] = $this->loadTableSchema($realName); |
|
150 | } |
||
151 | |||
152 | /** |
||
153 | * Returns the cache key for the specified table name. |
||
154 | * @param string $name the table name |
||
155 | * @return mixed the cache key |
||
156 | */ |
||
157 | 7 | protected function getCacheKey($name) |
|
158 | { |
||
159 | return [ |
||
160 | 7 | __CLASS__, |
|
161 | 7 | $this->db->dsn, |
|
162 | 7 | $this->db->username, |
|
163 | 7 | $name, |
|
164 | 7 | ]; |
|
165 | } |
||
166 | |||
167 | /** |
||
168 | * Returns the cache tag name. |
||
169 | * This allows [[refresh()]] to invalidate all cached table schemas. |
||
170 | * @return string the cache tag name |
||
171 | */ |
||
172 | 7 | protected function getCacheTag() |
|
173 | { |
||
174 | 7 | return md5(serialize([ |
|
175 | 7 | __CLASS__, |
|
176 | 7 | $this->db->dsn, |
|
177 | 7 | $this->db->username, |
|
178 | 7 | ])); |
|
179 | } |
||
180 | |||
181 | /** |
||
182 | * Returns the metadata for all tables in the database. |
||
183 | * @param string $schema the schema of the tables. Defaults to empty string, meaning the current or default schema name. |
||
184 | * @param boolean $refresh whether to fetch the latest available table schemas. If this is false, |
||
185 | * cached data may be returned if available. |
||
186 | * @return TableSchema[] the metadata for all tables in the database. |
||
187 | * Each array element is an instance of [[TableSchema]] or its child class. |
||
188 | */ |
||
189 | 10 | public function getTableSchemas($schema = '', $refresh = false) |
|
190 | { |
||
191 | 10 | $tables = []; |
|
192 | 10 | foreach ($this->getTableNames($schema, $refresh) as $name) { |
|
193 | 10 | if ($schema !== '') { |
|
194 | $name = $schema . '.' . $name; |
||
195 | } |
||
196 | 10 | if (($table = $this->getTableSchema($name, $refresh)) !== null) { |
|
197 | 10 | $tables[] = $table; |
|
198 | 10 | } |
|
199 | 10 | } |
|
200 | |||
201 | 10 | return $tables; |
|
202 | } |
||
203 | |||
204 | /** |
||
205 | * Returns all schema names in the database, except system schemas. |
||
206 | * @param boolean $refresh whether to fetch the latest available schema names. If this is false, |
||
207 | * schema names fetched previously (if available) will be returned. |
||
208 | * @return string[] all schema names in the database, except system schemas. |
||
209 | * @since 2.0.4 |
||
210 | */ |
||
211 | 1 | public function getSchemaNames($refresh = false) |
|
212 | { |
||
213 | 1 | if ($this->_schemaNames === null || $refresh) { |
|
214 | 1 | $this->_schemaNames = $this->findSchemaNames(); |
|
215 | 1 | } |
|
216 | |||
217 | 1 | return $this->_schemaNames; |
|
218 | } |
||
219 | |||
220 | /** |
||
221 | * Returns all table names in the database. |
||
222 | * @param string $schema the schema of the tables. Defaults to empty string, meaning the current or default schema name. |
||
223 | * If not empty, the returned table names will be prefixed with the schema name. |
||
224 | * @param boolean $refresh whether to fetch the latest available table names. If this is false, |
||
225 | * table names fetched previously (if available) will be returned. |
||
226 | * @return string[] all table names in the database. |
||
227 | */ |
||
228 | 16 | public function getTableNames($schema = '', $refresh = false) |
|
229 | { |
||
230 | 16 | if (!isset($this->_tableNames[$schema]) || $refresh) { |
|
231 | 16 | $this->_tableNames[$schema] = $this->findTableNames($schema); |
|
232 | 16 | } |
|
233 | |||
234 | 16 | return $this->_tableNames[$schema]; |
|
235 | } |
||
236 | |||
237 | /** |
||
238 | * @return QueryBuilder the query builder for this connection. |
||
239 | */ |
||
240 | 484 | public function getQueryBuilder() |
|
241 | { |
||
242 | 484 | if ($this->_builder === null) { |
|
243 | 391 | $this->_builder = $this->createQueryBuilder(); |
|
244 | 391 | } |
|
245 | |||
246 | 484 | return $this->_builder; |
|
247 | } |
||
248 | |||
249 | /** |
||
250 | * Determines the PDO type for the given PHP data value. |
||
251 | * @param mixed $data the data whose PDO type is to be determined |
||
252 | * @return integer the PDO type |
||
253 | * @see http://www.php.net/manual/en/pdo.constants.php |
||
254 | */ |
||
255 | 472 | public function getPdoType($data) |
|
256 | { |
||
257 | static $typeMap = [ |
||
258 | // php type => PDO type |
||
259 | 'boolean' => \PDO::PARAM_BOOL, |
||
260 | 'integer' => \PDO::PARAM_INT, |
||
261 | 'string' => \PDO::PARAM_STR, |
||
262 | 'resource' => \PDO::PARAM_LOB, |
||
263 | 'NULL' => \PDO::PARAM_NULL, |
||
264 | 472 | ]; |
|
265 | 472 | $type = gettype($data); |
|
266 | |||
267 | 472 | return isset($typeMap[$type]) ? $typeMap[$type] : \PDO::PARAM_STR; |
|
268 | } |
||
269 | |||
270 | /** |
||
271 | * Refreshes the schema. |
||
272 | * This method cleans up all cached table schemas so that they can be re-created later |
||
273 | * to reflect the database schema change. |
||
274 | */ |
||
275 | 9 | public function refresh() |
|
276 | { |
||
277 | /* @var $cache Cache */ |
||
278 | 9 | $cache = is_string($this->db->schemaCache) ? Yii::$app->get($this->db->schemaCache, false) : $this->db->schemaCache; |
|
279 | 9 | if ($this->db->enableSchemaCache && $cache instanceof Cache) { |
|
280 | 1 | TagDependency::invalidate($cache, $this->getCacheTag()); |
|
281 | 1 | } |
|
282 | 9 | $this->_tableNames = []; |
|
283 | 9 | $this->_tables = []; |
|
284 | 9 | } |
|
285 | |||
286 | /** |
||
287 | * Refreshes the particular table schema. |
||
288 | * This method cleans up cached table schema so that it can be re-created later |
||
289 | * to reflect the database schema change. |
||
290 | * @param string $name table name. |
||
291 | * @since 2.0.6 |
||
292 | */ |
||
293 | 19 | public function refreshTableSchema($name) |
|
294 | { |
||
295 | 19 | unset($this->_tables[$name]); |
|
296 | 19 | $this->_tableNames = []; |
|
297 | /* @var $cache Cache */ |
||
298 | 19 | $cache = is_string($this->db->schemaCache) ? Yii::$app->get($this->db->schemaCache, false) : $this->db->schemaCache; |
|
299 | 19 | if ($this->db->enableSchemaCache && $cache instanceof Cache) { |
|
300 | 4 | $cache->delete($this->getCacheKey($name)); |
|
301 | 4 | } |
|
302 | 19 | } |
|
303 | |||
304 | /** |
||
305 | * Creates a query builder for the database. |
||
306 | * This method may be overridden by child classes to create a DBMS-specific query builder. |
||
307 | * @return QueryBuilder query builder instance |
||
308 | */ |
||
309 | public function createQueryBuilder() |
||
310 | { |
||
311 | return new QueryBuilder($this->db); |
||
312 | } |
||
313 | |||
314 | /** |
||
315 | * Create a column schema builder instance giving the type and value precision. |
||
316 | * |
||
317 | * This method may be overridden by child classes to create a DBMS-specific column schema builder. |
||
318 | * |
||
319 | * @param string $type type of the column. See [[ColumnSchemaBuilder::$type]]. |
||
320 | * @param integer|string|array $length length or precision of the column. See [[ColumnSchemaBuilder::$length]]. |
||
321 | * @return ColumnSchemaBuilder column schema builder instance |
||
322 | * @since 2.0.6 |
||
323 | */ |
||
324 | 2 | public function createColumnSchemaBuilder($type, $length = null) |
|
325 | { |
||
326 | 2 | return new ColumnSchemaBuilder($type, $length); |
|
327 | } |
||
328 | |||
329 | /** |
||
330 | * Returns all schema names in the database, including the default one but not system schemas. |
||
331 | * This method should be overridden by child classes in order to support this feature |
||
332 | * because the default implementation simply throws an exception. |
||
333 | * @return array all schema names in the database, except system schemas |
||
334 | * @throws NotSupportedException if this method is called |
||
335 | * @since 2.0.4 |
||
336 | */ |
||
337 | protected function findSchemaNames() |
||
338 | { |
||
339 | throw new NotSupportedException(get_class($this) . ' does not support fetching all schema names.'); |
||
340 | } |
||
341 | |||
342 | /** |
||
343 | * Returns all table names in the database. |
||
344 | * This method should be overridden by child classes in order to support this feature |
||
345 | * because the default implementation simply throws an exception. |
||
346 | * @param string $schema the schema of the tables. Defaults to empty string, meaning the current or default schema. |
||
347 | * @return array all table names in the database. The names have NO schema name prefix. |
||
348 | * @throws NotSupportedException if this method is called |
||
349 | */ |
||
350 | protected function findTableNames($schema = '') |
||
351 | { |
||
352 | throw new NotSupportedException(get_class($this) . ' does not support fetching all table names.'); |
||
353 | } |
||
354 | |||
355 | /** |
||
356 | * Returns all unique indexes for the given table. |
||
357 | * Each array element is of the following structure: |
||
358 | * |
||
359 | * ```php |
||
360 | * [ |
||
361 | * 'IndexName1' => ['col1' [, ...]], |
||
362 | * 'IndexName2' => ['col2' [, ...]], |
||
363 | * ] |
||
364 | * ``` |
||
365 | * |
||
366 | * This method should be overridden by child classes in order to support this feature |
||
367 | * because the default implementation simply throws an exception |
||
368 | * @param TableSchema $table the table metadata |
||
369 | * @return array all unique indexes for the given table. |
||
370 | * @throws NotSupportedException if this method is called |
||
371 | */ |
||
372 | public function findUniqueIndexes($table) |
||
373 | { |
||
374 | throw new NotSupportedException(get_class($this) . ' does not support getting unique indexes information.'); |
||
375 | } |
||
376 | |||
377 | /** |
||
378 | * Returns the ID of the last inserted row or sequence value. |
||
379 | * @param string $sequenceName name of the sequence object (required by some DBMS) |
||
380 | * @return string the row ID of the last row inserted, or the last value retrieved from the sequence object |
||
381 | * @throws InvalidCallException if the DB connection is not active |
||
382 | * @see http://www.php.net/manual/en/function.PDO-lastInsertId.php |
||
383 | */ |
||
384 | 37 | public function getLastInsertID($sequenceName = '') |
|
385 | { |
||
386 | 37 | if ($this->db->isActive) { |
|
387 | 37 | return $this->db->pdo->lastInsertId($sequenceName === '' ? null : $this->quoteTableName($sequenceName)); |
|
388 | } else { |
||
389 | throw new InvalidCallException('DB Connection is not active.'); |
||
390 | } |
||
391 | } |
||
392 | |||
393 | /** |
||
394 | * @return boolean whether this DBMS supports [savepoint](http://en.wikipedia.org/wiki/Savepoint). |
||
395 | */ |
||
396 | 3 | public function supportsSavepoint() |
|
397 | { |
||
398 | 3 | return $this->db->enableSavepoint; |
|
399 | } |
||
400 | |||
401 | /** |
||
402 | * Creates a new savepoint. |
||
403 | * @param string $name the savepoint name |
||
404 | */ |
||
405 | 3 | public function createSavepoint($name) |
|
406 | { |
||
407 | 3 | $this->db->createCommand("SAVEPOINT $name")->execute(); |
|
408 | 3 | } |
|
409 | |||
410 | /** |
||
411 | * Releases an existing savepoint. |
||
412 | * @param string $name the savepoint name |
||
413 | */ |
||
414 | public function releaseSavepoint($name) |
||
415 | { |
||
416 | $this->db->createCommand("RELEASE SAVEPOINT $name")->execute(); |
||
417 | } |
||
418 | |||
419 | /** |
||
420 | * Rolls back to a previously created savepoint. |
||
421 | * @param string $name the savepoint name |
||
422 | */ |
||
423 | 3 | public function rollBackSavepoint($name) |
|
424 | { |
||
425 | 3 | $this->db->createCommand("ROLLBACK TO SAVEPOINT $name")->execute(); |
|
426 | 3 | } |
|
427 | |||
428 | /** |
||
429 | * Sets the isolation level of the current transaction. |
||
430 | * @param string $level The transaction isolation level to use for this transaction. |
||
431 | * This can be one of [[Transaction::READ_UNCOMMITTED]], [[Transaction::READ_COMMITTED]], [[Transaction::REPEATABLE_READ]] |
||
432 | * and [[Transaction::SERIALIZABLE]] but also a string containing DBMS specific syntax to be used |
||
433 | * after `SET TRANSACTION ISOLATION LEVEL`. |
||
434 | * @see http://en.wikipedia.org/wiki/Isolation_%28database_systems%29#Isolation_levels |
||
435 | */ |
||
436 | 4 | public function setTransactionIsolationLevel($level) |
|
437 | { |
||
438 | 4 | $this->db->createCommand("SET TRANSACTION ISOLATION LEVEL $level;")->execute(); |
|
439 | 4 | } |
|
440 | |||
441 | /** |
||
442 | * Executes the INSERT command, returning primary key values. |
||
443 | * @param string $table the table that new rows will be inserted into. |
||
444 | * @param array $columns the column data (name => value) to be inserted into the table. |
||
445 | * @return array primary key values or false if the command fails |
||
446 | * @since 2.0.4 |
||
447 | */ |
||
448 | 40 | public function insert($table, $columns) |
|
449 | { |
||
450 | 40 | $command = $this->db->createCommand()->insert($table, $columns); |
|
451 | 40 | if (!$command->execute()) { |
|
452 | return false; |
||
453 | } |
||
454 | 40 | $tableSchema = $this->getTableSchema($table); |
|
455 | 40 | $result = []; |
|
456 | 40 | foreach ($tableSchema->primaryKey as $name) { |
|
457 | 38 | if ($tableSchema->columns[$name]->autoIncrement) { |
|
458 | 34 | $result[$name] = $this->getLastInsertID($tableSchema->sequenceName); |
|
459 | 34 | break; |
|
460 | } else { |
||
461 | 6 | $result[$name] = isset($columns[$name]) ? $columns[$name] : $tableSchema->columns[$name]->defaultValue; |
|
462 | } |
||
463 | 40 | } |
|
464 | 40 | return $result; |
|
465 | } |
||
466 | |||
467 | /** |
||
468 | * Quotes a string value for use in a query. |
||
469 | * Note that if the parameter is not a string, it will be returned without change. |
||
470 | * @param string $str string to be quoted |
||
471 | * @return string the properly quoted string |
||
472 | * @see http://www.php.net/manual/en/function.PDO-quote.php |
||
473 | */ |
||
474 | 400 | public function quoteValue($str) |
|
475 | { |
||
476 | 400 | if (!is_string($str)) { |
|
477 | 3 | return $str; |
|
478 | } |
||
479 | |||
480 | 400 | if (($value = $this->db->getSlavePdo()->quote($str)) !== false) { |
|
481 | 400 | return $value; |
|
482 | } else { |
||
483 | // the driver doesn't support quote (e.g. oci) |
||
484 | return "'" . addcslashes(str_replace("'", "''", $str), "\000\n\r\\\032") . "'"; |
||
485 | } |
||
486 | } |
||
487 | |||
488 | /** |
||
489 | * Quotes a table name for use in a query. |
||
490 | * If the table name contains schema prefix, the prefix will also be properly quoted. |
||
491 | * If the table name is already quoted or contains '(' or '{{', |
||
492 | * then this method will do nothing. |
||
493 | * @param string $name table name |
||
494 | * @return string the properly quoted table name |
||
495 | * @see quoteSimpleTableName() |
||
496 | */ |
||
497 | 600 | public function quoteTableName($name) |
|
512 | |||
513 | /** |
||
514 | * Quotes a column name for use in a query. |
||
515 | * If the column name contains prefix, the prefix will also be properly quoted. |
||
516 | * If the column name is already quoted or contains '(', '[[' or '{{', |
||
517 | * then this method will do nothing. |
||
518 | * @param string $name column name |
||
519 | * @return string the properly quoted column name |
||
520 | * @see quoteSimpleColumnName() |
||
521 | */ |
||
522 | 689 | public function quoteColumnName($name) |
|
523 | { |
||
524 | 689 | if (strpos($name, '(') !== false || strpos($name, '[[') !== false) { |
|
525 | 32 | return $name; |
|
526 | } |
||
527 | 689 | if (($pos = strrpos($name, '.')) !== false) { |
|
528 | 93 | $prefix = $this->quoteTableName(substr($name, 0, $pos)) . '.'; |
|
529 | 93 | $name = substr($name, $pos + 1); |
|
530 | 93 | } else { |
|
531 | 689 | $prefix = ''; |
|
532 | } |
||
533 | 689 | if (strpos($name, '{{') !== false) { |
|
534 | 3 | return $name; |
|
535 | } |
||
536 | 689 | return $prefix . $this->quoteSimpleColumnName($name); |
|
537 | } |
||
538 | |||
539 | /** |
||
540 | * Quotes a simple table name for use in a query. |
||
541 | * A simple table name should contain the table name only without any schema prefix. |
||
542 | * If the table name is already quoted, this method will do nothing. |
||
543 | * @param string $name table name |
||
544 | * @return string the properly quoted table name |
||
545 | */ |
||
546 | public function quoteSimpleTableName($name) |
||
550 | |||
551 | /** |
||
552 | * Quotes a simple column name for use in a query. |
||
553 | * A simple column name should contain the column name only without any prefix. |
||
554 | * If the column name is already quoted or is the asterisk character '*', this method will do nothing. |
||
555 | * @param string $name column name |
||
556 | * @return string the properly quoted column name |
||
557 | */ |
||
558 | 203 | public function quoteSimpleColumnName($name) |
|
562 | |||
563 | /** |
||
564 | * Returns the actual name of a given table name. |
||
565 | * This method will strip off curly brackets from the given table name |
||
566 | * and replace the percentage character '%' with [[Connection::tablePrefix]]. |
||
567 | * @param string $name the table name to be converted |
||
568 | * @return string the real name of the given table name |
||
569 | */ |
||
570 | 376 | public function getRawTableName($name) |
|
580 | |||
581 | /** |
||
582 | * Extracts the PHP type from abstract DB type. |
||
583 | * @param ColumnSchema $column the column schema information |
||
584 | * @return string PHP type name |
||
585 | */ |
||
586 | 366 | protected function getColumnPhpType($column) |
|
587 | { |
||
588 | static $typeMap = [ |
||
589 | // abstract type => php type |
||
590 | 'smallint' => 'integer', |
||
591 | 'integer' => 'integer', |
||
592 | 'bigint' => 'integer', |
||
593 | 'boolean' => 'boolean', |
||
594 | 'float' => 'double', |
||
595 | 'double' => 'double', |
||
596 | 'binary' => 'resource', |
||
597 | 366 | ]; |
|
598 | 366 | if (isset($typeMap[$column->type])) { |
|
599 | 362 | if ($column->type === 'bigint') { |
|
600 | 18 | return PHP_INT_SIZE === 8 && !$column->unsigned ? 'integer' : 'string'; |
|
601 | 362 | } elseif ($column->type === 'integer') { |
|
602 | 362 | return PHP_INT_SIZE === 4 && $column->unsigned ? 'string' : 'integer'; |
|
603 | } else { |
||
604 | 104 | return $typeMap[$column->type]; |
|
605 | } |
||
606 | } else { |
||
607 | 351 | return 'string'; |
|
608 | } |
||
609 | } |
||
610 | |||
611 | /** |
||
612 | * Converts a DB exception to a more concrete one if possible. |
||
613 | * |
||
614 | * @param \Exception $e |
||
615 | * @param string $rawSql SQL that produced exception |
||
616 | * @return Exception |
||
617 | */ |
||
618 | 19 | public function convertException(\Exception $e, $rawSql) |
|
634 | |||
635 | /** |
||
636 | * Returns a value indicating whether a SQL statement is for read purpose. |
||
637 | * @param string $sql the SQL statement |
||
638 | * @return boolean whether a SQL statement is for read purpose. |
||
639 | */ |
||
640 | 9 | public function isReadQuery($sql) |
|
645 | } |
||
646 |