예제 #1
0
 /**
  * This method will return a native type that corresponds to the specified
  * Creole (JDBC-like) type.
  * 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];
 }
예제 #2
0
 /** Loads the columns for this table. */
 protected function initColumns()
 {
     include_once CREOLE_ROOT . 'metadata/ColumnInfo.php';
     //include_once CREOLE_ROOT . 'metadata/ColumnInfo.php';
     include_once CREOLE_ROOT . 'drivers/mysql/MySQLTypes.php';
     //include_once CREOLE_ROOT . 'drivers/mysql/MySQLTypes.php';
     if (!@mysql_select_db($this->dbname, $this->conn->getResource())) {
         throw new SQLException('No database selected');
     }
     // To get all of the attributes we need, we use
     // the MySQL "SHOW COLUMNS FROM $tablename" SQL.  We cannot
     // use the API functions (e.g. mysql_list_fields() because they
     // do not return complete information -- e.g. precision / scale, default
     // values).
     $res = mysql_query("SHOW COLUMNS FROM `" . $this->name . "`", $this->conn->getResource());
     $defaults = array();
     $nativeTypes = array();
     $precisions = array();
     while ($row = mysql_fetch_assoc($res)) {
         $name = $row['Field'];
         $is_nullable = $row['Null'] == 'YES';
         $is_auto_increment = strpos($row['Extra'], 'auto_increment') !== false;
         $size = null;
         $precision = null;
         $scale = null;
         if (preg_match('/^(\\w+)[\\(]?([\\d,]*)[\\)]?( |$)/', $row['Type'], $matches)) {
             //            colname[1]   size/precision[2]
             $nativeType = $matches[1];
             if ($matches[2]) {
                 if (($cpos = strpos($matches[2], ',')) !== false) {
                     $size = (int) substr($matches[2], 0, $cpos);
                     $precision = $size;
                     $scale = (int) substr($matches[2], $cpos + 1);
                 } else {
                     $size = (int) $matches[2];
                 }
             }
         } elseif (preg_match('/^(\\w+)\\(/', $row['Type'], $matches)) {
             $nativeType = $matches[1];
         } else {
             $nativeType = $row['Type'];
         }
         //BLOBs can't have any default values in MySQL
         $default = preg_match('~blob|text~', $nativeType) ? null : $row['Default'];
         $this->columns[$name] = new ColumnInfo($this, $name, MySQLTypes::getType($nativeType), $nativeType, $size, $precision, $scale, $is_nullable, $default, $is_auto_increment, $row);
     }
     $this->colsLoaded = true;
 }
 /** Loads the columns for this table. */
 protected function initColumns()
 {
     require_once 'creole/metadata/ColumnInfo.php';
     require_once 'creole/drivers/mysql/MySQLTypes.php';
     if (!@mysqli_select_db($this->conn->getResource(), $this->dbname)) {
         throw new SQLException('No database selected');
     }
     // To get all of the attributes we need, we use
     // the MySQL "SHOW COLUMNS FROM $tablename" SQL.
     $res = mysqli_query($this->conn->getResource(), "SHOW COLUMNS FROM " . $this->name);
     $defaults = array();
     $nativeTypes = array();
     $precisions = array();
     while ($row = mysqli_fetch_assoc($res)) {
         $name = $row['Field'];
         $default = $row['Default'];
         $is_nullable = $row['Null'] == 'YES';
         $size = null;
         $precision = null;
         $scale = null;
         if (preg_match('/^(\\w+)[\\(]?([\\d,]*)[\\)]?( |$)/', $row['Type'], $matches)) {
             //            colname[1]   size/precision[2]
             $nativeType = $matches[1];
             if ($matches[2]) {
                 if (($cpos = strpos($matches[2], ',')) !== false) {
                     $size = (int) substr($matches[2], 0, $cpos);
                     $precision = $size;
                     $scale = (int) substr($matches[2], $cpos + 1);
                 } else {
                     $size = (int) $matches[2];
                 }
             }
         } elseif (preg_match('/^(\\w+)\\(/', $row['Type'], $matches)) {
             $nativeType = $matches[1];
         } else {
             $nativeType = $row['Type'];
         }
         $this->columns[$name] = new ColumnInfo($this, $name, MySQLTypes::getType($nativeType), $nativeType, $size, $precision, $scale, $is_nullable, $default);
     }
     $this->colsLoaded = true;
 }