/**
  * This method will return a native type that corresponds to the specified
  * Creole (JDBC-like) type.  Remember that this is really only for "hint" purposes
  * as SQLite is typeless.
  * 
  * If there is more than one matching native type, then the LAST defined 
  * native type will be returned.
  * 
  * @param int $creoleType
  * @return string Native type string.
  */
 public static function getNativeType($creoleType)
 {
     if (self::$reverseMap === null) {
         self::$reverseMap = array_flip(self::$typeMap);
     }
     return @self::$reverseMap[$creoleType];
 }
Ejemplo n.º 2
0
 /** Loads the columns for this table. */
 protected function initColumns()
 {
     include_once 'creole/metadata/ColumnInfo.php';
     include_once 'creole/metadata/PrimaryKeyInfo.php';
     include_once 'creole/drivers/sqlite/SQLiteTypes.php';
     // To get all of the attributes we need, we'll actually do
     // two separate queries.  The first gets names and default values
     // the second will fill in some more details.
     $sql = "PRAGMA table_info('" . $this->name . "')";
     $res = sqlite_query($this->conn->getResource(), $sql);
     while ($row = sqlite_fetch_array($res, SQLITE_ASSOC)) {
         $name = $row['name'];
         $fulltype = $row['type'];
         $size = null;
         $precision = null;
         $scale = null;
         if (preg_match('/^([^\\(]+)\\(\\s*(\\d+)\\s*,\\s*(\\d+)\\s*\\)$/', $fulltype, $matches)) {
             $type = $matches[1];
             $precision = $matches[2];
             $scale = $matches[3];
             // aka precision
         } elseif (preg_match('/^([^\\(]+)\\(\\s*(\\d+)\\s*\\)$/', $fulltype, $matches)) {
             $type = $matches[1];
             $size = $matches[2];
         } else {
             $type = $fulltype;
         }
         // If column is primary key and of type INTEGER, it is auto increment
         // See: http://sqlite.org/faq.html#q1
         $is_auto_increment = $row['pk'] == 1 && $fulltype == 'INTEGER';
         $not_null = $row['notnull'];
         $is_nullable = !$not_null;
         $default_val = $row['dflt_value'];
         $this->columns[$name] = new ColumnInfo($this, $name, SQLiteTypes::getType($type), $type, $size, $precision, $scale, $is_nullable, $default_val);
         if ($row['pk'] == 1 || strtolower($type) == 'integer primary key') {
             if ($this->primaryKey === null) {
                 $this->primaryKey = new PrimaryKeyInfo($name);
             }
             $this->primaryKey->addColumn($this->columns[$name]);
         }
     }
     $this->colsLoaded = true;
 }