I am doing some PostGIS work on a CakePHP application.
Because I've been working with some database functions, I've done raw $this->query()
calls to do inserts of data. I'm at a point where I need to get the ID of the result of an insert query, but $this->query()
returns an empty array.
Here is the query I'm using for inserts:
INSERT INTO locations (title,company_id,state_id,poly,point)
VALUES ('$title',$company_id,$state_id,ST_GeomFromText('$geom',4269),$point);
The problem is Cake is trying to insert 'ST_GeomFromText('$geom',4269)'
as a string, and I cannot figure out how to get it to remove the quotes in the SQL insert statement it prepares via $this->Location->save();
.
Any suggestions?
Edit:
Before I was doing $this->query();
and my SQL works fine. That's not the issue.
Now when I do:
$this->Location->create();
$this->Location->set('poly',$poly);
... Set all the rest of the model fields ...
$this->Location->save();
The SQL that gets produced looks like this:
INSERT INTO locations (title,company_id,state_id,poly,point)
VALUES ('Some Title',5,23,'ST_GeomFromText('$geom',4269)',POINT(-72.342,102.23455);
Because ST_GeomFromText gets 'quoted', PostgreSQL throws an error and doesn't insert the geometry.