Skip to content

Commit

Permalink
Helpers::detectType() uses more strict type patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed May 30, 2016
1 parent d8aab0a commit b660054
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/Database/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,13 @@ class Helpers
/** @var array */
public static $typePatterns = [
'^_' => IStructure::FIELD_TEXT, // PostgreSQL arrays
'BYTEA|BLOB|BIN' => IStructure::FIELD_BINARY,
'TEXT|CHAR|POINT|INTERVAL' => IStructure::FIELD_TEXT,
'YEAR|BYTE|COUNTER|SERIAL|INT|LONG|SHORT|^TINY$' => IStructure::FIELD_INTEGER,
'CURRENCY|REAL|MONEY|FLOAT|DOUBLE|DECIMAL|NUMERIC|NUMBER' => IStructure::FIELD_FLOAT,
'^TIME$' => IStructure::FIELD_TIME,
'TIME' => IStructure::FIELD_DATETIME, // DATETIME, TIMESTAMP
'(TINY|SMALL|SHORT|MEDIUM|BIG|LONG)(INT)?|INT(EGER|\d+| IDENTITY)?|(SMALL|BIG|)SERIAL\d*|COUNTER|YEAR|BYTE|LONGLONG|UNSIGNED BIG INT' => IStructure::FIELD_INTEGER,
'(NEW)?DEC(IMAL)?(\(.*)?|NUMERIC|REAL|DOUBLE( PRECISION)?|FLOAT\d*|(SMALL)?MONEY|CURRENCY|NUMBER' => IStructure::FIELD_FLOAT,
'BOOL(EAN)?' => IStructure::FIELD_BOOL,
'TIME' => IStructure::FIELD_TIME,
'DATE' => IStructure::FIELD_DATE,
'BOOL' => IStructure::FIELD_BOOL,
'(SMALL)?DATETIME(OFFSET)?\d*|TIME(STAMP)?' => IStructure::FIELD_DATETIME,
'BYTEA|(TINY|MEDIUM|LONG|)BLOB|(LONG )?(VAR)?BINARY|IMAGE' => IStructure::FIELD_BINARY,
];


Expand Down Expand Up @@ -171,7 +170,7 @@ public static function detectType($type)
if (!isset($cache[$type])) {
$cache[$type] = 'string';
foreach (self::$typePatterns as $s => $val) {
if (preg_match("#$s#i", $type)) {
if (preg_match("#^($s)$#i", $type)) {
return $cache[$type] = $val;
}
}
Expand Down

0 comments on commit b660054

Please sign in to comment.