Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Database: patterns for type detection can be altered [Closes #482]

  • Loading branch information...
commit bd8724453e554cd89196f58105e80526469b3e9f 1 parent 455160f
@dg dg authored
Showing with 19 additions and 14 deletions.
  1. +19 −14 Nette/Database/Helpers.php
View
33 Nette/Database/Helpers.php
@@ -23,6 +23,19 @@
*/
class Helpers
{
+ /** @var array */
+ public static $typePatterns = array(
+ '^_' => IReflection::FIELD_TEXT, // PostgreSQL arrays
+ 'BYTEA|BLOB|BIN' => IReflection::FIELD_BINARY,
+ 'TEXT|CHAR' => IReflection::FIELD_TEXT,
+ 'YEAR|BYTE|COUNTER|SERIAL|INT|LONG' => IReflection::FIELD_INTEGER,
+ 'CURRENCY|REAL|MONEY|FLOAT|DOUBLE|DECIMAL|NUMERIC|NUMBER' => IReflection::FIELD_FLOAT,
+ '^TIME$' => IReflection::FIELD_TIME,
+ 'TIME' => IReflection::FIELD_DATETIME, // DATETIME, TIMESTAMP
+ 'DATE' => IReflection::FIELD_DATE,
+ 'BOOL|BIT' => IReflection::FIELD_BOOL,
+ );
+
/**
@@ -112,24 +125,16 @@ public static function dumpSql($sql)
*/
public static function detectType($type)
{
- static $types, $patterns = array(
- 'BYTEA|BLOB|BIN' => IReflection::FIELD_BINARY,
- 'TEXT|CHAR' => IReflection::FIELD_TEXT,
- 'YEAR|BYTE|COUNTER|SERIAL|INT|LONG' => IReflection::FIELD_INTEGER,
- 'CURRENCY|REAL|MONEY|FLOAT|DOUBLE|DECIMAL|NUMERIC|NUMBER' => IReflection::FIELD_FLOAT,
- 'TIME|DATE' => IReflection::FIELD_DATETIME,
- 'BOOL|BIT' => IReflection::FIELD_BOOL,
- );
-
- if (!isset($types[$type])) {
- $types[$type] = 'string';
- foreach ($patterns as $s => $val) {
+ static $cache;
+ if (!isset($cache[$type])) {
+ $cache[$type] = 'string';
+ foreach (self::$typePatterns as $s => $val) {
if (preg_match("#$s#i", $type)) {
- return $types[$type] = $val;
+ return $cache[$type] = $val;
}
}
}
- return $types[$type];
+ return $cache[$type];
}
Please sign in to comment.
Something went wrong with that request. Please try again.