diff options
Diffstat (limited to 'docs/reference/libtracker-sparql/examples/readonly-example.c')
-rw-r--r-- | docs/reference/libtracker-sparql/examples/readonly-example.c | 43 |
1 files changed, 40 insertions, 3 deletions
diff --git a/docs/reference/libtracker-sparql/examples/readonly-example.c b/docs/reference/libtracker-sparql/examples/readonly-example.c index 3759e5299..2aafd7e0d 100644 --- a/docs/reference/libtracker-sparql/examples/readonly-example.c +++ b/docs/reference/libtracker-sparql/examples/readonly-example.c @@ -5,6 +5,7 @@ int main (int argc, const char **argv) GError *error = NULL; TrackerSparqlConnection *connection; TrackerSparqlCursor *cursor; + TrackerSparqlStatement *stmt; const gchar *query = "SELECT nie:url(?u) WHERE { ?u a nfo:FileDataObject }"; connection = tracker_sparql_connection_bus_new ("org.freedesktop.Tracker3.Miner.Files", NULL, NULL, &error); @@ -18,9 +19,9 @@ int main (int argc, const char **argv) /* Make a synchronous query to the store */ cursor = tracker_sparql_connection_query (connection, - query, - NULL, - &error); + query, + NULL, + &error); if (error) { /* Some error happened performing the query, not good */ @@ -49,6 +50,42 @@ int main (int argc, const char **argv) g_object_unref (cursor); } + /* Prepare the statement with tracker_sparql_connection_query_statement */ + stmt = tracker_sparql_connection_query_statement (connection, + query, + NULL, + &error); + + if (error) { + /* Some error happened performing the query, not good */ + g_printerr ("Couldn't query the Tracker Store: '%s'", + error->message); + g_clear_error (&error); + + return 1; + } + + /* Executes the SPARQL query with the currently bound values and get new cursor */ + cursor = tracker_sparql_statement_execute (stmt, NULL, &error); + + /* Check results... */ + if (!cursor) { + g_print ("No results found :-/\n"); + } else { + gint i = 0; + + /* Iterate, synchronously, the results... */ + while (tracker_sparql_cursor_next (cursor, NULL, &error)) { + g_print ("Result [%d]: %s\n", + i++, + tracker_sparql_cursor_get_string (cursor, 0, NULL)); + } + + g_print ("A total of '%d' results were found\n", i); + + g_object_unref (cursor); + } + g_object_unref (connection); return 0; |