Beispiel #1
0
 protected function createColumn($row, $tblName)
 {
     $fieldName = trim($row['rdb$field_name']);
     $column = new Sabel_Db_Metadata_Column();
     $column->name = strtolower($fieldName);
     $column->nullable = $row['rdb$null_flag'] === null;
     $type = $this->types[$row['rdb$field_type']];
     if ($type === "blob" && $row['rdb$field_sub_type'] === 1) {
         $column->type = Sabel_Db_Type::TEXT;
     } elseif ($type === "char" && $row['rdb$character_length'] === 1) {
         $column->type = Sabel_Db_Type::BOOL;
     } else {
         Sabel_Db_Type_Manager::create()->applyType($column, $type);
     }
     $seq = "{$tblName}_{$fieldName}_SEQ";
     $column->increment = in_array($seq, $this->sequences);
     $column->primary = in_array($fieldName, $this->primaryKeys);
     if (($default = $row['rdb$default_source']) !== null) {
         $default = substr($default, 8);
         if ($default[0] === "'") {
             $default = substr($default, 1, -1);
         }
     }
     $this->setDefaultValue($column, $default);
     if ($column->isString()) {
         $column->max = (int) $row['rdb$character_length'];
     }
     return $column;
 }
Beispiel #2
0
 protected function createColumns($tblName)
 {
     $rows = $this->driver->execute("PRAGMA table_info('{$tblName}')");
     if (!$rows) {
         return array();
     }
     $columns = array();
     foreach ($rows as $row) {
         $co = new Sabel_Db_Metadata_Column();
         $co->name = $row["name"];
         if ($row["pk"] === "1") {
             $co->primary = true;
             $co->nullable = false;
             $co->increment = $row["type"] === "integer";
         } else {
             $co->primary = false;
             $co->nullable = $row["notnull"] === "0";
             $co->increment = false;
         }
         if ($this->isBoolean($row["type"])) {
             $co->type = Sabel_Db_Type::BOOL;
         } elseif (!$this->isString($co, $row["type"])) {
             Sabel_Db_Type_Manager::create()->applyType($co, $row["type"]);
         }
         $this->setDefaultValue($co, $row["dflt_value"]);
         if (is_string($co->default) && ($length = strlen($co->default)) > 1) {
             if ($co->default[0] === "'" && substr($co->default, --$length, 1) === "'") {
                 $co->default = substr($co->default, 1, --$length);
             }
         }
         $columns[$co->name] = $co;
     }
     return $columns;
 }
Beispiel #3
0
 public static function create()
 {
     if (self::$instance === null) {
         self::$instance = new self();
     }
     return self::$instance;
 }
Beispiel #4
0
 protected function createColumn($row)
 {
     $column = new Sabel_Db_Metadata_Column();
     $column->name = $row["column_name"];
     $column->nullable = $row["is_nullable"] !== "NO";
     Sabel_Db_Type_Manager::create()->applyType($column, $row["data_type"]);
     $this->setDefault($column, $row["column_default"]);
     $column->primary = in_array($column->name, $this->primaryKeys);
     $seq = $row["table_name"] . "_" . $column->name . "_seq";
     $column->increment = in_array($seq, $this->sequences);
     if ($column->primary) {
         $column->nullable = false;
     }
     if ($column->isString()) {
         $this->setLength($column, $row);
     }
     return $column;
 }
Beispiel #5
0
 protected function createColumn($row)
 {
     $column = new Sabel_Db_Metadata_Column();
     $column->name = $row["column_name"];
     $column->nullable = $row["is_nullable"] !== "NO";
     if ($row["column_type"] === "tinyint(1)") {
         $column->type = Sabel_Db_Type::BOOL;
     } else {
         Sabel_Db_Type_Manager::create()->applyType($column, $row["data_type"]);
     }
     $this->setDefault($column, $row["column_default"]);
     $column->primary = $row["column_key"] === "PRI";
     $column->increment = $row["extra"] === "auto_increment";
     if ($column->primary) {
         $column->nullable = false;
     }
     if ($column->isString()) {
         $column->max = (int) $row["character_maximum_length"];
     }
     return $column;
 }
Beispiel #6
0
 protected function createColumn($row)
 {
     $column = new Sabel_Db_Metadata_Column();
     $column->name = $row["column_name"];
     $column->nullable = $row["is_nullable"] !== "NO";
     if ($row["data_type"] === "varchar" && $row["character_maximum_length"] === -1) {
         $row["data_type"] = "text";
     } elseif ($row["data_type"] === "float") {
         $row["data_type"] = "double";
     }
     Sabel_Db_Type_Manager::create()->applyType($column, $row["data_type"]);
     $this->setDefault($column, $row["column_default"]);
     $column->primary = in_array($column->name, $this->primaryKeys);
     $column->increment = in_array($column->name, $this->sequences);
     if ($column->primary) {
         $column->nullable = false;
     }
     if ($column->isString()) {
         $this->setLength($column, $row);
     }
     return $column;
 }
Beispiel #7
0
 protected function createColumn($row)
 {
     $column = new Sabel_Db_Metadata_Column();
     $column->name = strtolower($row["column_name"]);
     $column->nullable = $row["nullable"] !== "N";
     $type = strtolower($row["data_type"]);
     $default = trim($row["data_default"]);
     $precision = (int) $row["data_precision"];
     if ($type === "number") {
         if ($precision === 1 && ($default === "1" || $default === "0")) {
             $column->type = Sabel_Db_Type::BOOL;
         } else {
             if ($precision === 5) {
                 $type = "smallint";
             } elseif ($precision === 19) {
                 $type = "bigint";
             } else {
                 $type = "integer";
             }
         }
     }
     if (!$column->isBool()) {
         if ($type === "float") {
             $type = $precision === 24 ? "float" : "double";
         } elseif ($type === "date" && !$this->isDate($column->name)) {
             $type = "datetime";
         }
         Sabel_Db_Type_Manager::create()->applyType($column, $type);
     }
     $this->setDefault($column, $default);
     $seq = $row["table_name"] . "_" . $row["column_name"] . "_seq";
     $column->increment = in_array(strtoupper($seq), $this->sequences);
     $column->primary = in_array($column->name, $this->primaryKeys);
     if ($column->primary) {
         $column->nullable = false;
     }
     if ($column->isString()) {
         $column->max = (int) $row["char_length"];
     }
     return $column;
 }