27 #require_once 'Zend/Db/Adapter/Pdo/Abstract.php'; 83 if ($this->_connection) {
89 if (!empty($this->_config[
'charset'])) {
90 $sql =
"SET NAMES '" . $this->_config[
'charset'] .
"'";
91 $this->_connection->exec($sql);
103 $sql =
"SELECT c.relname AS table_name " 104 .
"FROM pg_class c, pg_user u " 105 .
"WHERE c.relowner = u.usesysid AND c.relkind = 'r' " 106 .
"AND NOT EXISTS (SELECT 1 FROM pg_views WHERE viewname = c.relname) " 107 .
"AND c.relname !~ '^(pg_|sql_)' " 109 .
"SELECT c.relname AS table_name " 111 .
"WHERE c.relkind = 'r' " 112 .
"AND NOT EXISTS (SELECT 1 FROM pg_views WHERE viewname = c.relname) " 113 .
"AND NOT EXISTS (SELECT 1 FROM pg_user WHERE usesysid = c.relowner) " 114 .
"AND c.relname !~ '^pg_'";
155 a.attname AS colname, 158 FORMAT_TYPE(a.atttypid, a.atttypmod) AS complete_type, 159 d.adsrc AS default_value, 160 a.attnotnull AS notnull, 163 ARRAY_TO_STRING(co.conkey, ',') AS conkey 164 FROM pg_attribute AS a 165 JOIN pg_class AS c ON a.attrelid = c.oid 166 JOIN pg_namespace AS n ON c.relnamespace = n.oid 167 JOIN pg_type AS t ON a.atttypid = t.oid 168 LEFT OUTER JOIN pg_constraint AS co ON (co.conrelid = c.oid 169 AND a.attnum = ANY(co.conkey) AND co.contype = 'p') 170 LEFT OUTER JOIN pg_attrdef AS d ON d.adrelid = c.oid AND d.adnum = a.attnum 171 WHERE a.attnum > 0 AND c.relname = ".$this->quote(
$tableName);
173 $sql .=
" AND n.nspname = ".$this->quote($schemaName);
175 $sql .=
' ORDER BY a.attnum';
177 $stmt = $this->
query($sql);
197 $defaultValue =
$row[$default_value];
199 if (preg_match(
'/character(?: varying)?(?:\((\d+)\))?/',
$row[$complete_type], $matches)) {
200 if (isset($matches[1])) {
201 $row[$length] = $matches[1];
203 $row[$length] =
null;
206 if (preg_match(
"/^'(.*?)'::(?:character varying|bpchar)$/", $defaultValue, $matches)) {
207 $defaultValue = $matches[1];
210 list($primary, $primaryPosition, $identity) = array(
false,
null,
false);
211 if (
$row[$contype] ==
'p') {
213 $primaryPosition = array_search(
$row[$attnum], explode(
',',
$row[$conkey])) + 1;
214 $identity = (bool) (preg_match(
'/^nextval/',
$row[$default_value]));
220 'COLUMN_POSITION' =>
$row[$attnum],
222 'DEFAULT' => $defaultValue,
223 'NULLABLE' => (
bool) (
$row[$notnull] !=
't'),
224 'LENGTH' =>
$row[$length],
228 'PRIMARY' => $primary,
229 'PRIMARY_POSITION' => $primaryPosition,
230 'IDENTITY' => $identity
252 #require_once 'Zend/Db/Adapter/Exception.php'; 256 $offset = intval($offset);
261 #require_once 'Zend/Db/Adapter/Exception.php'; 265 $sql .=
" LIMIT $count";
267 $sql .=
" OFFSET $offset";
328 $sequenceName .=
"_$primaryKey";
330 $sequenceName .=
'_seq';
333 return $this->_connection->lastInsertId(
$tableName);
getQuoteIdentifierSymbol()
fetchOne($sql, $bind=array())
fetchCol($sql, $bind=array())
quote($value, $type=null)
describeTable($tableName, $schemaName=null)
limit($sql, $count, $offset=0)
lastInsertId($tableName=null, $primaryKey=null)
nextSequenceId($sequenceName)
quoteIdentifier($ident, $auto=false)
lastSequenceId($sequenceName)
query($sql, $bind=array())