Closed shiftyp closed 8 years ago
I'm also getting the same error when running a multi-row query when more than one row is returned.
Thanks for the report!
So I was able to reproduce the bug in the tests by removing the integer property from the node in TestQueryNode
. The issue occurs when the node has only string properties, where the properties end up as a map[string]string
instead of a map[string]CypherValue
.
It's sort of a tricky issue since you can't really change the way the CypherValue
unmarshalls. I was able to implement a fix in the node's Scan
function by trying to convert the properties to a map[string]CypherValue
, and if that fails convert it to a map[string]string
and create the map of CypherValue
's manually. Like so:
properties, ok := inner.Val.(map[string]CypherValue)
if ok {
n.Properties = properties
} else {
n.Properties = map[string]CypherValue{}
properties := inner.Val.(map[string]string)
for k, v := range properties {
n.Properties[k] = CypherValue{CypherString, v}
}
}
If that sounds like a good solution to you I can put in a pr for your review.
Yeah, PR is great. I started doing this last night but fell asleep on the sofa. :P
The good news is the typed-ness of bolt is going to solve a lot of this in v2.
I don't often return nodes/rels as full entities, usually pull data into structs in go so I list out the fields. Wasn't sufficient testing for nodes/rels. (I imagine rels have the same problem.)
I'll check out the rels then as well and include a fix in the PR if they have the same issue.
For my application I'm returning the nodes and creating structs that can populate themselves from Node
s. Some of the nodes have arbitrary properties, so I can't easily list out all of them individually in the query.
Merged PR.
I have a query that returns three nodes as values in a single row, and in scanning the nodes I get this error:
The query looks a bit like this
It returns a single row, but when I run it as a single row query I get the above error when scanning the nodes. So something like this:
If I execute the statement as a multi row query and scan the first row I don't get the error.