summaryrefslogtreecommitdiff
path: root/docs/reference/libtracker-sparql/examples/writeonly-example.c
blob: 94104c3d78123976831e21af5a1b03f0436f46f5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <libtracker-sparql/tracker-sparql.h>

int main (int argc, const char **argv)
{
  GError *error = NULL;
  TrackerSparqlConnection *connection;
  const gchar *query =
    "INSERT { "
    "  _:tag a nao:Tag ; "
    "        nao:prefLabel 'mylabel' . "
    "} WHERE { "
    "  OPTIONAL { "
    "    ?tag a nao:Tag ; "
    "    nao:prefLabel 'mylabel' "
    "  } . "
    "FILTER (!bound(?tag)) "
    "}";

  connection = tracker_sparql_connection_bus_new ("org.freedesktop.Tracker3.Miner.Files", NULL, NULL, &error);
  if (!error) {
    g_printerr ("Couldn't obtain a connection to the Tracker store: %s",
                error->message);
    g_clear_error (&error);

    return 1;
  }

  /* Run a synchronous update query */
  tracker_sparql_connection_update (connection,
                                    query,
                                    NULL,
                                    &error);
  if (error) {
    /* Some error happened performing the query, not good */
    g_printerr ("Couldn't update the Tracker store: %s",
                error->message);

    g_clear_error (&error);
    g_object_unref (connection);

    return 1;
  }

  g_object_unref (connection);

  return 0;
}