Ostico / PhpOrient

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

Attributes of type double loaded as strings #34

Closed andreyvk closed 9 years ago

andreyvk commented 9 years ago

Hi,

Looks like there's an issue with loading fields of type double (havent tested floats yet). Im on the latest PhpOrient using OrientDB 2.0.12.

Here's the schema + test record:

create class Test extends V

create property Test.attr1 string
alter property Test.attr1 mandatory true

create property Test.attr2 double
alter property Test.attr2 mandatory true

insert into Test set attr1="foo bar", attr2=0

Getting data and printing out attr2 shows that it's a string:

$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( '#83:0' ) )[0];
var_dump($record["attr2"]);

Prints the following to the console:

string(3) "0.0"
Ostico commented 9 years ago

Hi @andreyvk ,

you're right, by design in PhpOrient the numbers are always treated as strings because of the platform dependant nature of PHP.

In 32bit platform the integers must be treated as string because the numbers greater than 2147483647 would be lost and the BCMath/GMP modules must be used to obtain the right numbers.

I taken a decision, to make the results of the same type for all platforms ( 32 and 64bit ) and leave to the user/developer the decision on how to use it's own data ( by manual cast ) i used string for all primitive data types.

andreyvk commented 9 years ago

Hi @Ostico, thanks for clearing this out. Maybe it's good to add this note to the documentation somewhere after the https://github.com/Ostico/PhpOrient#phporient-works-even-on-32bit-and-64bit-platforms section. What do you think?

Ostico commented 9 years ago

Yes, i will do today or tomorrow i think in the next release

andreyvk commented 9 years ago

:+1: