Fix pb with mix collation. Add a way to fix this in repair.

This commit is contained in:
Laurent Destailleur 2017-08-04 21:23:40 +02:00
parent e039f7cc22
commit 1c157c7c3d
2 changed files with 32 additions and 23 deletions

View File

@ -146,7 +146,7 @@ function run_sql($sqlfile,$silent=1,$entity='',$usesavepoint=1,$handler='',$oker
$buf = fgets($fp, 4096); $buf = fgets($fp, 4096);
// Test if request must be ran only for particular database or version (if yes, we must remove the -- comment) // Test if request must be ran only for particular database or version (if yes, we must remove the -- comment)
if (preg_match('/^--\sV(MYSQL|PGSQL|)([0-9\.]+)/i',$buf,$reg)) if (preg_match('/^--\sV(MYSQL|PGSQL)([^\s]*)/i',$buf,$reg))
{ {
$qualified=1; $qualified=1;
@ -159,7 +159,10 @@ function run_sql($sqlfile,$silent=1,$entity='',$usesavepoint=1,$handler='',$oker
// restrict on version // restrict on version
if ($qualified) if ($qualified)
{ {
if (! empty($reg[2]))
{
if (is_numeric($reg[2])) // This is a version
{
$versionrequest=explode('.',$reg[2]); $versionrequest=explode('.',$reg[2]);
//print var_dump($versionrequest); //print var_dump($versionrequest);
//print var_dump($versionarray); //print var_dump($versionarray);
@ -168,11 +171,17 @@ function run_sql($sqlfile,$silent=1,$entity='',$usesavepoint=1,$handler='',$oker
$qualified=0; $qualified=0;
} }
} }
else // This is a test on a constant. For example when we have -- VMYSQLUTF8UNICODE, we test constant $conf->global->UTF8UNICODE
{
if (empty($conf->db->dolibarr_main_db_collation) || ($reg[2] != strtoupper(preg_replace('/_/', '', $conf->db->dolibarr_main_db_collation)))) $qualified=0;
}
}
}
if ($qualified) if ($qualified)
{ {
// Version qualified, delete SQL comments // Version qualified, delete SQL comments
$buf=preg_replace('/^--\sV(MYSQL|PGSQL|)([0-9\.]+)/i','',$buf); $buf=preg_replace('/^--\sV(MYSQL|PGSQL)([^\s]*)/i','',$buf);
//print "Ligne $i qualifi?e par version: ".$buf.'<br>'; //print "Ligne $i qualifi?e par version: ".$buf.'<br>';
} }
} }

View File

@ -27,12 +27,12 @@
-- VMYSQLUTF8UNICODE ALTER TABLE llx_accounting_account MODIFY account_number VARCHAR(20) CHARACTER SET utf8; -- VMYSQLUTF8UNICODECI ALTER TABLE llx_accounting_account MODIFY account_number VARCHAR(20) CHARACTER SET utf8;
-- VMYSQLUTF8UNICODE ALTER TABLE llx_accounting_account MODIFY account_number VARCHAR(20) COLLATE utf8_unicode_ci; -- VMYSQLUTF8UNICODECI ALTER TABLE llx_accounting_account MODIFY account_number VARCHAR(20) COLLATE utf8_unicode_ci;
-- VMYSQLUTF8UNICODE ALTER TABLE llx_stock_mouvement MODIFY batch VARCHAR(30) CHARACTER SET utf8; -- VMYSQLUTF8UNICODECI ALTER TABLE llx_stock_mouvement MODIFY batch VARCHAR(30) CHARACTER SET utf8;
-- VMYSQLUTF8UNICODE ALTER TABLE llx_stock_mouvement MODIFY batch VARCHAR(30) COLLATE utf8_unicode_ci; -- VMYSQLUTF8UNICODECI ALTER TABLE llx_stock_mouvement MODIFY batch VARCHAR(30) COLLATE utf8_unicode_ci;
-- VMYSQLUTF8UNICODE ALTER TABLE llx_product_lot MODIFY batch VARCHAR(30) CHARACTER SET utf8; -- VMYSQLUTF8UNICODECI ALTER TABLE llx_product_lot MODIFY batch VARCHAR(30) CHARACTER SET utf8;
-- VMYSQLUTF8UNICODE ALTER TABLE llx_product_lot MODIFY batch VARCHAR(30) COLLATE utf8_unicode_ci; -- VMYSQLUTF8UNICODECI ALTER TABLE llx_product_lot MODIFY batch VARCHAR(30) COLLATE utf8_unicode_ci;