コード例 #1
0
ファイル: ColumnObject.php プロジェクト: railsphp/framework
 /**
  * @param string $dataType  E.g. "tinyint(4)", "varchar(255)"
  */
 public function setDataType($dataType)
 {
     parent::setDataType($dataType);
     $this->extractMetadata($dataType);
     $this->setType($this->simplifiedDataType($dataType));
     return $this;
 }
コード例 #2
0
ファイル: AbstractSource.php プロジェクト: totolouis/ZF2-Auth
 /**
  * Get column
  *
  * @param  string $columnName
  * @param  string $table
  * @param  string $schema
  * @return Object\ColumnObject
  */
 public function getColumn($columnName, $table, $schema = null)
 {
     if ($schema === null) {
         $schema = $this->defaultSchema;
     }
     $this->loadColumnData($table, $schema);
     if (!isset($this->data['columns'][$schema][$table][$columnName])) {
         throw new \Exception('A column by that name was not found.');
     }
     $info = $this->data['columns'][$schema][$table][$columnName];
     $column = new Object\ColumnObject($columnName, $table, $schema);
     $props = array('ordinal_position', 'column_default', 'is_nullable', 'data_type', 'character_maximum_length', 'character_octet_length', 'numeric_precision', 'numeric_scale', 'numeric_unsigned', 'erratas');
     foreach ($props as $prop) {
         if (isset($info[$prop])) {
             $column->{'set' . str_replace('_', '', $prop)}($info[$prop]);
         }
     }
     $column->setOrdinalPosition($info['ordinal_position']);
     $column->setColumnDefault($info['column_default']);
     $column->setIsNullable($info['is_nullable']);
     $column->setDataType($info['data_type']);
     $column->setCharacterMaximumLength($info['character_maximum_length']);
     $column->setCharacterOctetLength($info['character_octet_length']);
     $column->setNumericPrecision($info['numeric_precision']);
     $column->setNumericScale($info['numeric_scale']);
     $column->setNumericUnsigned($info['numeric_unsigned']);
     $column->setErratas($info['erratas']);
     return $column;
 }
コード例 #3
0
 /**
  * Get column
  * 
  * @param  string $columnName
  * @param  string $table
  * @param  string $schema
  * @param  string $database
  * @return Object\ColumnObject 
  */
 public function getColumn($columnName, $table, $schema = null)
 {
     // set values for database & schema
     $database = $database ?: '__DEFAULT_DB__';
     if ($schema == null && $this->defaultSchema != null) {
         $schema = $this->defaultSchema;
     }
     if (!isset($this->data[$database][$schema]['columns'][$table][$columnName])) {
         $this->loadColumnData($table, $schema, $database);
     }
     if (!isset($this->data[$database][$schema]['columns'][$table][$columnName])) {
         throw new \Exception('A column by that name was not found.');
     }
     $columnInfo =& $this->data[$database][$schema]['columns'][$table][$columnName];
     $column = new Object\ColumnObject($columnName, $table, $schema);
     $column->setOrdinalPosition($columnInfo['ORDINAL_POSITION']);
     $column->setColumnDefault($columnInfo['COLUMN_DEFAULT']);
     $column->setIsNullable($columnInfo['IS_NULLABLE']);
     $column->setDataType($columnInfo['DATA_TYPE']);
     $column->setCharacterMaximumLength($columnInfo['CHARACTER_MAXIMUM_LENGTH']);
     $column->setCharacterOctetLength($columnInfo['CHARACTER_OCTET_LENGTH']);
     $column->setNumericPrecision($columnInfo['NUMERIC_PRECISION']);
     $column->setNumericScale($columnInfo['NUMERIC_SCALE']);
     return $column;
 }
コード例 #4
0
ファイル: SqliteMetadata.php プロジェクト: necrogami/zf2
    /**
     * Get column
     * 
     * @param  string $columnName
     * @param  string $table
     * @param  string $schema
     * @param  string $database
     * @return Object\ColumnObject 
     */
    public function getColumn($columnName, $table, $schema = null)
    {
        $sql = 'PRAGMA table_info("' . $table . '")';
        $rows = $this->adapter->query($sql, Adapter::QUERY_MODE_EXECUTE);

        $found = false;
        foreach ($rows->toArray() as $row) {
            if ($row['name'] == $columnName) {
                $found = $row;
                break;
            }
        }

        if ($found == false) {
            throw new \Exception('Column not found');
        }

        $column = new Object\ColumnObject($found['name'], $table);
        $column->setOrdinalPosition($found['cid']);
        $column->setDataType($found['type']);
        $column->setIsNullable(!((bool) $found['notnull']));
        $column->setColumnDefault($found['dflt_value']);
        return $column;
    }
コード例 #5
0
ファイル: DbUpgrade.php プロジェクト: no-reply/cbpl-vufind
 /**
  * Given a table column object, return true if the object's type matches the
  * specified $type parameter.  Return false if there is a mismatch that will
  * require table structure updates.
  *
  * @param \Zend\Db\Metadata\Object\ColumnObject $column       Object to check
  * @param string                                $expectedType Type to compare
  *
  * @return bool
  */
 protected function typeMatches($column, $expectedType)
 {
     // Get base type:
     $type = $column->getDataType();
     // If it's not a blob or a text (which don't have explicit sizes in our SQL),
     // we should see what the character length is, if any:
     if ($type != 'blob' && $type != 'text') {
         $charLen = $column->getCharacterMaximumLength();
         if ($charLen) {
             $type .= '(' . $charLen . ')';
         }
     }
     // If it's an integer, the expected type will have a parenthetical value;
     // this is a display width which we can't retrieve using the column metadata
     // object.  Since display width is not important to VuFind, we should ignore
     // this factor when comparing things.
     if ($type == 'int' || $type == 'tinyint' || $type == 'smallint' || $type == 'mediumint' || $type == 'bigint') {
         list($expectedType) = explode('(', $expectedType);
     }
     return $type == $expectedType;
 }