在 C++ 中迭代 neo4j_client 中的结果
Iterate over results in neo4j_client for C++
我正在寻找有关 neo4j_client 在 C++ 中的用法的示例。在 test suite 中,我看到了 neo4j_result_t,但没有按名称迭代或调用字段的示例。这可能吗?
结果以 neo4j_result_stream_t
, which represents a stream of result rows. The number of the columns in the result is available via neo4j_nfields
, and their names via neo4j_fieldname
, both of which take the neo4j_result_stream_t
指针作为参数返回。
要遍历结果行,请使用 neo4j_fetch_next
which returns a neo4j_result_t
. And to extract values for each column from the row (the fields), pass the pointer to neo4j_result_field
(连同列的索引)。
一个例子是这样的:
neo4j_result_stream_t *results =
neo4j_run(session, "MATCH (n) RETURN n.name, n.age", neo4j_null);
if (results == NULL)
{
neo4j_perror(stderr, errno, "Failed to run statement");
return EXIT_FAILURE;
}
int ncolumns = neo4j_nfields(results);
if (ncolumns < 0)
{
neo4j_perror(stderr, errno, "Failed to retrieve results");
return EXIT_FAILURE;
}
neo4j_result_t *result;
while ((result = neo4j_fetch_next(results)) != NULL)
{
unsigned int i;
for (i = 0; i < ncolumns; ++i)
{
if (i > 0)
{
printf(", ");
}
neo4j_value_t value = neo4j_result_field(result, i);
neo4j_fprint(value, stdout);
}
printf("\n");
}
我正在寻找有关 neo4j_client 在 C++ 中的用法的示例。在 test suite 中,我看到了 neo4j_result_t,但没有按名称迭代或调用字段的示例。这可能吗?
结果以 neo4j_result_stream_t
, which represents a stream of result rows. The number of the columns in the result is available via neo4j_nfields
, and their names via neo4j_fieldname
, both of which take the neo4j_result_stream_t
指针作为参数返回。
要遍历结果行,请使用 neo4j_fetch_next
which returns a neo4j_result_t
. And to extract values for each column from the row (the fields), pass the pointer to neo4j_result_field
(连同列的索引)。
一个例子是这样的:
neo4j_result_stream_t *results =
neo4j_run(session, "MATCH (n) RETURN n.name, n.age", neo4j_null);
if (results == NULL)
{
neo4j_perror(stderr, errno, "Failed to run statement");
return EXIT_FAILURE;
}
int ncolumns = neo4j_nfields(results);
if (ncolumns < 0)
{
neo4j_perror(stderr, errno, "Failed to retrieve results");
return EXIT_FAILURE;
}
neo4j_result_t *result;
while ((result = neo4j_fetch_next(results)) != NULL)
{
unsigned int i;
for (i = 0; i < ncolumns; ++i)
{
if (i > 0)
{
printf(", ");
}
neo4j_value_t value = neo4j_result_field(result, i);
neo4j_fprint(value, stdout);
}
printf("\n");
}