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

Conversation

mores
Copy link

@mores mores commented Dec 16, 2016

MySQL 5.7: ST_AsBinary(), ST_AsWKB(), AsBinary(), and AsWKB() are synonyms.

MySQL 5.5: ST_AsWKB does not exist
5.5 supports AsBinary(g), AsWKB(g)


I am still unable to transfer my point(s) from MySQL to PostgreSql, but atleast this patch gets it closer to working.

Stephen More added 3 commits December 16, 2016 09:46
----
MySQL 5.7: ST_AsBinary(), ST_AsWKB(), AsBinary(), and AsWKB() are synonyms.

MySQL 5.5: ST_AsWKB does not exist
5.5 only supports  AsBinary(g), AsWKB(g)
@@ -164,7 +164,7 @@ private function __construct()

'point' => [
'increased_size' => '',
Copy link
Owner

Choose a reason for hiding this comment

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

Why?

While geometry is capable to hold point value, the
point simply restrict a value to a specific type...

Copy link
Author

Choose a reason for hiding this comment

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

Here is what I know: when I use this script, it fails on all of my point data types ( contain latitude and longitude). This change allows my data to import.

Here is what I have learned:
postgresql point storage size is only 16 byte
postgis geometry point storage size is 29 byte

Here is what I am guessing:
the postgresql point is simply an xy coordinate
the postgis geometry point is an xy coordinate plus Spatial Reference System attached to it.

As this post points out - you can not convert from one to the other.
http://dba.stackexchange.com/questions/156947/how-do-i-go-from-a-postgresql-native-point-type-to-a-postgis-point/156948

I don't claim to be a PostgreSQL expert. If there is another way to make this import work I would like to know. I can provide a MySQL test case if that would help.

Copy link
Owner

Choose a reason for hiding this comment

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

The test-case would be appreciated...
Thanks!

Copy link
Author

Choose a reason for hiding this comment

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

MySQL test case:

create table testGeoPoint (
ID bigint(20) NOT NULL,
GEOPOINT point DEFAULT NULL,
LATITUDE decimal(19,10) DEFAULT NULL,
LONGITUDE decimal(19,10) DEFAULT NULL
) ENGINE=InnoDB;

insert into testGeoPoint values ( 1, GeomFromText('POINT(-74.0445000000 40.6892000000 )' ), 40.6892000000, -74.0445000000 );

Copy link
Author

Choose a reason for hiding this comment

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

Error output I see is:
--Following MySQL query will return a data set, rejected by PostgreSQL:
SELECT ID,HEX(AsWKB(GEOPOINT)),LATITUDE,LONGITUDE FROM testGeoPoint LIMIT 0, 1;

    -- FromMySqlToPostgreSql::populateTableWorker

    -- PDOException code: 22P02
    -- File: /home/mores/wip/MySQL2PSQL/php/migration/FromMySqlToPostgreSql/FromMySqlToPostgreSql.php
    -- Line: 674
    -- Message: SQLSTATE[22P02]: Invalid text representation: 7 ERROR:  invalid input syntax for type point: "0101000000022B8716D98252C09C33A2B437584440"

CONTEXT: COPY testGeoPoint, line 1, column GEOPOINT: "0101000000022B8716D98252C09C33A2B437584440"
-- SQL: SELECT ID,HEX(AsWKB(GEOPOINT)),LATITUDE,LONGITUDE FROM testGeoPoint LIMIT 0, 1;
COPY "test"."testGeoPoint" FROM '/home/mores/wip/MySQL2PSQL/php/temporary_directory/testGeoPoint0.csv' DELIMITER ',' CSV;

    -------------------------------------------------------

@@ -712,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.

@AnatolyUss
Copy link
Owner

Great idea!
Thanks a lot for the P.R.!

@mr-russ
Copy link
Contributor

mr-russ commented Apr 29, 2017

Is there agreement to merge this pull request now?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants