-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
[NFR]: Support POINT column type in MySQL #14769
Comments
I was able to reproduce this locally. |
The |
What would your expected outcome will look like @jesugmz ?
|
It makes sense, POINT type is binary and works in that way so more than fine @ruudboon! But still exists the issue when updating. Seems adding Note I have added a new field name: DROP DATABASE test;
CREATE DATABASE test DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
USE test;
CREATE TABLE items (
id MEDIUMINT(3) UNSIGNED NOT NULL AUTO_INCREMENT,
name VARCHAR(50),
location POINT NOT NULL,
PRIMARY KEY (id),
SPATIAL INDEX (location)
) ENGINE=InnoDB DEFAULT CHARSET=utf8; <?php
use Phalcon\Db\Adapter\Pdo\Mysql;
use Phalcon\Db\RawValue;
use Phalcon\Di\FactoryDefault;
use Phalcon\Http\Response;
use Phalcon\Mvc\Micro;
use Phalcon\Mvc\Model;
class Items extends Model
{
/**
* @var integer
* @Primary
* @Identity
* @Column(type="integer", length=3, nullable=false)
*/
public $id;
/**
* @var string
* @Column(type="string", length=50, nullable=true)
*/
public $name;
/**
* @var string
* @Column(type="string", length=60, nullable=false)
*/
public $location;
public function initialize()
{
$this->setSchema('test');
$this->setSource('items');
$this->useDynamicUpdate(true);
}
}
$di = new FactoryDefault();
$di->setShared('db', function () {
return new Mysql([
'host' => 'my-host',
'username' => 'root',
'password' => 'root',
'dbname' => 'test',
'charset' => 'utf8',
]);
});
$app = new Micro($di);
$app->get('/items/{id:[\d]}', function ($id) use ($app) {
$item = Items::findFirst('id = '.$id);
$coordinates = unpack('x/x/x/x/corder/Ltype/dlat/dlon', $item->location);
return $this->response->setJsonContent($coordinates);
});
$app->post('/items', function () use ($app) {
$item = new Items();
$item->location = new RawValue('ST_GeomFromText("POINT(1.0 1.0)")');
$created = $item->save();
return $created ? $this->response->setStatusCode(201) : $this->response->setStatusCode(500);
});
$app->put('/items/{id:[\d]}', function ($id) use ($app) {
$item = Items::findFirst('id = '.$id);
$item->name = 'test';
$updated = $item->update();
// will return 500 as seems to be doing internally $item->location = $item->location
return $updated ? $this->response->setStatusCode(200) : $this->response->setStatusCode(500);
});
$app->notFound(function() {
$response = new Response();
return $response->setStatusCode(404);
});
$app->handle($_SERVER["REQUEST_URI"]); but doing this, works: $app->put('/items/{id:[\d]}', function ($id) use ($app) {
$item = Items::findFirst('id = '.$id);
$item->location = new RawValue($item->location);
$item->name = 'test';
$updated = $item->update();
return $updated ? $this->response->setStatusCode(200) : $this->response->setStatusCode(500);
}); The problem with this is I have to do the POINT update manually even when I want just to update another field. As a patch works for me so far. |
I'm gonna file this one as a NFR. The type column isn't in our known DB columns yet. Also need to check if the |
Apologizes for the mess guys. Just have tested again the case and works fine in 4.0.2 so even I let the issue open in case you want to keep going with POINT type support. Thanks! |
@jesugmz Thanks for reporting this. As Ruud pointed out we pretty much never supported There have been a lot of types added for v4 in our ORM but clearly we have not caught everything - especially taking into account the differences in RDBMs syntax. I can keep this as a NFR but I propose we close it because we are working/will release a brand new ORM which will be more flexible for pretty much every RDBMS we support. That will solve this and related issues. |
@ruudboon Perfectly fine with that. |
Closing this in favour of #14608 (comment) |
Describe the bug
Having a MySQL column with type POINT the reading of its value is not well retrieved.
To Reproduce
Phalcon Micro application:
Database schema:
POST and PUT (writing a POINT column) operations will works but GET (reading a POINT column) will return a response like this:
In Phalcon 3.4.4 the reading works well but not the writing which cannot modify the POINT column.
Details
The text was updated successfully, but these errors were encountered: