cleishm / libneo4j-client

neo4j-client -- Neo4j Command Line Interface (CLI)
https://neo4j-client.net
Apache License 2.0
156 stars 36 forks source link

How to get string result from neo4j_value_t? #30

Closed andr1972 closed 6 years ago

andr1972 commented 6 years ago

I have query: string queryStr = "match ...." "return rel.amount as amount, a.btc_address as address"; This query returns int64 and string vector results = neo4j->runQueryTransactions(queryStr, 2); where runQueryTransactions is my method calling neo4j_result_field First value (amount) i can simply obtain by results[0]._vdata._int But how to get address to string or char* ?

cleishm commented 6 years ago

Hey @borneq!

Avoid directly accessing _vdata_, as this is an implementation-dependent storage field. neo4j_value_t is an opaque type, and various methods are provided for converting or exposing its contents to platform types like int, and const char *. These are all documented in the API docs, http://neo4j-client.net/doc/latest/neo4j-client_8h.html.

E.g.

For an int value, use neo4j_int_value(value), which returns a long long. For a string value, use neo4j_string_length(value) to get the length, and neo4j_ustring_value(value) to get the const char * pointer to the string content. Or use neo4j_string_value(value, buf, bufsize) to copy it to a buffer and ensure it is properly null terminated.

Similar functions exist for all the other types that are supported by the bolt protocol.

Cheers, Chris