Skip to content

Commit

Permalink
Fix to be sure database is not created using utf8mb4 (not yet supported)
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Jul 2, 2017
1 parent efecb32 commit aa1351d
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 8 deletions.
10 changes: 8 additions & 2 deletions htdocs/core/db/mysqli.class.php
Expand Up @@ -857,6 +857,7 @@ function DDLCreateUser($dolibarr_main_db_host,$dolibarr_main_db_user,$dolibarr_m
* Return charset used to store data in current database (same result than using SELECT default_character_set_name FROM information_schema.SCHEMATA WHERE schema_name = "databasename";)
*
* @return string Charset
* @see getDefaultCollationDatabase
*/
function getDefaultCharacterSetDatabase()
{
Expand All @@ -867,7 +868,9 @@ function getDefaultCharacterSetDatabase()
return $this->forcecharset;
}
$liste=$this->fetch_array($resql);
return $liste['Value'];
$tmpval = $liste['Value'];

return $tmpval;
}

/**
Expand Down Expand Up @@ -900,6 +903,7 @@ function getListOfCharacterSet()
* Return collation used in current database
*
* @return string Collation value
* @see getDefaultCharacterSetDatabase
*/
function getDefaultCollationDatabase()
{
Expand All @@ -910,7 +914,9 @@ function getDefaultCollationDatabase()
return $this->forcecollate;
}
$liste=$this->fetch_array($resql);
return $liste['Value'];
$tmpval = $liste['Value'];

return $tmpval;
}

/**
Expand Down
11 changes: 8 additions & 3 deletions htdocs/install/mysql/migration/repair.sql
Expand Up @@ -13,12 +13,17 @@
-- flush privileges;


-- Requests to change character set and collation of a varchar column.
-- utf8 and utf8_unicode_ci is recommended (or even better utf8mb4 and utf8mb4_unicode_ci with mysql 5.5.3+)
-- Request to change default pagecode + colation of database
-- ALTER DATABASE name_of_database CHARACTER SET utf8 COLLATE utf8_unicode_ci;

-- Request to change default pagecode + colation of table
-- ALTER TABLE name_of_table CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;

-- Request to change character set and collation of a varchar column.
-- utf8 and utf8_unicode_ci is recommended (or even better utf8mb4 and utf8mb4_unicode_ci with mysql 5.5.3+)
-- ALTER TABLE llx_accounting_account MODIFY account_number VARCHAR(20) CHARACTER SET utf8;
-- ALTER TABLE llx_accounting_account MODIFY account_number VARCHAR(20) COLLATE utf8_unicode_ci;
-- You can check with 'show full columns from llx_accounting_account';
-- You can check with 'show full columns from mytablename';



Expand Down
3 changes: 2 additions & 1 deletion htdocs/install/mysql/tables/llx_product_attribute.key.sql
Expand Up @@ -16,4 +16,5 @@
--
-- ============================================================================

ALTER TABLE llx_product_attribute ADD CONSTRAINT unique_ref UNIQUE (ref);
ALTER TABLE llx_product_attribute ADD UNIQUE INDEX uk_product_attribute_ref (ref);

15 changes: 13 additions & 2 deletions htdocs/install/step1.php
Expand Up @@ -312,8 +312,11 @@
// Define $defaultCharacterSet and $defaultDBSortingCollation
if (! $error && $db->connected)
{
if (!empty($db_create_database)) { // If we create database, we force default value
$defaultCharacterSet=$db->forcecharset;
if (!empty($db_create_database)) // If we create database, we force default value
{
// Default values come from the database handler

$defaultCharacterSet=$db->forcecharset;
$defaultDBSortingCollation=$db->forcecollate;
}
else // If already created, we take current value
Expand All @@ -322,6 +325,14 @@
$defaultDBSortingCollation=$db->getDefaultCollationDatabase();
}

// Force to avoid utf8mb4 because index on field char 255 reach limit of 767 char for indexes (example with mysql 5.6.34 = mariadb 10.0.29)
// TODO Remove this when utf8mb4 is supported
if ($defaultCharacterSet == 'utf8mb4' || $defaultDBSortingCollation == 'utf8mb4_unicode_ci')
{
$defaultCharacterSet = 'utf8';
$defaultDBSortingCollation = 'utf8_unicode_ci';
}

print '<input type="hidden" name="dolibarr_main_db_character_set" value="'.$defaultCharacterSet.'">';
print '<input type="hidden" name="dolibarr_main_db_collation" value="'.$defaultDBSortingCollation.'">';
$db_character_set=$defaultCharacterSet;
Expand Down

0 comments on commit aa1351d

Please sign in to comment.