Skip to content
Permalink
Browse files

Merge branch '873-utf8mb4' into stable

  • Loading branch information...
following5 committed Dec 22, 2015
2 parents 55c1df6 + 0d8b0e7 commit fcd70054b82ecaecd3815b8dc3ddda68f54ac433
@@ -61,6 +61,52 @@
$db_version = -1;
} while ($db_version > 0);
// Ensure that all tables have the right charset, including added tables:
check_tables_charset($opt['db']['placeholder']['db']);
exit;
// Check if the tables' charset is consistent with $opt['charset']['mysql'].
// Do an upgrade from utf8 to utf8mb4 if necessary.
// OKAPI tables upgrade is done by a similar function in OKAPI's update module.
function check_tables_charset($database)
{
global $opt;
$rs = sql("
SELECT TABLE_NAME, TABLE_COLLATION
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA='&1' AND TABLE_NAME NOT LIKE 'okapi_%'",
$database);
while ($table = sql_fetch_assoc($rs))
{
$table_collation = explode('_', $table['TABLE_COLLATION']);
if ($table_collation[0] != $opt['charset']['mysql'])
{
$migrate = "table `" . $table['TABLE_NAME'] . "` from charset " .
$table_collation[0] . " to " . $opt['charset']['mysql'];
if ($table_collation[0] == 'utf8' && $opt['charset']['mysql'] == 'utf8mb4')
{
echo "migrating " . $migrate . "\n";
$table_collation[0] = $opt['charset']['mysql'];
sql("
ALTER TABLE `&1`
CONVERT TO CHARACTER SET '&2'
COLLATE '&3'",
$table['TABLE_NAME'],
$table_collation[0],
implode('_', $table_collation));
}
else
echo "Warning: cannot migrate " . $migrate . "\n";
}
}
sql_free_result($rs);
}
// Now and then a maintain.php update should be inserted, because multiple
// mutations may be run in one batch, and future mutations may depend on
@@ -219,7 +265,7 @@ function dbv_106() // Cache status logging
`new_state` tinyint(2) unsigned NOT NULL,
`user_id` int(10) unsigned NOT NULL default '0',
UNIQUE KEY `cache_id` (`cache_id`,`date_modified`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8");
) ENGINE=MyISAM");
}
function dbv_107() // sync of table definitions, developer and production system
@@ -259,7 +305,7 @@ function dbv_110() // move adoption history to separate table
`to_user_id` int(10) unsigned NOT NULL,
PRIMARY KEY (`id`),
KEY `cache_id` (`cache_id`,`date`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1");
) ENGINE=MyISAM AUTO_INCREMENT=1");
// Up to commit d15ee5f9, new cache notification logs were erronously stored with
// event ID 5 (instead of 8). Therefore we need to check for the module, too:
@@ -406,7 +452,7 @@ function dbv_123() // add tables, fields and procs for cache lists and list wat
UNIQUE KEY `uuid` (`uuid`),
KEY `name` (`name`),
KEY `user_id` (`user_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8");
) ENGINE=MyISAM");
}
if (!sql_table_exists('cache_list_items'))
{
@@ -416,7 +462,7 @@ function dbv_123() // add tables, fields and procs for cache lists and list wat
`cache_id` int(10) NOT NULL,
UNIQUE KEY `cache_list_id` (`cache_list_id`,`cache_id`),
KEY `cache_id` (`cache_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8");
) ENGINE=MyISAM");
}
if (!sql_table_exists('cache_list_watches'))
{
@@ -426,7 +472,7 @@ function dbv_123() // add tables, fields and procs for cache lists and list wat
`user_id` int(10) NOT NULL,
UNIQUE KEY `cache_list_id` (`cache_list_id`,`user_id`),
KEY `user_id` (`user_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8");
) ENGINE=MyISAM");
}
if (!sql_field_exists('caches','show_cachelists'))
@@ -449,7 +495,7 @@ function dbv_124() // update cache lists implementation
`entries` int(6) NOT NULL default '0' COMMENT 'via trigger in cache_list_items',
`watchers` int(6) NOT NULL default '0' COMMENT 'via trigger in cache_list_watches',
PRIMARY KEY (`cache_list_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8
) ENGINE=MyISAM
SELECT `id` `cache_list_id`, `entries`, `watchers` FROM `cache_lists`");
}
if (sql_field_exists('cache_lists','entries'))
@@ -525,7 +571,7 @@ function dbv_129() // cache list passwords & bookmarking
`password` varchar(80) NOT NULL,
UNIQUE KEY `cache_list_id` (`cache_list_id`,`user_id`),
KEY `user_id` (`user_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8");
) ENGINE=MyISAM");
}
}
@@ -581,7 +627,7 @@ function dbv_136() // move main town table from settings into database
`coord_long` double NOT NULL,
`maplist` tinyint(1) NOT NULL default '0',
KEY `country` (`country`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;");
) ENGINE=MyISAM");
}
}
@@ -631,6 +677,16 @@ function dbv_141() // adjust some comments
sql("ALTER TABLE `log_types` MODIFY `icon_small` varchar(255) NOT NULL COMMENT ''");
}
function dbv_142() // drop obsolete table
{
// This table has/had an index over a 255 chars column, which would produce
// the error "index too long (maximum is 1000 chars)" when trying to convert
// to utf8mb4 charset. We drop it here before an utf8 migration may be run.
if (sql_table_exists('search_words'))
sql("DROP TABLE `search_words`");
}
// When adding new mutations, take care that they behave well if run multiple
// times. This improves robustness of database versioning.
@@ -8,6 +8,15 @@
* See also locale.inc.php, which is included in both lib1 and lib2.
***************************************************************************/
/* Database charset
* Frontend and PHP charsets are UTF-8.
* MySQL database default charset is 'utf8' (16 bit restricted Unicode).
* For MySQL or MariaDB >= 5.5, this can be changed to 'utf8mb4' (21 bit full Unicode).
* bin/dbsv-update.php will then migrate the tables' charset.
*/
$opt['charset']['iconv'] = 'UTF-8'; // 'ISO-8859-1'; // use iconv compatible charset-name
$opt['charset']['mysql'] = 'utf8'; // use mysql compatible charset-name
// page title
$opt['page']['title'] = 'OPENCACHING';
$opt['page']['subtitle1'] = 'Geocaching with Opencaching';
@@ -372,17 +372,6 @@
*/
$opt['logic']['api']['email_problems']['key'] = ''; // must be set to enable
/* Database charset
* frontend and php charsets are UTF-8
* here you can set a different charset for the MySQL-Engine
* usefull if your database is not UTF-8.
* Should only be used for step by step migration.
*
* Both charsets must be the same!
*/
$opt['charset']['iconv'] = 'UTF-8'; // 'ISO-8859-1'; // use iconv compatible charset-name
$opt['charset']['mysql'] = 'utf8'; // use mysql compatible charset-name
/* cronjob
*/
$opt['cron']['username'] = 'apache'; // system username for cronjobs

This file was deleted.

Oops, something went wrong.
@@ -580,6 +580,7 @@ function db_disconnect()
function db_connect()
{
global $dblink, $dbpconnect, $dbusername, $dbname, $dbserver, $dbpasswd, $dbpconnect;
global $opt;
//connect to the database by the given method - no php error reporting!
if ($dbpconnect == true)
@@ -593,7 +594,7 @@ function db_connect()
if ($dblink != false)
{
mysql_query("SET NAMES 'utf8'", $dblink);
mysql_query("SET NAMES '" . mysql_real_escape_string($opt['charset']['mysql'], $dblink) . "'", $dblink);
//database connection established ... set the used database
if (@mysql_select_db($dbname, $dblink) == false)

0 comments on commit fcd7005

Please sign in to comment.
You can’t perform that action at this time.