Example #1
0
 private function parseColumn(Parser $parser)
 {
     $columnName = $parser->inner(null, array(' ', "\r", "\n", "\t"));
     $columnName = (string) $this->resolve(trim($columnName));
     $type = (string) $parser->inner(null, ' ');
     $unsigned = $parser->contain('UNSIGNED', true);
     $notNull = $parser->contain('NOT NULL', true);
     $autoId = $this->isAutoId($parser);
     $default = $parser->inner('DEFAULT ', null, false, true);
     if (!$default->isEmpty()) {
         $default = (string) $default;
         $defUpper = strtoupper($default);
         if ('NULL' === $defUpper) {
             $default = null;
         } elseif ('CURRENT_TIMESTAMP' === $defUpper) {
             $default = new Raw($defUpper);
         } elseif (strpos($default, self::BIND_PREFIX) !== false) {
             $default = $this->resolve($default);
         }
     } else {
         $default = false;
     }
     $flags = $this->getTypeByString($type);
     if ($notNull) {
         $flags += Column::NOT_NULL;
     }
     if ($autoId) {
         $flags += Column::AUTO_ID;
     }
     if ($unsigned) {
         $flags += Column::UNSIGNED;
     }
     $column = new Column($flags);
     if ($length = (string) $parser->setOffset(0)->inner('VARCHAR(', ')', false, true)) {
         $column->setStringLength($length, false);
     } elseif ($length = (string) $parser->setOffset(0)->inner('CHAR(', ')', false, true)) {
         $column->setStringLength($length, true);
     }
     $column->setDefault($default);
     $column->schemaName = $columnName;
     $this->columns->{$columnName} = $column;
 }