php-mysql-diff icon indicating copy to clipboard operation
php-mysql-diff copied to clipboard

different between MySQL and mariadb problem

Open applibs opened this issue 6 years ago • 2 comments

I found that using SHOW CREATE TABLE 'xxx' is different result. I have mariadb on development and mysql on production. Problem is for example DEFAULT, one is DEFAULT 0 and second db is DEFAULT '0'.

applibs avatar Jun 16 '18 14:06 applibs

I found some info: https://mariadb.com/kb/en/library/server-system-variables/#sql_quote_show_create but not works well. This is another info about this: https://jira.mariadb.org/browse/MDEV-15377 https://jira.mariadb.org/browse/MDEV-13244 I see that this library accept only DEFAULT values in quotes. It ignore "DEFAULT 0" for example. Your code is:

if (!empty($defaultValue)) 

but when $defaultValue is "0" it doesnot work. Same for "0.00" etc...

applibs avatar Jun 16 '18 14:06 applibs

this is my fix at Column class:

if (!is_null($this->defaultValue) && $this->nullable === false) {
            if($this->defaultValue === "''" || $this->defaultValue === 'CURRENT_TIMESTAMP') {
                $columnOptions[] = sprintf('DEFAULT %s', $this->defaultValue);
            }
            else {
                $columnOptions[] = sprintf("DEFAULT '%s'", $this->defaultValue);
            }

        }

and at Parser class and function parseColumns:

            if($defaultValue !== '' && $defaultValue !== "''") {
                $defaultValue = trim($defaultValue,"'");
            }
if (!is_null($defaultValue) && $defaultValue !== '') {
                $column->setDefaultValue($defaultValue);
            }

applibs avatar Aug 15 '18 09:08 applibs