0

How can I send a statement with an integer type in neo4j-client? Fore example, in CREATE (n:Node {id:1}) the value of the field id is 1. Also, how can I retrieve it?

I have tried, assuming:

std::stringstream ss;
neo4j_run(connection,
            ss.str().c_str(), neo4j_null);

--

ss << "RETURN 'hello world'"; // server returns 'hello world'
ss << "RETURN 1"; // server returns 1
ss << "CREATE (n:Node {id:" << std::to_string(2) << "}); // Statement failed
ss << "CREATE (n:Node {id:" << neo4j_int(2) << "})"; // compile error

I am also printing those strings in the console, and CREATE (n:Node {id:" << std::to_string(2) << "}) copy-pasted fro the consolo to the web gui works.

Gabor Szarnyas
  • 4,410
  • 3
  • 18
  • 42
vicaba
  • 2,836
  • 1
  • 27
  • 45
  • 1
    What have you tried so far? The [docs](https://neo4j-client.net/) show this line for running a query: `neo4j_result_stream_t *results = neo4j_run(connection, "RETURN 'hello world'", neo4j_null);` -- what happens if you run your query this way? – Gabor Szarnyas Nov 21 '17 at 13:17
  • @GaborSzarnyas I have added what I have tried. – vicaba Nov 21 '17 at 13:25
  • My C++ is a little rusty, but I'm pretty sure you do not concatenate strings with the `<<` operator, which only works for output streams. Try something along the lines of https://stackoverflow.com/questions/6061648/concatenate-two-string-literals. – Gabor Szarnyas Nov 21 '17 at 14:53

1 Answers1

0

You're probably best sending the integer ID as a parameter, e.g.:

neo4j_map_entry_t map_entry = neo4j_map_entry("id", 2);
neo4j_value_t params = neo4j_map(&map_entry, 1);
neo4j_run(session, "CREATE (n:Node {id:$id});", params);
Chris Leishman
  • 1,777
  • 13
  • 19