Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better support my sql5.5 #52

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
43 changes: 42 additions & 1 deletion migration/FromMySqlToPostgreSql/FromMySqlToPostgreSql.php
Expand Up @@ -32,6 +32,13 @@ class FromMySqlToPostgreSql
*/
private $mysql;

/**
* A String to hold database version.
*
* @var string
*/
private $mysqlVersion;

/**
* A \PDO instance, connected to PostgreSql server.
*
Expand Down Expand Up @@ -366,6 +373,32 @@ private function generateError(\PDOException $e, $strMessage, $strSql = '')
unset($strError);
}

/**
* Retrieve MySQL version
*
* @param void
* @return bool
*/
private function retrieveMySqlVersion()
{
$sql = '';

try {
$this->connect();
$sql = 'SELECT VERSION() AS mysql_version;';
$stmt = $this->mysql->query($sql);
$arrRows = $stmt->fetchAll(\PDO::FETCH_ASSOC);
$this->mysqlVersion = $arrRows[0]['mysql_version'];
unset( $sql, $stmt, $arrResult );
} catch (\PDOException $e) {
$this->generateError(
$e,
__METHOD__ . PHP_EOL . "\t" . '-- Cannot retrieve version from source (MySql) database...',
$sql
);
}
}

/**
* Load MySql tables, that need to be migrated into an array.
*
Expand Down Expand Up @@ -679,7 +712,12 @@ private function arrangeColumnsData(array $arrColumns)
|| stripos($arrColumn['Type'], 'linestring') !== false
|| stripos($arrColumn['Type'], 'polygon') !== false
) {
$strRetVal .= 'HEX(ST_AsWKB(`' . $arrColumn['Field'] . '`)),';
if ( strcmp( '5.5', substr( $this->mysqlVersion, 0, 3 ) ) == 0
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How will this code deal with MySQL version < 5.5 , or version > 5.5 ?

Am I missing something?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AsBinary() and AsWKB() are deprecated as of MySQL 5.7.6 and will be removed in a future MySQL release.

As far as I know ST_AsWKB will only work for 5.6 and above.

Would you prefer to see:

if( mysql <= 5.5 )
{
AsWKB
}
else
{
ST_AsWKB
}

I will modify the PR how ever you see fit.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, that if( mysql <= 5.5 ) is much better option.

Could you modify the P.R. a little bit?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, will do.

) {
$strRetVal .= 'HEX(AsWKB(`' . $arrColumn['Field'] . '`)),';
} else {
$strRetVal .= 'HEX(ST_AsWKB(`' . $arrColumn['Field'] . '`)),';
}
} elseif (
stripos($arrColumn['Type'], 'blob') !== false
|| stripos($arrColumn['Type'], 'binary') !== false
Expand Down Expand Up @@ -1527,6 +1565,9 @@ public function migrate()
PHP_EOL
);

$this->retrieveMySqlVersion();
$this->log('-- Discovered MySQL Version "' . $this->mysqlVersion . '"' . PHP_EOL);

ini_set('memory_limit', '-1');

/*
Expand Down