diff options
author | Steven Wittens <steven@10.no-reply.drupal.org> | 2006-01-21 01:42:52 +0000 |
---|---|---|
committer | Steven Wittens <steven@10.no-reply.drupal.org> | 2006-01-21 01:42:52 +0000 |
commit | 7914ad0f3f9b29d78e7321ad9addbff99de48a4f (patch) | |
tree | bb97f37f191c966993a9607daa9f4168591dd68c /database | |
parent | 0ff0c4beaaf0ae49e8b9b7afeda83a26d8d59666 (diff) | |
download | brdo-7914ad0f3f9b29d78e7321ad9addbff99de48a4f.tar.gz brdo-7914ad0f3f9b29d78e7321ad9addbff99de48a4f.tar.bz2 |
- #40515: Ensure UTF-8 character set on the database side (and include upgrade path for incorrectly set up databases)
Diffstat (limited to 'database')
-rw-r--r-- | database/database.mysql | 177 | ||||
-rw-r--r-- | database/database.pgsql | 2 | ||||
-rw-r--r-- | database/updates.inc | 142 |
3 files changed, 257 insertions, 64 deletions
diff --git a/database/database.mysql b/database/database.mysql index 635ae5046..cb6917c3b 100644 --- a/database/database.mysql +++ b/database/database.mysql @@ -1,19 +1,14 @@ --- MySQL dump 8.22 --- --- Host: localhost Database: drupal_devel --- Server version 3.23.52-nt - -- -- Table structure for table 'access' -- - CREATE TABLE access ( aid tinyint(10) NOT NULL auto_increment, mask varchar(255) NOT NULL default '', type varchar(255) NOT NULL default '', status tinyint(2) NOT NULL default '0', PRIMARY KEY (aid) -) TYPE=MyISAM; +) TYPE=MyISAM +/*!40100 DEFAULT CHARACTER SET utf8 */ ; -- -- Table structure for table 'accesslog' @@ -31,7 +26,8 @@ CREATE TABLE accesslog ( timestamp int(11) unsigned NOT NULL default '0', KEY accesslog_timestamp (timestamp), PRIMARY KEY (aid) -) TYPE=MyISAM; +) TYPE=MyISAM +/*!40100 DEFAULT CHARACTER SET utf8 */ ; -- -- Table structure for table 'aggregator_category' @@ -44,7 +40,8 @@ CREATE TABLE aggregator_category ( block tinyint(2) NOT NULL default '0', PRIMARY KEY (cid), UNIQUE KEY title (title) -) TYPE=MyISAM; +) TYPE=MyISAM +/*!40100 DEFAULT CHARACTER SET utf8 */ ; -- -- Table structure for table 'aggregator_category_feed' @@ -54,7 +51,8 @@ CREATE TABLE aggregator_category_feed ( fid int(10) NOT NULL default '0', cid int(10) NOT NULL default '0', PRIMARY KEY (fid,cid) -) TYPE=MyISAM; +) TYPE=MyISAM +/*!40100 DEFAULT CHARACTER SET utf8 */ ; -- -- Table structure for table 'aggregator_category_item' @@ -64,7 +62,8 @@ CREATE TABLE aggregator_category_item ( iid int(10) NOT NULL default '0', cid int(10) NOT NULL default '0', PRIMARY KEY (iid,cid) -) TYPE=MyISAM; +) TYPE=MyISAM +/*!40100 DEFAULT CHARACTER SET utf8 */ ; -- -- Table structure for table 'aggregator_feed' @@ -85,7 +84,8 @@ CREATE TABLE aggregator_feed ( PRIMARY KEY (fid), UNIQUE KEY link (url), UNIQUE KEY title (title) -) TYPE=MyISAM; +) TYPE=MyISAM +/*!40100 DEFAULT CHARACTER SET utf8 */ ; -- -- Table structure for table 'aggregator_item' @@ -100,7 +100,8 @@ CREATE TABLE aggregator_item ( description longtext NOT NULL, timestamp int(11) default NULL, PRIMARY KEY (iid) -) TYPE=MyISAM; +) TYPE=MyISAM +/*!40100 DEFAULT CHARACTER SET utf8 */ ; -- -- Table structure for table 'authmap' @@ -113,7 +114,8 @@ CREATE TABLE authmap ( module varchar(128) NOT NULL default '', PRIMARY KEY (aid), UNIQUE KEY authname (authname) -) TYPE=MyISAM; +) TYPE=MyISAM +/*!40100 DEFAULT CHARACTER SET utf8 */ ; -- -- Table structure for table 'blocks' @@ -130,7 +132,8 @@ CREATE TABLE blocks ( throttle tinyint(1) DEFAULT '0' NOT NULL, visibility tinyint(1) DEFAULT '0' NOT NULL, pages text DEFAULT '' NOT NULL -) TYPE=MyISAM; +) TYPE=MyISAM +/*!40100 DEFAULT CHARACTER SET utf8 */ ; -- -- Table structure for table 'book' @@ -144,7 +147,8 @@ CREATE TABLE book ( PRIMARY KEY (vid), KEY nid (nid), KEY parent (parent) -) TYPE=MyISAM; +) TYPE=MyISAM +/*!40100 DEFAULT CHARACTER SET utf8 */ ; -- -- Table structure for table 'boxes' @@ -158,7 +162,8 @@ CREATE TABLE boxes ( format int(4) NOT NULL default '0', PRIMARY KEY (bid), UNIQUE KEY info (info) -) TYPE=MyISAM; +) TYPE=MyISAM +/*!40100 DEFAULT CHARACTER SET utf8 */ ; -- -- Table structure for table 'cache' @@ -172,7 +177,8 @@ CREATE TABLE cache ( headers text, PRIMARY KEY (cid), INDEX expire (expire) -) TYPE=MyISAM; +) TYPE=MyISAM +/*!40100 DEFAULT CHARACTER SET utf8 */ ; -- -- Table structure for table 'comments' @@ -197,7 +203,8 @@ CREATE TABLE comments ( homepage varchar(255) default NULL, PRIMARY KEY (cid), KEY lid (nid) -) TYPE=MyISAM; +) TYPE=MyISAM +/*!40100 DEFAULT CHARACTER SET utf8 */ ; -- -- Table structre for table 'contact' @@ -212,7 +219,8 @@ CREATE TABLE contact ( selected tinyint(1) NOT NULL default '0', PRIMARY KEY (cid), UNIQUE KEY category (category) -) TYPE=MyISAM; +) TYPE=MyISAM +/*!40100 DEFAULT CHARACTER SET utf8 */ ; -- -- Table structre for table 'node_comment_statistics' @@ -226,7 +234,8 @@ CREATE TABLE node_comment_statistics ( comment_count int(10) unsigned NOT NULL default '0', PRIMARY KEY (nid), KEY node_comment_timestamp (last_comment_timestamp) -) TYPE=MyISAM; +) TYPE=MyISAM +/*!40100 DEFAULT CHARACTER SET utf8 */ ; -- -- Table structure for table 'client' @@ -245,7 +254,8 @@ CREATE TABLE client ( created int(11) NOT NULL default '0', changed int(11) NOT NULL default '0', PRIMARY KEY (cid) -) TYPE=MyISAM; +) TYPE=MyISAM +/*!40100 DEFAULT CHARACTER SET utf8 */ ; -- -- Table structure for table 'client_system' @@ -256,7 +266,8 @@ CREATE TABLE client_system ( name varchar(255) NOT NULL default '', type varchar(255) NOT NULL default '', PRIMARY KEY (cid,name) -) TYPE=MyISAM; +) TYPE=MyISAM +/*!40100 DEFAULT CHARACTER SET utf8 */ ; -- -- Table structure for table 'files' @@ -274,7 +285,8 @@ CREATE TABLE files ( list tinyint(1) unsigned NOT NULL default '0', KEY vid (vid), KEY fid (fid) -) TYPE=MyISAM; +) TYPE=MyISAM +/*!40100 DEFAULT CHARACTER SET utf8 */ ; -- -- Table structure for table 'filter_formats' @@ -286,7 +298,8 @@ CREATE TABLE filter_formats ( roles varchar(255) NOT NULL default '', cache tinyint(2) NOT NULL default '0', PRIMARY KEY (format) -) TYPE=MyISAM; +) TYPE=MyISAM +/*!40100 DEFAULT CHARACTER SET utf8 */ ; -- -- Table structure for table 'filters' @@ -298,7 +311,8 @@ CREATE TABLE filters ( delta tinyint(2) DEFAULT '0' NOT NULL, weight tinyint(2) DEFAULT '0' NOT NULL, INDEX (weight) -) TYPE=MyISAM; +) TYPE=MyISAM +/*!40100 DEFAULT CHARACTER SET utf8 */ ; -- -- Table structure for table 'flood' @@ -308,7 +322,8 @@ CREATE TABLE flood ( event varchar(64) NOT NULL default '', hostname varchar(128) NOT NULL default '', timestamp int(11) NOT NULL default '0' -) TYPE=MyISAM; +) TYPE=MyISAM +/*!40100 DEFAULT CHARACTER SET utf8 */ ; -- -- Table structure for table 'forum' @@ -321,7 +336,8 @@ CREATE TABLE forum ( PRIMARY KEY (nid), KEY vid (vid), KEY tid (tid) -) TYPE=MyISAM; +) TYPE=MyISAM +/*!40100 DEFAULT CHARACTER SET utf8 */ ; -- -- Table structure for table 'history' @@ -332,7 +348,8 @@ CREATE TABLE history ( nid int(10) NOT NULL default '0', timestamp int(11) NOT NULL default '0', PRIMARY KEY (uid,nid) -) TYPE=MyISAM; +) TYPE=MyISAM +/*!40100 DEFAULT CHARACTER SET utf8 */ ; -- -- Table structure for table 'locales_meta' @@ -346,7 +363,8 @@ CREATE TABLE locales_meta ( plurals int(1) NOT NULL default '0', formula varchar(128) NOT NULL default '', PRIMARY KEY (locale) -) TYPE=MyISAM; +) TYPE=MyISAM +/*!40100 DEFAULT CHARACTER SET utf8 */ ; -- -- Table structure for table 'locales_source' @@ -357,7 +375,8 @@ CREATE TABLE locales_source ( location varchar(255) NOT NULL default '', source blob NOT NULL, PRIMARY KEY (lid) -) TYPE=MyISAM; +) TYPE=MyISAM +/*!40100 DEFAULT CHARACTER SET utf8 */ ; -- -- Table structure for table 'locales_target' @@ -373,7 +392,8 @@ CREATE TABLE locales_target ( KEY lang (locale), KEY plid (plid), KEY plural (plural) -) TYPE=MyISAM; +) TYPE=MyISAM +/*!40100 DEFAULT CHARACTER SET utf8 */ ; -- -- Table structure for table 'menu' @@ -388,7 +408,8 @@ CREATE TABLE menu ( weight tinyint(4) NOT NULL default '0', type int(2) unsigned NOT NULL default '0', PRIMARY KEY (mid) -) TYPE=MyISAM; +) TYPE=MyISAM +/*!40100 DEFAULT CHARACTER SET utf8 */ ; -- -- Table structure for table 'node' @@ -418,7 +439,8 @@ CREATE TABLE node ( KEY node_created (created), KEY node_changed (changed), KEY node_status_type (status, type, nid) -) TYPE=MyISAM; +) TYPE=MyISAM +/*!40100 DEFAULT CHARACTER SET utf8 */ ; -- -- Table structure for table `node_access` @@ -432,7 +454,8 @@ CREATE TABLE node_access ( grant_update tinyint(1) unsigned NOT NULL default '0', grant_delete tinyint(1) unsigned NOT NULL default '0', PRIMARY KEY (nid,gid,realm) -) TYPE=MyISAM; +) TYPE=MyISAM +/*!40100 DEFAULT CHARACTER SET utf8 */ ; -- -- Table structure for table 'node_revisions' @@ -450,7 +473,8 @@ CREATE TABLE node_revisions ( format int(4) NOT NULL default '0', PRIMARY KEY (nid,vid), KEY uid (uid) -) TYPE=MyISAM; +) TYPE=MyISAM +/*!40100 DEFAULT CHARACTER SET utf8 */ ; -- -- Table structure for table 'profile_fields' @@ -472,7 +496,8 @@ CREATE TABLE profile_fields ( KEY category (category), UNIQUE KEY name (name), PRIMARY KEY (fid) -) TYPE=MyISAM; +) TYPE=MyISAM +/*!40100 DEFAULT CHARACTER SET utf8 */ ; -- -- Table structure for table 'profile_values' @@ -484,7 +509,8 @@ CREATE TABLE profile_values ( value text, KEY uid (uid), KEY fid (fid) -) TYPE=MyISAM; +) TYPE=MyISAM +/*!40100 DEFAULT CHARACTER SET utf8 */ ; -- @@ -498,7 +524,8 @@ CREATE TABLE url_alias ( PRIMARY KEY (pid), UNIQUE KEY dst (dst), KEY src (src) -) TYPE=MyISAM; +) TYPE=MyISAM +/*!40100 DEFAULT CHARACTER SET utf8 */ ; -- -- Table structure for table 'permission' @@ -509,7 +536,8 @@ CREATE TABLE permission ( perm longtext, tid int(10) unsigned NOT NULL default '0', KEY rid (rid) -) TYPE=MyISAM; +) TYPE=MyISAM +/*!40100 DEFAULT CHARACTER SET utf8 */ ; -- -- Table structure for table 'poll' @@ -520,7 +548,8 @@ CREATE TABLE poll ( runtime int(10) NOT NULL default '0', active int(2) unsigned NOT NULL default '0', PRIMARY KEY (nid) -) TYPE=MyISAM; +) TYPE=MyISAM +/*!40100 DEFAULT CHARACTER SET utf8 */ ; -- -- Table structure for table 'poll_votes' @@ -533,7 +562,8 @@ CREATE TABLE poll_votes ( INDEX (nid), INDEX (uid), INDEX (hostname) -) TYPE=MyISAM; +) TYPE=MyISAM +/*!40100 DEFAULT CHARACTER SET utf8 */ ; -- -- Table structure for table 'poll_choices' @@ -547,7 +577,8 @@ CREATE TABLE poll_choices ( chorder int(2) NOT NULL default '0', PRIMARY KEY (chid), KEY nid (nid) -) TYPE=MyISAM; +) TYPE=MyISAM +/*!40100 DEFAULT CHARACTER SET utf8 */ ; -- -- Table structure for table 'role' @@ -558,7 +589,8 @@ CREATE TABLE role ( name varchar(32) NOT NULL default '', PRIMARY KEY (rid), UNIQUE KEY name (name) -) TYPE=MyISAM; +) TYPE=MyISAM +/*!40100 DEFAULT CHARACTER SET utf8 */ ; -- -- Table structure for table 'search_dataset' @@ -568,7 +600,8 @@ CREATE TABLE search_dataset ( type varchar(16) default NULL, data longtext NOT NULL, KEY sid_type (sid, type) -) TYPE=MyISAM; +) TYPE=MyISAM +/*!40100 DEFAULT CHARACTER SET utf8 */ ; -- -- Table structure for table 'search_index' @@ -584,7 +617,8 @@ CREATE TABLE search_index ( KEY sid_type (sid, type), KEY from_sid_type (fromsid, fromtype), KEY word (word) -) TYPE=MyISAM; +) TYPE=MyISAM +/*!40100 DEFAULT CHARACTER SET utf8 */ ; -- -- Table structure for table 'search_total' @@ -594,7 +628,8 @@ CREATE TABLE search_total ( word varchar(50) NOT NULL default '', count float default NULL, PRIMARY KEY (word) -) TYPE=MyISAM; +) TYPE=MyISAM +/*!40100 DEFAULT CHARACTER SET utf8 */ ; -- -- Table structure for table 'sessions' @@ -611,7 +646,8 @@ CREATE TABLE sessions ( KEY uid (uid), PRIMARY KEY (sid), KEY timestamp (timestamp) -) TYPE=MyISAM; +) TYPE=MyISAM +/*!40100 DEFAULT CHARACTER SET utf8 */ ; -- -- Table structure for table 'sequences' @@ -621,7 +657,8 @@ CREATE TABLE sequences ( name varchar(255) NOT NULL default '', id int(10) unsigned NOT NULL default '0', PRIMARY KEY (name) -) TYPE=MyISAM; +) TYPE=MyISAM +/*!40100 DEFAULT CHARACTER SET utf8 */ ; -- -- Table structure for table 'node_counter' @@ -636,7 +673,8 @@ CREATE TABLE node_counter ( KEY totalcount (totalcount), KEY daycount (daycount), KEY timestamp (timestamp) -) TYPE=MyISAM; +) TYPE=MyISAM +/*!40100 DEFAULT CHARACTER SET utf8 */ ; -- -- Table structure for table 'system' @@ -650,11 +688,12 @@ CREATE TABLE system ( status int(2) NOT NULL default '0', throttle tinyint(1) DEFAULT '0' NOT NULL, bootstrap int(2) NOT NULL default '0', - schema_version smallint(2) unsigned NOT NULL default 0, + schema_version smallint(3) NOT NULL default -1, weight int(2) NOT NULL default '0', PRIMARY KEY (filename), KEY (weight) -) TYPE=MyISAM; +) TYPE=MyISAM +/*!40100 DEFAULT CHARACTER SET utf8 */ ; -- -- Table structure for table 'term_data' @@ -668,7 +707,8 @@ CREATE TABLE term_data ( weight tinyint(4) NOT NULL default '0', PRIMARY KEY (tid), KEY vid (vid) -) TYPE=MyISAM; +) TYPE=MyISAM +/*!40100 DEFAULT CHARACTER SET utf8 */ ; -- -- Table structure for table 'term_hierarchy' @@ -680,7 +720,8 @@ CREATE TABLE term_hierarchy ( KEY tid (tid), KEY parent (parent), PRIMARY KEY (tid, parent) -) TYPE=MyISAM; +) TYPE=MyISAM +/*!40100 DEFAULT CHARACTER SET utf8 */ ; -- -- Table structure for table 'term_node' @@ -692,7 +733,8 @@ CREATE TABLE term_node ( KEY nid (nid), KEY tid (tid), PRIMARY KEY (tid,nid) -) TYPE=MyISAM; +) TYPE=MyISAM +/*!40100 DEFAULT CHARACTER SET utf8 */ ; -- -- Table structure for table 'term_relation' @@ -703,7 +745,8 @@ CREATE TABLE term_relation ( tid2 int(10) unsigned NOT NULL default '0', KEY tid1 (tid1), KEY tid2 (tid2) -) TYPE=MyISAM; +) TYPE=MyISAM +/*!40100 DEFAULT CHARACTER SET utf8 */ ; -- -- Table structure for table 'term_synonym' @@ -714,7 +757,8 @@ CREATE TABLE term_synonym ( name varchar(255) NOT NULL default '', KEY tid (tid), KEY name (name(3)) -) TYPE=MyISAM; +) TYPE=MyISAM +/*!40100 DEFAULT CHARACTER SET utf8 */ ; -- -- Table structure for table 'users' @@ -742,7 +786,8 @@ CREATE TABLE users ( PRIMARY KEY (uid), UNIQUE KEY name (name), KEY access (access) -) TYPE=MyISAM; +) TYPE=MyISAM +/*!40100 DEFAULT CHARACTER SET utf8 */ ; -- -- Table structure for table 'users_roles' @@ -752,7 +797,8 @@ CREATE TABLE users_roles ( uid int(10) unsigned NOT NULL default '0', rid int(10) unsigned NOT NULL default '0', PRIMARY KEY (uid, rid) -) TYPE=MyISAM; +) TYPE=MyISAM +/*!40100 DEFAULT CHARACTER SET utf8 */ ; -- -- Table structure for table 'variable' @@ -762,7 +808,8 @@ CREATE TABLE variable ( name varchar(48) NOT NULL default '', value longtext NOT NULL, PRIMARY KEY (name) -) TYPE=MyISAM; +) TYPE=MyISAM +/*!40100 DEFAULT CHARACTER SET utf8 */ ; -- -- Table structure for table 'vocabulary' @@ -781,7 +828,8 @@ CREATE TABLE vocabulary ( module varchar(255) NOT NULL default '', weight tinyint(4) NOT NULL default '0', PRIMARY KEY (vid) -) TYPE=MyISAM; +) TYPE=MyISAM +/*!40100 DEFAULT CHARACTER SET utf8 */ ; -- -- Table structure for table 'vocabulary_node_types' @@ -791,7 +839,8 @@ CREATE TABLE vocabulary_node_types ( vid int(10) unsigned NOT NULL DEFAULT '0', type varchar(32) NOT NULL DEFAULT '', PRIMARY KEY (vid, type) -) TYPE=MyISAM; +) TYPE=MyISAM +/*!40100 DEFAULT CHARACTER SET utf8 */ ; -- -- Table structure for table 'watchdog' @@ -809,7 +858,8 @@ CREATE TABLE watchdog ( hostname varchar(128) NOT NULL default '', timestamp int(11) NOT NULL default '0', PRIMARY KEY (wid) -) TYPE=MyISAM; +) TYPE=MyISAM +/*!40100 DEFAULT CHARACTER SET utf8 */ ; -- -- Insert some default values @@ -865,3 +915,4 @@ INSERT INTO variable (name, value) VALUES ('node_options_forum', 'a:1:{i:0;s:6:" INSERT INTO menu VALUES (2, 0, '', 'Primary links', '', 0, 115); INSERT INTO variable VALUES ('menu_primary_menu', 'i:2;'); INSERT INTO variable VALUES ('menu_secondary_menu', 'i:2;'); + diff --git a/database/database.pgsql b/database/database.pgsql index 728f99962..f9b5827f7 100644 --- a/database/database.pgsql +++ b/database/database.pgsql @@ -646,7 +646,7 @@ CREATE TABLE system ( status integer NOT NULL default '0', throttle smallint NOT NULL default '0', bootstrap integer NOT NULL default '0', - schema_version smallint NOT NULL default 0, + schema_version smallint NOT NULL default -1, weight smallint NOT NULL default 0, PRIMARY KEY (filename) ); diff --git a/database/updates.inc b/database/updates.inc index eaf1b5c84..c82f445f5 100644 --- a/database/updates.inc +++ b/database/updates.inc @@ -1437,3 +1437,145 @@ function system_update_168() { return $ret; } + +function system_update_169() { + // Warn PGSQL admins if their database is set up incorrectly + if ($GLOBALS['db_type'] == 'pgsql') { + $encoding = db_result(db_query('SHOW server_encoding')); + if (!in_array(strtolower($encoding), array('unicode', 'utf8'))) { + $msg = 'Your PostgreSQL database is set up with the wrong character encoding ('. $encoding .'). It is possible it will not work as expected. It is advised to recreate it with UTF-8/Unicode encoding. More information can be found in the <a href="http://www.postgresql.org/docs/7.4/interactive/multibyte.html">PostgreSQL documentation</a>.'; + watchdog('php', $msg, WATCHDOG_WARNING); + drupal_set_message($msg, 'status'); + } + } + + return _system_update_utf8(array( + 'access', 'accesslog', 'aggregator_category', + 'aggregator_category_feed', 'aggregator_category_item', + 'aggregator_feed', 'aggregator_item', 'authmap', 'blocks', + 'book', 'boxes', 'cache', 'comments', 'contact', + 'node_comment_statistics', 'client', 'client_system', 'files', + 'filter_formats', 'filters', 'flood', 'forum', 'history', + 'locales_meta', 'locales_source', 'locales_target', 'menu', + 'moderation_filters', 'moderation_roles', 'moderation_votes', + 'node', 'node_access', 'node_revisions', 'profile_fields', + 'profile_values', 'url_alias', 'permission', 'poll', 'poll_votes', + 'poll_choices', 'role', 'search_dataset', 'search_index', + 'search_total', 'sessions', 'sequences', 'node_counter', + 'system', 'term_data', 'term_hierarchy', 'term_node', + 'term_relation', 'term_synonym', 'users', 'users_roles', 'variable', + 'vocabulary', 'vocabulary_node_types', 'watchdog' + )); +} + +/** + * Converts tables to UTF-8 encoding. + * + * This update is designed to be re-usable by contrib modules and is + * used by system_update_169(). + */ +function _system_update_utf8($tables) { + // Are we starting this update for the first time? + if (!isset($_SESSION['update_utf8'])) { + switch ($GLOBALS['db_type']) { + // Only for MySQL 4.1+ + case 'mysqli': + break; + case 'mysql': + if (version_compare(mysql_get_server_info($GLOBALS['active_db']), '4.1.0', '<')) { + return array(); + } + break; + case 'pgsql': + return array(); + } + + // See if database uses UTF-8 already + $url = parse_url($GLOBALS['db_url']); + $db_name = substr($url['path'], 1); + $create = array_pop(db_fetch_array(db_query('SHOW CREATE DATABASE `%s`', $db_name))); + if (preg_match('/utf8/i', $create)) { + return array(); + } + + // Make list of tables to convert + $_SESSION['update_utf8'] = $tables; + // Keep track of total for progress bar + $_SESSION['update_utf8_total'] = count($tables); + } + + // Fetch remaining tables list + $list = &$_SESSION['update_utf8']; + $ret = array(); + + // Convert a table to UTF-8. + // We change all text columns to their correspending binary type, + // then back to text, but with a UTF-8 character set. + // See: http://dev.mysql.com/doc/refman/4.1/en/charset-conversion.html + $types = array('char' => 'binary', + 'varchar' => 'varbinary', + 'tinytext' => 'tinyblob', + 'text' => 'blob', + 'mediumtext' => 'mediumblob', + 'longtext' => 'longblob'); + + // Get next table in list + $table = array_shift($list); + $convert_to_binary = array(); + $convert_to_utf8 = array(); + + // Set table default charset + $ret[] = update_sql("ALTER TABLE \{$table} DEFAULT CHARACTER SET utf8"); + + // Find out which columns need converting and build SQL statements + $result = db_query("SHOW FULL COLUMNS FROM \{$table}"); + while ($column = db_fetch_array($result)) { + list($type) = explode('(', $column['Type']); + if (isset($types[$type])) { + $names = 'CHANGE `'. $column['Field'] .'` `'. $column['Field'] .'` '; + $attributes = ' DEFAULT '. ($column['Default'] == 'NULL' ? 'NULL ' : + "'". db_escape_string($column['Default']) ."' ") . + ($column['Null'] == 'YES' ? 'NULL' : 'NOT NULL'); + + $convert_to_binary[] = $names . preg_replace('/'. $type .'/i', $types[$type], $column['Type']) . $attributes; + $convert_to_utf8[] = $names . $column['Type'] .' CHARACTER SET utf8'. $attributes; + } + } + + if (count($convert_to_binary)) { + // Convert text columns to binary + $ret[] = update_sql("ALTER TABLE \{$table} ". implode(', ', $convert_to_binary)); + // Convert binary columns to UTF-8 + $ret[] = update_sql("ALTER TABLE \{$table} ". implode(', ', $convert_to_utf8)); + } + + // Are we done? + if (count($list) == 0) { + unset($_SESSION['update_utf8']); + unset($_SESSION['update_utf8_total']); + return $ret; + } + + // Progress percentage + $ret['#finished'] = 1 - (count($list) / $_SESSION['update_utf8_total']); + return $ret; +} + +function system_update_170() { + if (!variable_get('update_170_done', false)) { + switch ($GLOBALS['db_type']) { + case 'pgsql': + $ret = array(); + db_change_column($ret, 'system', 'schema_version', 'schema_version', 'smallint', array('not null' => TRUE, 'default' => -1)); + break; + + case 'mysql': + case 'mysqli': + db_query('ALTER TABLE {system} CHANGE schema_version schema_version smallint(3) not null default -1'); + break; + } + // Set schema version -1 (uninstalled) for disabled modules (only affects contrib). + db_query('UPDATE {system} SET schema_version = -1 WHERE status = 0 AND schema_version = 0'); + } + return array(); +} |