Adds support for geometry fields in SQL mappers#361
Adds support for geometry fields in SQL mappers#361Lawrence72 wants to merge 1 commit intof3-factory:masterfrom
Conversation
|
@Lawrence72 How is the field type |
|
@ikkez In the mapper class, as part of the construct it grabs the table schema, and part of that is the field types (F3 Mapper already does this), this is all stored in the $this->fields array. So I am checking the info stored in there to see if the field is set to type geometry and behaving a little differently if it is. Its not a user set variable or anything the user can alter in their mapper call. |
|
Hi again.. sorry for the delay. Does this work for all sql engines or have you only tried MySQL/MariaDB ? |
|
Ive only tested it on MYSQL/Maria. Here is a gist of the test I ran to work out what the issue was: The SQL queries work fine, the select from a mapper works as long as its added as a virtual field The insert does not work. What I found was that the mapper didnt handle SQL functions in the mapper field value which is required in order to add a geo spacial. ( ST_GeomFromText('POINT(4 4)') ) So the solution I was trying to do was to take out the need for the ST_GeomFromText by detecting that the field was of type geometry and wrap it in a ST_GeomFromText($value) so the mapper could be set to $mapper->field = 'POINT(4 4)' and have it insert correctly. The alternative that I can think of for this would be a more general fix where the mapper allows SQL functions in the mapper field value. Though when I was looking at it I thought that might cause problems. Another idea I had was to allow something similar to virtual fields in an insert. That would make it so SQL functions could be added but under more controlled conditions than trying to detect when the value includes a SQL function and when it doesn't. I hope this makes sense, on what I was trying to do with it. |
|
the function to call depends on the dbms. For SQL Server it's like |
Currently its not possible to insert/update geometry fields with a SQL mapper.
This adds support for this
How to use:
This also works with other geometry types:
$this->User_Mapper->position = 'LINESTRING(2 1, 6 6)';$this->User_Mapper->position = 'POLYGON((0 5, 2 5, 2 7, 0 7, 0 5))';Retrieving geometry information can be done using a virtual field