Skip Menu |

This queue is for tickets about the REST-Neo4p CPAN distribution.

Report information
The Basics
Id: 92057
Status: resolved
Priority: 0/
Queue: REST-Neo4p

People
Owner: maj.fortinbras [...] gmail.com
Requestors: stesin [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 0.2233
Fixed in: (no value)



Subject: Scalar/string context in p
Dear Mark, I'm not sure is it a bug or maybe feature, this is what I discovered just today. Suppose I create a query with parameters, where attributes are supposed to be just integers. Like $some_qry = "MATCH (n) WHERE n.payload <= {my_val} RETURN id(n)"; I "compile" (or "prepare") it than, like $qry_some = REST::Neo4p::Query->new( $some_qry ); and execute it: $my_int = ...some int value... ; $numrows = $qry_some->execute( my_val => $my_int ); What I discovered. As soon as $my_int <= 0 (my "some int value" is negative, like -1234) query works fine. But as soon as $my_in >= 0 (like 5678) I got an error, smth like "cannot compare n.payload (Long) with 5678 (String)". Adding explicit type (context?) conversion, like: $numrows = $qry_some->execute( my_val => int( $my_int ) ); helps, query works as expected. I'm just in doubt - either this is a feature out of my knowlege, or this is a bug with unwanted context switch to string while $my_int is actually integer? What do you think on it? Thanks in advance! WBR, Andrii
Hi Andrii-- I think it's tricky. Perl sort of types, but Java (neo4j server) strongly types. The JSON module has to pick whether to send { "thing" : 5678 } or { "thing" : "5678" } and the server probably takes the JSON at its word. JSON probably picks { "thing" : -5678 } when it sees the -, so all is well there. Is that a bug? Could be. I will see if my conjecture is correct and let you know. MAJ On Sat Jan 11 16:56:11 2014, stesin@gmail.com wrote: Show quoted text
> Dear Mark, > > I'm not sure is it a bug or maybe feature, this is what I discovered > just today. > > Suppose I create a query with parameters, where attributes are > supposed to be just integers. Like > > $some_qry = "MATCH (n) WHERE n.payload <= {my_val} RETURN id(n)"; > > I "compile" (or "prepare") it than, like > > $qry_some = REST::Neo4p::Query->new( $some_qry ); > > and execute it: > > $my_int = ...some int value... ; > $numrows = $qry_some->execute( my_val => $my_int ); > > What I discovered. As soon as $my_int <= 0 (my "some int value" is > negative, like -1234) query works fine. But as soon as $my_in >= 0 > (like 5678) I got an error, smth like "cannot compare n.payload (Long) > with 5678 (String)". > > Adding explicit type (context?) conversion, like: > $numrows = $qry_some->execute( my_val => int( $my_int ) ); > > helps, query works as expected. I'm just in doubt - either this is a > feature out of my knowlege, or this is a bug with unwanted context > switch to string while $my_int is actually integer? > > What do you think on it? > > Thanks in advance! > WBR, > Andrii
Andrii, If you look here https://metacpan.org/pod/JSON#PERL---JSON, there is some information on how JSON determines how to write simple scalars. I think you are right, the last context in which the scalar was used determines the json: the following (on my machine Ubuntu 12.04/perl 5.14) use JSON; my $j = JSON->new(); my $my_int = 5678; print $j->encode( { thing => $my_int } ),"\n"; $my_int.=""; print $j->encode( { thing => $my_int } ),"\n"; print $j->encode( { thing => 0+$my_int } ),"\n"; outputs {"thing":5678} {"thing":"5678"} {"thing":5678} So maybe it's a feature. What do you think? MAJ On Sat Jan 18 20:35:19 2014, MAJENSEN wrote: Show quoted text
> Hi Andrii-- I think it's tricky. Perl sort of types, but Java (neo4j > server) strongly types. The JSON module has to pick whether to send > { "thing" : 5678 } > or > { "thing" : "5678" } > and the server probably takes the JSON at its word. > > JSON probably picks > { "thing" : -5678 } > when it sees the -, so all is well there. Is that a bug? Could be. I > will see if my conjecture is correct and let you know. > MAJ > On Sat Jan 11 16:56:11 2014, stesin@gmail.com wrote:
> > Dear Mark, > > > > I'm not sure is it a bug or maybe feature, this is what I discovered > > just today. > > > > Suppose I create a query with parameters, where attributes are > > supposed to be just integers. Like > > > > $some_qry = "MATCH (n) WHERE n.payload <= {my_val} RETURN id(n)"; > > > > I "compile" (or "prepare") it than, like > > > > $qry_some = REST::Neo4p::Query->new( $some_qry ); > > > > and execute it: > > > > $my_int = ...some int value... ; > > $numrows = $qry_some->execute( my_val => $my_int ); > > > > What I discovered. As soon as $my_int <= 0 (my "some int value" is > > negative, like -1234) query works fine. But as soon as $my_in >= 0 > > (like 5678) I got an error, smth like "cannot compare n.payload > > (Long) > > with 5678 (String)". > > > > Adding explicit type (context?) conversion, like: > > $numrows = $qry_some->execute( my_val => int( $my_int ) ); > > > > helps, query works as expected. I'm just in doubt - either this is a > > feature out of my knowlege, or this is a bug with unwanted context > > switch to string while $my_int is actually integer? > > > > What do you think on it? > > > > Thanks in advance! > > WBR, > > Andrii
Calling this resolved, basically because of how Perl typing works (see previous comment); use 0+ to insure that the last context of a scalar is numeric before assigning the property value. MAJ