Пример #1
0
 /**
  * Extracts the PHP type from DF type.
  *
  * @param string $type DF type
  *
  * @return string
  */
 public static function extractPhpType($type)
 {
     switch ($type) {
         case static::TYPE_MONEY:
             return 'string';
     }
     return parent::extractPhpType($type);
 }
Пример #2
0
 /**
  * Converts the input value to the type that this column is of.
  *
  * @param mixed $value input value
  *
  * @return mixed converted value
  */
 public function typecast($value)
 {
     if ($this->phpType === 'boolean') {
         return $value ? 1 : 0;
     } else {
         return parent::typecast($value);
     }
 }
Пример #3
0
 /**
  * Extracts the default value for the column.
  * The value is typecasted to correct PHP type.
  *
  * @param mixed $defaultValue the default value obtained from metadata
  */
 public function extractDefault($defaultValue)
 {
     if (stripos($defaultValue, 'timestamp') !== false) {
         $this->defaultValue = null;
     } else {
         parent::extractDefault($defaultValue);
     }
 }
Пример #4
0
 /**
  * Extracts the PHP type from DB type.
  *
  * @param string $dbType DB type
  */
 public function extractType($dbType)
 {
     parent::extractType($dbType);
     if (strpos($dbType, '[') !== false || strpos($dbType, 'char') !== false || strpos($dbType, 'text') !== false) {
         $this->type = static::TYPE_STRING;
     } elseif (preg_match('/(real|float|double)/', $dbType)) {
         $this->type = static::TYPE_DOUBLE;
     } elseif (preg_match('/(integer|oid|serial|smallint)/', $dbType)) {
         $this->type = static::TYPE_INTEGER;
     }
 }
Пример #5
0
 /**
  * Extracts the PHP type from DB type.
  *
  * @param string $dbType DB type
  */
 public function extractType($dbType)
 {
     parent::extractType($dbType);
     if (strpos($dbType, '[') !== false || strpos($dbType, 'char') !== false || strpos($dbType, 'text') !== false) {
         $this->type = 'string';
     } elseif (preg_match('/(real|float|double)/', $dbType)) {
         $this->type = 'double';
     } elseif (preg_match('/(integer|oid|serial|smallint)/', $dbType)) {
         $this->type = 'integer';
     }
 }
Пример #6
0
 /**
  * Extracts size, precision and scale information from column's DB type.
  *
  * @param string $dbType the column's DB type
  */
 public function extractLimit($dbType)
 {
     if (strncmp($dbType, 'enum', 4) === 0 && preg_match('/\\(([\'"])(.*)\\1\\)/', $dbType, $matches)) {
         // explode by (single or double) quote and comma (ENUM values may contain commas)
         $values = explode($matches[1] . ',' . $matches[1], $matches[2]);
         $size = 0;
         foreach ($values as $value) {
             if (($n = strlen($value)) > $size) {
                 $size = $n;
             }
         }
         $this->size = $this->precision = $size;
     } else {
         parent::extractLimit($dbType);
     }
 }
Пример #7
0
 public function parseFieldForSelect($as_quoted_string = false)
 {
     $field = $as_quoted_string ? $this->rawName : $this->name;
     $alias = $this->getName(true);
     switch ($this->dbType) {
         case 'datetime':
         case 'datetimeoffset':
             return "(CONVERT(nvarchar(30), {$field}, 127)) AS {$alias}";
         case 'geometry':
         case 'geography':
         case 'hierarchyid':
             return "({$field}.ToString()) AS {$alias}";
         default:
             return parent::parseFieldForSelect($as_quoted_string);
     }
 }
Пример #8
0
 /**
  * @param mixed        $value
  * @param ColumnSchema $info
  * @param array        $params
  *
  * @return int|null|string
  * @throws BadRequestException
  */
 protected function parseFilterValue($value, ColumnSchema $info, array &$params)
 {
     if (0 !== strpos($value, ':')) {
         // remove quoting on strings if used, i.e. 1.x required them
         if (is_string($value) && (0 === strcmp("'" . trim($value, "'") . "'", $value) || 0 === strcmp('"' . trim($value, '"') . '"', $value))) {
             $value = trim($value, '"\'');
         }
         // if not already a replacement parameter, evaluate it
         //            $value = $this->dbConn->getSchema()->parseValueForSet($value, $info);
         switch ($cnvType = DbUtilities::determinePhpConversionType($info->type)) {
             case 'int':
                 if (!is_int($value)) {
                     if (!ctype_digit($value)) {
                         throw new BadRequestException("Field '{$info->getName(true)}' must be a valid integer.");
                     } else {
                         $value = intval($value);
                     }
                 }
                 break;
             case 'time':
                 $cfgFormat = \Config::get('df.db_time_format');
                 $outFormat = 'H:i:s.u';
                 $value = DbUtilities::formatDateTime($outFormat, $value, $cfgFormat);
                 break;
             case 'date':
                 $cfgFormat = \Config::get('df.db_date_format');
                 $outFormat = 'Y-m-d';
                 $value = DbUtilities::formatDateTime($outFormat, $value, $cfgFormat);
                 break;
             case 'datetime':
                 $cfgFormat = \Config::get('df.db_datetime_format');
                 $outFormat = 'Y-m-d H:i:s';
                 $value = DbUtilities::formatDateTime($outFormat, $value, $cfgFormat);
                 break;
             case 'timestamp':
                 $cfgFormat = \Config::get('df.db_timestamp_format');
                 $outFormat = 'Y-m-d H:i:s';
                 $value = DbUtilities::formatDateTime($outFormat, $value, $cfgFormat);
                 break;
             default:
                 break;
         }
         $paramName = ':cf_' . count($params);
         // positionally unique
         $params[$paramName] = $value;
         $value = $paramName;
     }
     return $value;
 }
Пример #9
0
 /**
  * @param ColumnSchema $field_info
  *
  * @return array
  */
 public function parseFieldForBinding(ColumnSchema $field_info)
 {
     $pdoType = $field_info->allowNull ? null : $field_info->pdoType;
     $phpType = is_null($pdoType) ? $field_info->phpType : null;
     return ['name' => $field_info->getName(true), 'pdo_type' => $pdoType, 'php_type' => $phpType];
 }