Exemplo n.º 1
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)
    {
        $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;
    }
Exemplo n.º 2
0
 /**
  * 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;
 }
Exemplo n.º 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;
 }