summaryrefslogtreecommitdiff
path: root/includes/database/mysql
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/mysql
parentb46e90ad366c57095183891de56894d6a449bc14 (diff)
downloadbrdo-3a7047c670399f4dcd4033920004e1123edeec3e.tar.gz
brdo-3a7047c670399f4dcd4033920004e1123edeec3e.tar.bz2
- Patch #12201 by mfb: added support for table descriptions.
Diffstat (limited to 'includes/database/mysql')
-rw-r--r--includes/database/mysql/schema.inc52
1 files changed, 51 insertions, 1 deletions
diff --git a/includes/database/mysql/schema.inc b/includes/database/mysql/schema.inc
index 5b0aadee7..1a1508b8b 100644
--- a/includes/database/mysql/schema.inc
+++ b/includes/database/mysql/schema.inc
@@ -15,6 +15,16 @@
class DatabaseSchema_mysql extends DatabaseSchema {
/**
+ * Maximum length of a table comment in MySQL.
+ */
+ const COMMENT_MAX_TABLE = 60;
+
+ /**
+ * Maximum length of a column comment in MySQL.
+ */
+ const COMMENT_MAX_COLUMN = 255;
+
+ /**
* Build a condition to match a table name against a standard information_schema.
*
* MySQL uses databases like schemas rather than catalogs so when we build
@@ -50,7 +60,7 @@ class DatabaseSchema_mysql extends DatabaseSchema {
*/
protected function createTableSql($name, $table) {
if (empty($table['mysql_suffix'])) {
- $table['mysql_suffix'] = "/*!40100 DEFAULT CHARACTER SET UTF8 */";
+ $table['mysql_suffix'] = 'DEFAULT CHARACTER SET UTF8';
}
$sql = "CREATE TABLE {" . $name . "} (\n";
@@ -71,6 +81,11 @@ class DatabaseSchema_mysql extends DatabaseSchema {
$sql .= $table['mysql_suffix'];
+ // Add table comment.
+ if (!empty($table['description'])) {
+ $sql .= ' COMMENT ' . $this->prepareComment($table['description'], self::COMMENT_MAX_TABLE);
+ }
+
return array($sql);
}
@@ -122,6 +137,11 @@ class DatabaseSchema_mysql extends DatabaseSchema {
$sql .= ' DEFAULT NULL';
}
+ // Add column comment.
+ if (!empty($spec['description'])) {
+ $sql .= ' COMMENT ' . $this->prepareComment($spec['description'], self::COMMENT_MAX_COLUMN);
+ }
+
return $sql;
}
@@ -325,6 +345,36 @@ class DatabaseSchema_mysql extends DatabaseSchema {
$ret[] = update_sql($sql);
}
+ public function prepareComment($comment, $length = NULL) {
+ // Decode HTML-encoded comments.
+ $comment = decode_entities(strip_tags($comment));
+
+ // Work around a bug in some versions of PDO, see http://bugs.php.net/bug.php?id=41125
+ $comment = str_replace("'", '’', $comment);
+
+ // Truncate comment to maximum comment length.
+ if (isset($length)) {
+ // Add table prefixes before truncating.
+ $comment = truncate_utf8($this->connection->prefixTables($comment), $length, TRUE, TRUE);
+ }
+
+ return $this->connection->quote($comment);
+ }
+
+ /**
+ * Retrieve a table or column comment.
+ */
+ public function getComment($table, $column = NULL) {
+ $condition = $this->buildTableNameCondition($this->connection->prefixTables('{' . $table . '}'));
+ if (isset($column)) {
+ $condition->condition('column_name', $column);
+ $condition->compile($this->connection);
+ return db_query("SELECT column_comment FROM information_schema.columns WHERE " . (string) $condition, $condition->arguments())->fetchField();
+ }
+ $condition->compile($this->connection);
+ return db_query("SELECT table_comment FROM information_schema.tables WHERE " . (string) $condition, $condition->arguments())->fetchField();
+ }
+
}
/**