summaryrefslogtreecommitdiff
path: root/includes/database/pgsql/schema.inc
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2009-03-14 20:34:17 +0000
committerDries Buytaert <dries@buytaert.net>2009-03-14 20:34:17 +0000
commit3a7047c670399f4dcd4033920004e1123edeec3e (patch)
treea60249a53486dedae5646774b2a461c9291cb89a /includes/database/pgsql/schema.inc
parentb46e90ad366c57095183891de56894d6a449bc14 (diff)
downloadbrdo-3a7047c670399f4dcd4033920004e1123edeec3e.tar.gz
brdo-3a7047c670399f4dcd4033920004e1123edeec3e.tar.bz2
- Patch #12201 by mfb: added support for table descriptions.
Diffstat (limited to 'includes/database/pgsql/schema.inc')
-rw-r--r--includes/database/pgsql/schema.inc27
1 files changed, 27 insertions, 0 deletions
diff --git a/includes/database/pgsql/schema.inc b/includes/database/pgsql/schema.inc
index c8af719e8..be8755102 100644
--- a/includes/database/pgsql/schema.inc
+++ b/includes/database/pgsql/schema.inc
@@ -109,6 +109,18 @@ class DatabaseSchema_pgsql extends DatabaseSchema {
}
}
+ // Add table comment.
+ if (!empty($table['description'])) {
+ $statements[] = 'COMMENT ON TABLE {' . $name . '} IS ' . $this->prepareComment($table['description']);
+ }
+
+ // Add column comments.
+ foreach ($table['fields'] as $field_name => $field) {
+ if (!empty($field['description'])) {
+ $statements[] = 'COMMENT ON COLUMN {' . $name . '}.' . $field_name . ' IS ' . $this->prepareComment($field['description']);
+ }
+ }
+
return $statements;
}
@@ -322,6 +334,10 @@ class DatabaseSchema_pgsql extends DatabaseSchema {
if (isset($new_keys)) {
$this->_createKeys($ret, $table, $new_keys);
}
+ // Add column comment.
+ if (!empty($spec['description'])) {
+ $ret[] = update_sql('COMMENT ON COLUMN {' . $table . '}.' . $field . ' IS ' . $this->prepareComment($spec['description']));
+ }
}
/**
@@ -567,4 +583,15 @@ class DatabaseSchema_pgsql extends DatabaseSchema {
}
}
}
+
+ /**
+ * Retrieve a table or column comment.
+ */
+ public function getComment($table, $column = NULL) {
+ $table = $this->connection->prefixTables('{' . $table . '}');
+ if (isset($column)) {
+ return db_query('SELECT col_description(oid, attnum) FROM pg_class, pg_attribute WHERE attrelid = oid AND relname = ? AND attname = ?', array($table, $column))->fetchField();
+ }
+ return db_query('SELECT obj_description(oid, ?) FROM pg_class WHERE relname = ?', array('pg_class', $table))->fetchField();
+ }
}