Ostico / PhpOrient

PhpOrient - Official Php driver based on the binary protocol of OrientDB.
Other
68 stars 37 forks source link

Saving date field loses date data #29

Closed andreyvk closed 9 years ago

andreyvk commented 9 years ago

Hi,

I think there's a problem saving date/datetime fields, while updating records. Looks like problem is with converting DateTime object into date data, when saving a record. Im on the latest PhpOrient using OrientDB 2.0.10.

Here's the schema + test record:

create class Test extends V

create property Test.date date

insert into Test set date = "2015-01-01"

In the console:

orientdb {db=test}> select from Test

----+-----+------+-------------------
#   |@RID |@CLASS|date
----+-----+------+-------------------
0   |#43:0|Test  |2015-01-01 00:00:00
----+-----+------+-------------------

Executing the following saves wrong date data:

$client = new \PhpOrient\PhpOrient( 'localhost', 2424 );
$client->username = 'user';
$client->password = 'pass';
$client->connect();
$client->dbOpen( 'test', 'user', 'pass' );
$record = $client->recordLoad( new \PhpOrient\Protocols\Binary\Data\ID( '#43:0' ) )[0];
$updatedRecord = $client->recordUpdate( $record );

Select again (see date data lost):

orientdb {db=test}> select from Test

----+-----+------+-------------------
#   |@RID |@CLASS|date
----+-----+------+-------------------
0   |#43:0|Test  |1970-01-17 00:00:00
----+-----+------+-------------------
Ostico commented 9 years ago

Thenk you @andreyvk , i will investigate

andreyvk commented 9 years ago

I'm happy I could help really. And thanks for great job on this library :)

pjmazenot commented 9 years ago

Hi, I had the same problem with DateTimes and fixed it (for now), by replacing this line:

return $value->getTimestamp() . 't';

by this one:

return $value->getTimestamp() . '000t';

(vendor/ostico/phporient/src/PhpOrient/Protocols/Binary/Serialization/CSV.php:530)

In my understanding we get this bug because the 'getTimestamp()' method does not return the milliseconds.

Hope that helps!

Ostico commented 9 years ago

Hi @pjmazenot ,

the patch you suggested is good. I'm updating.

pjmazenot commented 9 years ago

Glad I could help. Thanks @Ostico for this library, I just started using OrientDB and it saved me a lot of time!

andreyvk commented 9 years ago

Thanks @pjmazenot! Looking forward for an official patch