detectType() public static method

Heuristic column type detection.
public static detectType ( $type ) : string
return string
示例#1
0
 /**
  * @return array
  */
 protected function getTables()
 {
     $tables = [];
     foreach ($this->structure->getTables() as $table) {
         if ($table['view'] === FALSE) {
             foreach ($this->structure->getColumns($table['name']) as $column) {
                 $tables[$table['name']][$column['name']] = \Nette\Database\Helpers::detectType($column['nativetype']);
             }
         }
     }
     return $tables;
 }
示例#2
0
 /**
  * Returns associative array of detected types (IReflection::FIELD_*) in result set.
  */
 public function getColumnTypes(\PDOStatement $statement)
 {
     $types = [];
     $count = $statement->columnCount();
     for ($col = 0; $col < $count; $col++) {
         $meta = $statement->getColumnMeta($col);
         if (isset($meta['native_type'])) {
             $types[$meta['name']] = $type = Nette\Database\Helpers::detectType($meta['native_type']);
             if ($type === Nette\Database\IStructure::FIELD_TIME) {
                 $types[$meta['name']] = Nette\Database\IStructure::FIELD_TIME_INTERVAL;
             }
         }
     }
     return $types;
 }
示例#3
0
 /**
  * Returns associative array of detected types (IReflection::FIELD_*) in result set.
  */
 public function getColumnTypes(\PDOStatement $statement)
 {
     $types = [];
     $count = $statement->columnCount();
     for ($col = 0; $col < $count; $col++) {
         $meta = $statement->getColumnMeta($col);
         if (isset($meta['sqlite:decl_type'])) {
             if ($meta['sqlite:decl_type'] === 'DATE') {
                 $types[$meta['name']] = Nette\Database\IStructure::FIELD_UNIX_TIMESTAMP;
             } else {
                 $types[$meta['name']] = Nette\Database\Helpers::detectType($meta['sqlite:decl_type']);
             }
         } elseif (isset($meta['native_type'])) {
             $types[$meta['name']] = Nette\Database\Helpers::detectType($meta['native_type']);
         }
     }
     return $types;
 }
示例#4
0
 private function detectColumnTypes()
 {
     if ($this->types === NULL) {
         $this->types = array();
         if ($this->connection->getSupplementalDriver()->isSupported(ISupplementalDriver::SUPPORT_COLUMNS_META)) {
             $count = $this->columnCount();
             for ($col = 0; $col < $count; $col++) {
                 $meta = $this->getColumnMeta($col);
                 if (isset($meta['native_type'])) {
                     $this->types[$meta['name']] = Helpers::detectType($meta['native_type']);
                 }
             }
         }
     }
     return $this->types;
 }
 private function detectColumnTypes()
 {
     if ($this->types === null) {
         $this->types = array();
         if ($this->connection->getSupplementalDriver()->isSupported(ISupplementalDriver::META)) {
             // workaround for PHP bugs #53782, #54695
             $col = 0;
             while ($meta = $this->getColumnMeta($col++)) {
                 if (isset($meta['native_type'])) {
                     $this->types[$meta['name']] = Helpers::detectType($meta['native_type']);
                 }
             }
         }
     }
     return $this->types;
 }
示例#6
0
 private function determineFromColumns(array $columns)
 {
     $out = [];
     foreach ($columns as $column) {
         $type = Nette\Database\Helpers::detectType($column['nativetype']);
         if ($column['nativetype'] === 'ENUM') {
             $out[$column['name']] = ['type' => IColumnStructure::ENUM];
             $enum = $column['vendor']['Type'];
             $options = str_getcsv(str_replace('enum(', '', substr($enum, 0, strlen($enum) - 1)), ',', "'");
             $out[$column['name']]['values'] = [];
             foreach ($options as $option) {
                 $out[$column['name']]['values'][] = $option;
             }
         } elseif ($column['nativetype'] === 'TINYINT' && $column['size'] === 1) {
             $out[$column['name']] = ['type' => IColumnStructure::BOOL];
         } else {
             switch ($type) {
                 case Nette\Database\IStructure::FIELD_TEXT:
                     $out[$column['name']] = ['type' => IColumnStructure::TEXT];
                     break;
                 case Nette\Database\IStructure::FIELD_INTEGER:
                 case Nette\Database\IStructure::FIELD_FLOAT:
                     $out[$column['name']] = ['type' => IColumnStructure::NUMBER];
                     break;
                 case Nette\Database\IStructure::FIELD_DATE:
                 case Nette\Database\IStructure::FIELD_TIME:
                 case Nette\Database\IStructure::FIELD_DATETIME:
                 case Nette\Database\IStructure::FIELD_UNIX_TIMESTAMP:
                     $out[$column['name']] = ['type' => IColumnStructure::DATE];
                     break;
                 case Nette\Database\IStructure::FIELD_BOOL:
                     $out[$column['name']] = ['type' => IColumnStructure::BOOL];
                     break;
             }
         }
         if (isset($out[$column['name']])) {
             $out[$column['name']]['nullable'] = $column['nullable'];
         }
     }
     return $out;
 }
示例#7
0
Nette\DateTime($value);}}return$this->connection->getSupplementalDriver()->normalizeRow($row,$this);}private
function
detectColumnTypes(){if($this->types===NULL){$this->types=array();if($this->connection->getSupplementalDriver()->isSupported(ISupplementalDriver::META)){$col=0;while($meta=$this->getColumnMeta($col++)){if(isset($meta['native_type'])){$this->types[$meta['name']]=Helpers::detectType($meta['native_type']);}}}}return$this->types;}function
示例#8
-1
 /**
  * Returns associative array of detected types (IReflection::FIELD_*) in result set.
  */
 public function getColumnTypes(\PDOStatement $statement)
 {
     $types = array();
     $count = $statement->columnCount();
     for ($col = 0; $col < $count; $col++) {
         $meta = $statement->getColumnMeta($col);
         if (isset($meta['sqlsrv:decl_type']) && $meta['sqlsrv:decl_type'] !== 'timestamp') {
             // timestamp does not mean time in sqlsrv
             $types[$meta['name']] = Nette\Database\Helpers::detectType($meta['sqlsrv:decl_type']);
         } elseif (isset($meta['native_type'])) {
             $types[$meta['name']] = Nette\Database\Helpers::detectType($meta['native_type']);
         }
     }
     return $types;
 }