baser/models/datasources/dbo/dbo_postgres_ex.php
/**
 * Returns an array of the fields in given table name.
 *
 * @param string $tableName Name of database table to inspect
 * @return array Fields in table. Keys are name and type
 */
Returns an array of the fields in given table name.
@param string $tableName Name of database table to inspect
@return array Fields in table. Keys are name and type
Returns an array of the fields in given table name . @param string $tableName Name of database table to inspect @return array Fields in table . Keys are name and type
function &describe(&$model) {
		$fields = $this->__describe($model);
		$table = $this->fullTableName($model, false);
		$this->_sequenceMap[$table] = array();
		if ($fields === null) {
			$cols = $this->fetchAll(
				"SELECT DISTINCT column_name AS name, data_type AS type, udt_name AS udt, is_nullable AS null,
					column_default AS default, ordinal_position AS position, character_maximum_length AS char_length,
					character_octet_length AS oct_length FROM information_schema.columns
				WHERE table_name = " . $this->value($table) . " AND table_schema = " .
				$this->value($this->config['schema'])."  ORDER BY position",
				false
			);
			foreach ($cols as $column) {
				$colKey = array_keys($column);
				if (isset($column[$colKey[0]]) && !isset($column[0])) {
					$column[0] = $column[$colKey[0]];
				}
				if (isset($column[0])) {
					$c = $column[0];
					if (!empty($c['char_length'])) {
						$length = intval($c['char_length']);
					} elseif (!empty($c['oct_length'])) {
						if ($c['type'] == 'character varying') {
							$length = null;
							$c['type'] = 'text';
						} elseif($c['type'] == 'text') {
							$length = null;
						} else {
							$length = intval($c['oct_length']);
						}
					} else {
						$length = $this->length($c['udt']);
					}
					$fields[$c['name']] = array(
						'type'    => $this->column($c['type']),
						'null'    => ($c['null'] == 'NO' ? false : true),
						'default' => preg_replace(
							"/^'(.*)'$/",
							"$1",
							preg_replace('/::.*/', '', $c['default'])
						),
						'length'  => $length
					);
					if (!$fields[$c['name']]['length'] && $fields[$c['name']]['type'] == 'integer') {
						$fields[$c['name']]['length'] = 8;
					}
					if ($c['name'] == $model->primaryKey) {
						$fields[$c['name']]['key'] = 'primary';
						if ($fields[$c['name']]['type'] !== 'string') {
							$fields[$c['name']]['length'] = 8;
						}
					}
					if (
						$fields[$c['name']]['default'] == 'NULL' ||
						preg_match('/nextval\([\'"]?([\w.]+)/', $c['default'], $seq)
					) {
						$fields[$c['name']]['default'] = null;
						if (!empty($seq) && isset($seq[1])) {
							$this->_sequenceMap[$table][$c['name']] = $seq[1];
						}
					}
					if($fields[$c['name']]['default'] === 'true' && $fields[$c['name']]['type'] == 'boolean') {
						$fields[$c['name']]['default'] = 1;
					} elseif($fields[$c['name']]['default'] === 'false' && $fields[$c['name']]['type'] == 'boolean') {
						$fields[$c['name']]['default'] = 0;
					}
				}
			}
			$this->__cacheDescription($table, $fields);
		}
		if (isset($model->sequence)) {
			$this->_sequenceMap[$table][$model->primaryKey] = $model->sequence;
		}
		return $fields;
	}
function & describe ( & $ model ) { $ fields = $ this -> __describe ( $ model ) ; $ table = $ this -> fullTableName ( $ model , false ) ; $ this -> _sequenceMap [ $ table ] = array ( ) ; if ( $ fields === null ) { $ cols = $ this -> fetchAll ( " SELECT DISTINCT column_name AS name, data_type AS type, udt_name AS udt, is_nullable AS null,
					column_default AS default, ordinal_position AS position, character_maximum_length AS char_length,
					character_octet_length AS oct_length FROM information_schema.columns
				WHERE table_name =  " . $ this -> value ( $ table ) . "  AND table_schema =  " . $ this -> value ( $ this -> config [ 'schema' ] ) . "   ORDER BY position " , false ) ; foreach ( $ cols as $ column ) { $ colKey = array_keys ( $ column ) ; if ( isset ( $ column [ $ colKey [ 0 ] ] ) && ! isset ( $ column [ 0 ] ) ) { $ column [ 0 ] = $ column [ $ colKey [ 0 ] ] ; } if ( isset ( $ column [ 0 ] ) ) { $ c = $ column [ 0 ] ; if ( ! empty ( $ c [ 'char_length' ] ) ) { $ length = intval ( $ c [ 'char_length' ] ) ; } elseif ( ! empty ( $ c [ 'oct_length' ] ) ) { if ( $ c [ 'type' ] == 'character varying' ) { $ length = null ; $ c [ 'type' ] = 'text' ; } elseif ( $ c [ 'type' ] == 'text' ) { $ length = null ; } else { $ length = intval ( $ c [ 'oct_length' ] ) ; } } else { $ length = $ this -> length ( $ c [ 'udt' ] ) ; } $ fields [ $ c [ 'name' ] ] = array ( 'type' => $ this -> column ( $ c [ 'type' ] ) , 'null' => ( $ c [ 'null' ] == 'NO' ? false : true ) , 'default' => preg_replace ( " /^'(.*)'$/ " , " $1 " , preg_replace ( '/::.*/' , '' , $ c [ 'default' ] ) ) , 'length' => $ length ) ; if ( ! $ fields [ $ c [ 'name' ] ] [ 'length' ] && $ fields [ $ c [ 'name' ] ] [ 'type' ] == 'integer' ) { $ fields [ $ c [ 'name' ] ] [ 'length' ] = 8 ; } if ( $ c [ 'name' ] == $ model -> primaryKey ) { $ fields [ $ c [ 'name' ] ] [ 'key' ] = 'primary' ; if ( $ fields [ $ c [ 'name' ] ] [ 'type' ] !== 'string' ) { $ fields [ $ c [ 'name' ] ] [ 'length' ] = 8 ; } } if ( $ fields [ $ c [ 'name' ] ] [ 'default' ] == 'NULL' || preg_match ( '/nextval\([\'"]?([\w.]+)/' , $ c [ 'default' ] , $ seq ) ) { $ fields [ $ c [ 'name' ] ] [ 'default' ] = null ; if ( ! empty ( $ seq ) && isset ( $ seq [ 1 ] ) ) { $ this -> _sequenceMap [ $ table ] [ $ c [ 'name' ] ] = $ seq [ 1 ] ; } } if ( $ fields [ $ c [ 'name' ] ] [ 'default' ] === 'true' && $ fields [ $ c [ 'name' ] ] [ 'type' ] == 'boolean' ) { $ fields [ $ c [ 'name' ] ] [ 'default' ] = 1 ; } elseif ( $ fields [ $ c [ 'name' ] ] [ 'default' ] === 'false' && $ fields [ $ c [ 'name' ] ] [ 'type' ] == 'boolean' ) { $ fields [ $ c [ 'name' ] ] [ 'default' ] = 0 ; } } } $ this -> __cacheDescription ( $ table , $ fields ) ; } if ( isset ( $ model -> sequence ) ) { $ this -> _sequenceMap [ $ table ] [ $ model -> primaryKey ] = $ model -> sequence ; } return $ fields ; }
Returns an array of the fields in given table name.
Returns an array of the fields in given table name .
// >>> CUSTOMIZE MODIFY 2012/04/23 ryuring //$fields = parent::describe($model); // --- // <<< // >>> CUSTOMIZE MODIFY 2012/04/23 ryuring /*$cols = $this->fetchAll(
				"SELECT DISTINCT column_name AS name, data_type AS type, is_nullable AS null,
					column_default AS default, ordinal_position AS position, character_maximum_length AS char_length,
					character_octet_length AS oct_length FROM information_schema.columns
				WHERE table_name = " . $this->value($table) . " AND table_schema = " .
				$this->value($this->config['schema'])."  ORDER BY position",
				false
			);*/ // --- // <<< // >>> CUSTOMIZE ADD 2011/08/22 ryuring // <<< // >>> CUSTOMIZE MODIFY 2012/04/23 ryuring //$length = $this->length($c['type']); // --- // <<< // >>> CUSTOMIZE ADD 2011/08/22 ryuring // <<< // >>> CUSTOMIZE MODIFY 2011/08/22 ryuring //$fields[$c['name']]['length'] = 11; // --- // <<< // >>> CUSTOMIZE ADD 2011/08/22 ryuring // <<<