Coverage Report

Created: 2025-08-28 06:47

/src/tinysparql/src/libtinysparql/tracker-statement.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (C) 2018, Red Hat Ltd.
3
 *
4
 * This library is free software; you can redistribute it and/or
5
 * modify it under the terms of the GNU Lesser General Public
6
 * License as published by the Free Software Foundation; either
7
 * version 2.1 of the License, or (at your option) any later version.
8
 *
9
 * This library is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
 * Lesser General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU Lesser General Public
15
 * License along with this library; if not, write to the
16
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17
 * Boston, MA  02110-1301, USA.
18
 */
19
/**
20
 * TrackerSparqlStatement:
21
 *
22
 * `TrackerSparqlStatement` represents a prepared statement for a SPARQL query.
23
 *
24
 * The SPARQL query will be internally compiled into the format that is most
25
 * optimal to execute the query many times. For connections created
26
 * through [ctor@SparqlConnection.new] that will be a
27
 * SQLite compiled statement.
28
 *
29
 * The SPARQL query may contain parameterized variables expressed via the
30
 * `~` prefix in the SPARQL syntax (e.g. `~var`), these may happen anywhere
31
 * in the SPARQL where a literal or variable would typically happen. These
32
 * parameterized variables may be mapped to arbitrary values prior to
33
 * execution. The `TrackerSparqlStatement` may be reused for future
34
 * queries with different values.
35
 *
36
 * The argument bindings may be changed through the [method@SparqlStatement.bind_int],
37
 * [method@SparqlStatement.bind_int], etc... family of functions. Those functions
38
 * receive a @name argument corresponding for the variable name in the SPARQL query
39
 * (eg. `"var"` for `~var`) and a value to map the variable to.
40
 *
41
 * Once all arguments have a value, the query may be executed through
42
 * [method@SparqlStatement.execute_async] or [method@SparqlStatement.execute].
43
 *
44
 * It is possible to use any `TrackerSparqlStatement` from other threads than
45
 * the one it was created from. However, binding values and executing the
46
 * statement must only happen from one thread at a time. It is possible to reuse
47
 * the `TrackerSparqlStatement` right after [method@SparqlStatement.execute_async]
48
 * was called, there is no need to wait for [method@SparqlStatement.execute_finish].
49
 *
50
 * In some circumstances, it is possible that the query needs to be recompiled
51
 * from the SPARQL source. This will happen transparently.
52
 */
53
#include "config.h"
54
55
#include "tracker-statement.h"
56
#include "tracker-private.h"
57
58
enum {
59
  PROP_0,
60
  PROP_CONNECTION,
61
  PROP_SPARQL,
62
  N_PROPS
63
};
64
65
static GParamSpec *props[N_PROPS];
66
67
typedef struct {
68
  TrackerSparqlConnection *connection;
69
  gchar *sparql;
70
} TrackerSparqlStatementPrivate;
71
72
G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (TrackerSparqlStatement,
73
                                     tracker_sparql_statement,
74
                                     G_TYPE_OBJECT)
75
76
static void
77
tracker_sparql_statement_init (TrackerSparqlStatement *stmt)
78
0
{
79
0
}
80
81
static void
82
tracker_sparql_statement_finalize (GObject *object)
83
0
{
84
0
  TrackerSparqlStatement *stmt = TRACKER_SPARQL_STATEMENT (object);
85
0
  TrackerSparqlStatementPrivate *priv = tracker_sparql_statement_get_instance_private (stmt);
86
87
0
  g_clear_object (&priv->connection);
88
0
  g_free (priv->sparql);
89
0
  G_OBJECT_CLASS (tracker_sparql_statement_parent_class)->finalize (object);
90
0
}
91
92
static void
93
tracker_sparql_statement_set_property (GObject      *object,
94
                                       guint         prop_id,
95
                                       const GValue *value,
96
                                       GParamSpec   *pspec)
97
0
{
98
0
  TrackerSparqlStatement *stmt = TRACKER_SPARQL_STATEMENT (object);
99
0
  TrackerSparqlStatementPrivate *priv = tracker_sparql_statement_get_instance_private (stmt);
100
101
0
  switch (prop_id) {
102
0
  case PROP_CONNECTION:
103
0
    priv->connection = g_value_dup_object (value);
104
0
    break;
105
0
  case PROP_SPARQL:
106
0
    priv->sparql = g_value_dup_string (value);
107
0
    break;
108
0
  default:
109
0
    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
110
0
  }
111
0
}
112
113
static void
114
tracker_sparql_statement_get_property (GObject    *object,
115
                                       guint       prop_id,
116
                                       GValue     *value,
117
                                       GParamSpec *pspec)
118
0
{
119
0
  TrackerSparqlStatement *stmt = TRACKER_SPARQL_STATEMENT (object);
120
0
  TrackerSparqlStatementPrivate *priv = tracker_sparql_statement_get_instance_private (stmt);
121
122
0
  switch (prop_id) {
123
0
  case PROP_CONNECTION:
124
0
    g_value_set_object (value, priv->connection);
125
0
    break;
126
0
  case PROP_SPARQL:
127
0
    g_value_set_string (value, priv->sparql);
128
0
    break;
129
0
  default:
130
0
    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
131
0
  }
132
0
}
133
134
static void
135
tracker_sparql_statement_class_init (TrackerSparqlStatementClass *klass)
136
0
{
137
0
  GObjectClass *object_class = G_OBJECT_CLASS (klass);
138
139
0
  object_class->finalize = tracker_sparql_statement_finalize;
140
0
  object_class->set_property = tracker_sparql_statement_set_property;
141
0
  object_class->get_property = tracker_sparql_statement_get_property;
142
143
  /**
144
   * TrackerSparqlStatement:connection:
145
   *
146
   * The [class@SparqlConnection] the statement was created for.
147
   */
148
0
  props[PROP_CONNECTION] =
149
0
    g_param_spec_object ("connection",
150
0
                         "connection",
151
0
                         "connection",
152
0
                         TRACKER_TYPE_SPARQL_CONNECTION,
153
0
             G_PARAM_CONSTRUCT_ONLY |
154
0
                         G_PARAM_STATIC_STRINGS |
155
0
                         G_PARAM_READABLE |
156
0
                         G_PARAM_WRITABLE);
157
  /**
158
   * TrackerSparqlStatement:sparql:
159
   *
160
   * SPARQL query stored in this statement.
161
   */
162
0
  props[PROP_SPARQL] =
163
0
    g_param_spec_string ("sparql",
164
0
                         "sparql",
165
0
                         "sparql",
166
0
                         NULL,
167
0
             G_PARAM_CONSTRUCT_ONLY |
168
0
                         G_PARAM_STATIC_STRINGS |
169
0
                         G_PARAM_READABLE |
170
0
             G_PARAM_WRITABLE);
171
172
0
  g_object_class_install_properties (object_class, N_PROPS, props);
173
0
}
174
175
/**
176
 * tracker_sparql_statement_get_connection:
177
 * @stmt: a `TrackerSparqlStatement`
178
 *
179
 * Returns the [class@SparqlConnection] that this statement was created for.
180
 *
181
 * Returns: (transfer none): The SPARQL connection of this statement.
182
 **/
183
TrackerSparqlConnection *
184
tracker_sparql_statement_get_connection (TrackerSparqlStatement *stmt)
185
0
{
186
0
  TrackerSparqlStatementPrivate *priv = tracker_sparql_statement_get_instance_private (stmt);
187
188
0
  g_return_val_if_fail (TRACKER_IS_SPARQL_STATEMENT (stmt), NULL);
189
190
0
  return priv->connection;
191
0
}
192
193
/**
194
 * tracker_sparql_statement_get_sparql:
195
 * @stmt: a `TrackerSparqlStatement`
196
 *
197
 * Returns the SPARQL string that this prepared statement holds.
198
 *
199
 * Returns: The contained SPARQL query
200
 **/
201
const gchar *
202
tracker_sparql_statement_get_sparql (TrackerSparqlStatement *stmt)
203
0
{
204
0
  TrackerSparqlStatementPrivate *priv = tracker_sparql_statement_get_instance_private (stmt);
205
206
0
  g_return_val_if_fail (TRACKER_IS_SPARQL_STATEMENT (stmt), NULL);
207
208
0
  return priv->sparql;
209
0
}
210
211
/**
212
 * tracker_sparql_statement_bind_boolean:
213
 * @stmt: a `TrackerSparqlStatement`
214
 * @name: variable name
215
 * @value: value
216
 *
217
 * Binds the boolean @value to the parameterized variable given by @name.
218
 */
219
void
220
tracker_sparql_statement_bind_boolean (TrackerSparqlStatement *stmt,
221
                                       const gchar            *name,
222
                                       gboolean                value)
223
0
{
224
0
  g_return_if_fail (TRACKER_IS_SPARQL_STATEMENT (stmt));
225
0
  g_return_if_fail (name != NULL);
226
227
0
  TRACKER_SPARQL_STATEMENT_GET_CLASS (stmt)->bind_boolean (stmt,
228
0
                                                           name,
229
0
                                                           value);
230
0
}
231
232
/**
233
 * tracker_sparql_statement_bind_int:
234
 * @stmt: a `TrackerSparqlStatement`
235
 * @name: variable name
236
 * @value: value
237
 *
238
 * Binds the integer @value to the parameterized variable given by @name.
239
 */
240
void
241
tracker_sparql_statement_bind_int (TrackerSparqlStatement *stmt,
242
                                   const gchar            *name,
243
                                   gint64                  value)
244
0
{
245
0
  g_return_if_fail (TRACKER_IS_SPARQL_STATEMENT (stmt));
246
0
  g_return_if_fail (name != NULL);
247
248
0
  TRACKER_SPARQL_STATEMENT_GET_CLASS (stmt)->bind_int (stmt,
249
0
                                                       name,
250
0
                                                       value);
251
0
}
252
253
/**
254
 * tracker_sparql_statement_bind_double:
255
 * @stmt: a `TrackerSparqlStatement`
256
 * @name: variable name
257
 * @value: value
258
 *
259
 * Binds the double @value to the parameterized variable given by @name.
260
 */
261
void
262
tracker_sparql_statement_bind_double (TrackerSparqlStatement *stmt,
263
                                      const gchar            *name,
264
                                      gdouble                 value)
265
0
{
266
0
  g_return_if_fail (TRACKER_IS_SPARQL_STATEMENT (stmt));
267
0
  g_return_if_fail (name != NULL);
268
269
0
  TRACKER_SPARQL_STATEMENT_GET_CLASS (stmt)->bind_double (stmt,
270
0
                                                          name,
271
0
                                                          value);
272
0
}
273
274
/**
275
 * tracker_sparql_statement_bind_string:
276
 * @stmt: a `TrackerSparqlStatement`
277
 * @name: variable name
278
 * @value: value
279
 *
280
 * Binds the string @value to the parameterized variable given by @name.
281
 */
282
void
283
tracker_sparql_statement_bind_string (TrackerSparqlStatement *stmt,
284
                                      const gchar            *name,
285
                                      const gchar            *value)
286
0
{
287
0
  g_return_if_fail (TRACKER_IS_SPARQL_STATEMENT (stmt));
288
0
  g_return_if_fail (name != NULL);
289
0
  g_return_if_fail (value != NULL);
290
291
0
  TRACKER_SPARQL_STATEMENT_GET_CLASS (stmt)->bind_string (stmt,
292
0
                                                          name,
293
0
                                                          value);
294
0
}
295
296
/**
297
 * tracker_sparql_statement_bind_datetime:
298
 * @stmt: a `TrackerSparqlStatement`
299
 * @name: variable name
300
 * @value: value
301
 *
302
 * Binds the [type@GLib.DateTime] @value to the parameterized variable given by @name.
303
 *
304
 * Since: 3.2
305
 */
306
307
void
308
tracker_sparql_statement_bind_datetime (TrackerSparqlStatement *stmt,
309
                                        const gchar            *name,
310
                                        GDateTime              *value)
311
0
{
312
0
  g_return_if_fail (TRACKER_IS_SPARQL_STATEMENT (stmt));
313
0
  g_return_if_fail (name != NULL);
314
0
  g_return_if_fail (value != NULL);
315
316
0
  TRACKER_SPARQL_STATEMENT_GET_CLASS (stmt)->bind_datetime (stmt,
317
0
                                                            name,
318
0
                                                            value);
319
0
}
320
321
/**
322
 * tracker_sparql_statement_bind_langstring:
323
 * @stmt: a `TrackerSparqlStatement`
324
 * @name: variable name
325
 * @value: value
326
 * @langtag: language tag
327
 *
328
 * Binds the @value to the parameterized variable given by @name, tagged
329
 * with the language defined by @langtag. The language tag should follow
330
 * [RFC 5646](https://www.rfc-editor.org/rfc/rfc5646.html). The parameter
331
 * will be represented as a [`rdf:langString`](rdf-ontology.html#rdf:langString).
332
 *
333
 * Since: 3.7
334
 **/
335
void
336
tracker_sparql_statement_bind_langstring (TrackerSparqlStatement *stmt,
337
                                          const gchar            *name,
338
                                          const gchar            *value,
339
                                          const gchar            *langtag)
340
0
{
341
0
  g_return_if_fail (TRACKER_IS_SPARQL_STATEMENT (stmt));
342
0
  g_return_if_fail (name != NULL);
343
0
  g_return_if_fail (value != NULL);
344
0
  g_return_if_fail (langtag != NULL);
345
346
0
  TRACKER_SPARQL_STATEMENT_GET_CLASS (stmt)->bind_langstring (stmt,
347
0
                                                              name,
348
0
                                                              value,
349
0
                                                              langtag);
350
0
}
351
352
/**
353
 * tracker_sparql_statement_execute:
354
 * @stmt: a `TrackerSparqlStatement`
355
 * @cancellable: (nullable): Optional [type@Gio.Cancellable]
356
 * @error: Error location
357
 *
358
 * Executes the `SELECT` or `ASK` SPARQL query with the currently bound values.
359
 *
360
 * This function also works for `DESCRIBE` and `CONSTRUCT` queries that
361
 * retrieve data from the triple store. These query forms that return
362
 * RDF data are however more useful together with [method@SparqlStatement.serialize_async].
363
 *
364
 * This function should only be called on `TrackerSparqlStatement` objects
365
 * obtained through [method@SparqlConnection.query_statement] or
366
 * SELECT/CONSTRUCT/DESCRIBE statements loaded through
367
 * [method@SparqlConnection.load_statement_from_gresource].
368
 * An error will be raised if this method is called on a `INSERT` or `DELETE`
369
 * SPARQL query.
370
 *
371
 * Returns: (transfer full): A `TrackerSparqlCursor` with the query results.
372
 */
373
TrackerSparqlCursor *
374
tracker_sparql_statement_execute (TrackerSparqlStatement  *stmt,
375
                                  GCancellable            *cancellable,
376
                                  GError                 **error)
377
0
{
378
0
  TrackerSparqlStatementPrivate *priv =
379
0
    tracker_sparql_statement_get_instance_private (stmt);
380
0
  TrackerSparqlCursor *cursor;
381
382
0
  g_return_val_if_fail (TRACKER_IS_SPARQL_STATEMENT (stmt), NULL);
383
0
  g_return_val_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable), NULL);
384
0
  g_return_val_if_fail (!error || !*error, NULL);
385
386
0
  cursor = TRACKER_SPARQL_STATEMENT_GET_CLASS (stmt)->execute (stmt,
387
0
                                                               cancellable,
388
0
                                                               error);
389
0
  if (cursor)
390
0
    tracker_sparql_cursor_set_connection (cursor, priv->connection);
391
392
0
  return cursor;
393
0
}
394
395
/**
396
 * tracker_sparql_statement_execute_async:
397
 * @stmt: a `TrackerSparqlStatement`
398
 * @cancellable: (nullable): Optional [type@Gio.Cancellable]
399
 * @callback: user-defined [type@Gio.AsyncReadyCallback] to be called when
400
 *            the asynchronous operation is finished.
401
 * @user_data: user-defined data to be passed to @callback
402
 *
403
 * Executes asynchronously the `SELECT` or `ASK` SPARQL query with the currently bound values.
404
 *
405
 * This function also works for `DESCRIBE` and `CONSTRUCT` queries that
406
 * retrieve data from the triple store. These query forms that return
407
 * RDF data are however more useful together with [method@SparqlStatement.serialize_async].
408
 *
409
 * This function should only be called on `TrackerSparqlStatement` objects
410
 * obtained through [method@SparqlConnection.query_statement] or
411
 * SELECT/CONSTRUCT/DESCRIBE statements loaded through
412
 * [method@SparqlConnection.load_statement_from_gresource].
413
 * An error will be raised if this method is called on a `INSERT` or `DELETE`
414
 * SPARQL query.
415
 */
416
void
417
tracker_sparql_statement_execute_async (TrackerSparqlStatement *stmt,
418
                                        GCancellable           *cancellable,
419
                                        GAsyncReadyCallback     callback,
420
                                        gpointer                user_data)
421
0
{
422
0
  g_return_if_fail (TRACKER_IS_SPARQL_STATEMENT (stmt));
423
0
  g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
424
425
0
  TRACKER_SPARQL_STATEMENT_GET_CLASS (stmt)->execute_async (stmt,
426
0
                                                            cancellable,
427
0
                                                            callback,
428
0
                                                            user_data);
429
0
}
430
431
/**
432
 * tracker_sparql_statement_execute_finish:
433
 * @stmt: a `TrackerSparqlStatement`
434
 * @res: a [type@Gio.AsyncResult] with the result of the operation
435
 * @error: Error location
436
 *
437
 * Finishes the asynchronous operation started through
438
 * [method@SparqlStatement.execute_async].
439
 *
440
 * Returns: (transfer full): A `TrackerSparqlCursor` with the query results.
441
 */
442
TrackerSparqlCursor *
443
tracker_sparql_statement_execute_finish (TrackerSparqlStatement  *stmt,
444
                                         GAsyncResult            *res,
445
                                         GError                 **error)
446
0
{
447
0
  TrackerSparqlStatementPrivate *priv =
448
0
    tracker_sparql_statement_get_instance_private (stmt);
449
0
  TrackerSparqlCursor *cursor;
450
451
0
  g_return_val_if_fail (TRACKER_IS_SPARQL_STATEMENT (stmt), NULL);
452
0
  g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
453
0
  g_return_val_if_fail (!error || !*error, NULL);
454
455
0
  cursor = TRACKER_SPARQL_STATEMENT_GET_CLASS (stmt)->execute_finish (stmt,
456
0
                                                                      res,
457
0
                                                                      error);
458
0
  if (cursor)
459
0
    tracker_sparql_cursor_set_connection (cursor, priv->connection);
460
461
0
  return cursor;
462
0
}
463
464
/**
465
 * tracker_sparql_statement_update:
466
 * @stmt: a `TrackerSparqlStatement`
467
 * @cancellable: (nullable): Optional [type@Gio.Cancellable]
468
 * @error: Error location
469
 *
470
 * Executes the `INSERT`/`DELETE` SPARQL query series with the currently bound values.
471
 *
472
 * This function should only be called on `TrackerSparqlStatement` objects
473
 * obtained through [method@SparqlConnection.update_statement] or
474
 * `INSERT`/`DELETE` statements loaded through
475
 * [method@SparqlConnection.load_statement_from_gresource].
476
 * An error will be raised if this method is called on
477
 * `SELECT`/`ASK`/`DESCRIBE`/`CONSTRUCT` SPARQL queries.
478
 *
479
 * Returns: %TRUE if the update finished with no errors, %FALSE otherwise
480
 *
481
 * Since: 3.5
482
 */
483
gboolean
484
tracker_sparql_statement_update (TrackerSparqlStatement  *stmt,
485
                                 GCancellable            *cancellable,
486
                                 GError                 **error)
487
0
{
488
0
  g_return_val_if_fail (TRACKER_IS_SPARQL_STATEMENT (stmt), FALSE);
489
0
  g_return_val_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable), FALSE);
490
0
  g_return_val_if_fail (!error || !*error, FALSE);
491
492
0
  return TRACKER_SPARQL_STATEMENT_GET_CLASS (stmt)->update (stmt,
493
0
                                                            cancellable,
494
0
                                                            error);
495
0
}
496
497
/**
498
 * tracker_sparql_statement_update_async:
499
 * @stmt: a `TrackerSparqlStatement`
500
 * @cancellable: (nullable): Optional [type@Gio.Cancellable]
501
 * @callback: user-defined [type@Gio.AsyncReadyCallback] to be called when
502
 *            the asynchronous operation is finished.
503
 * @user_data: user-defined data to be passed to @callback
504
 *
505
 * Executes asynchronously the `INSERT`/`DELETE` SPARQL query series with the currently bound values.
506
 *
507
 * This function should only be called on `TrackerSparqlStatement` objects
508
 * obtained through [method@SparqlConnection.update_statement] or
509
 * `INSERT`/`DELETE` statements loaded through
510
 * [method@SparqlConnection.load_statement_from_gresource].
511
 * An error will be raised if this method is called on
512
 * `SELECT`/`ASK`/`DESCRIBE`/`CONSTRUCT` SPARQL queries.
513
 *
514
 * Since: 3.5
515
 */
516
void
517
tracker_sparql_statement_update_async (TrackerSparqlStatement *stmt,
518
                                       GCancellable           *cancellable,
519
                                       GAsyncReadyCallback     callback,
520
                                       gpointer                user_data)
521
0
{
522
0
  g_return_if_fail (TRACKER_IS_SPARQL_STATEMENT (stmt));
523
0
  g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
524
525
0
  TRACKER_SPARQL_STATEMENT_GET_CLASS (stmt)->update_async (stmt,
526
0
                                                           cancellable,
527
0
                                                           callback,
528
0
                                                           user_data);
529
0
}
530
531
/**
532
 * tracker_sparql_statement_update_finish:
533
 * @stmt: a `TrackerSparqlStatement`
534
 * @result: a [type@Gio.AsyncResult] with the result of the operation
535
 * @error: Error location
536
 *
537
 * Finishes the asynchronous update started through
538
 * [method@SparqlStatement.update_async].
539
 *
540
 * Returns: %TRUE if the update finished with no errors, %FALSE otherwise
541
 *
542
 * Since: 3.5
543
 */
544
gboolean
545
tracker_sparql_statement_update_finish (TrackerSparqlStatement  *stmt,
546
                                        GAsyncResult            *result,
547
                                        GError                 **error)
548
0
{
549
0
  g_return_val_if_fail (TRACKER_IS_SPARQL_STATEMENT (stmt), FALSE);
550
0
  g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
551
0
  g_return_val_if_fail (!error || !*error, FALSE);
552
553
0
  return TRACKER_SPARQL_STATEMENT_GET_CLASS (stmt)->update_finish (stmt,
554
0
                                                                   result,
555
0
                                                                   error);
556
0
}
557
558
559
/**
560
 * tracker_sparql_statement_clear_bindings:
561
 * @stmt: a `TrackerSparqlStatement`
562
 *
563
 * Clears all bindings.
564
 */
565
void
566
tracker_sparql_statement_clear_bindings (TrackerSparqlStatement *stmt)
567
0
{
568
0
  g_return_if_fail (TRACKER_IS_SPARQL_STATEMENT (stmt));
569
570
0
  TRACKER_SPARQL_STATEMENT_GET_CLASS (stmt)->clear_bindings (stmt);
571
0
}
572
573
/**
574
 * tracker_sparql_statement_serialize_async:
575
 * @stmt: a `TrackerSparqlStatement`
576
 * @flags: serialization flags
577
 * @format: RDF format of the serialized data
578
 * @cancellable: (nullable): Optional [type@Gio.Cancellable]
579
 * @callback: user-defined [type@Gio.AsyncReadyCallback] to be called when
580
 *            the asynchronous operation is finished.
581
 * @user_data: user-defined data to be passed to @callback
582
 *
583
 * Serializes a `DESCRIBE` or `CONSTRUCT` query into the given RDF @format.
584
 *
585
 * The query @stmt was created from must be either a `DESCRIBE` or `CONSTRUCT`
586
 * query, an error will be raised otherwise.
587
 *
588
 * This is an asynchronous operation, @callback will be invoked when the
589
 * data is available for reading.
590
 *
591
 * The SPARQL endpoint may not support the specified format, in that case
592
 * an error will be raised.
593
 *
594
 * The @flags argument is reserved for future expansions, currently
595
 * #TRACKER_SERIALIZE_FLAGS_NONE must be passed.
596
 *
597
 * Since: 3.3
598
 **/
599
void
600
tracker_sparql_statement_serialize_async (TrackerSparqlStatement *stmt,
601
                                          TrackerSerializeFlags   flags,
602
                                          TrackerRdfFormat        format,
603
                                          GCancellable           *cancellable,
604
                                          GAsyncReadyCallback     callback,
605
                                          gpointer                user_data)
606
0
{
607
0
  g_return_if_fail (TRACKER_IS_SPARQL_STATEMENT (stmt));
608
0
  g_return_if_fail (flags == TRACKER_SERIALIZE_FLAGS_NONE);
609
0
  g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
610
0
  g_return_if_fail (callback != NULL);
611
612
0
  TRACKER_SPARQL_STATEMENT_GET_CLASS (stmt)->serialize_async (stmt,
613
0
                                                              flags,
614
0
                                                              format,
615
0
                                                              cancellable,
616
0
                                                              callback,
617
0
                                                              user_data);
618
0
}
619
620
/**
621
 * tracker_sparql_statement_serialize_finish:
622
 * @stmt: a `TrackerSparqlStatement`
623
 * @result: a [type@Gio.AsyncResult] with the result of the operation
624
 * @error: Error location
625
 *
626
 * Finishes the asynchronous operation started through
627
 * [method@SparqlStatement.serialize_async].
628
 *
629
 * Returns: (transfer full): a [class@Gio.InputStream] to read RDF content.
630
 *
631
 * Since: 3.3
632
 **/
633
GInputStream *
634
tracker_sparql_statement_serialize_finish (TrackerSparqlStatement  *stmt,
635
                                           GAsyncResult            *result,
636
                                           GError                 **error)
637
0
{
638
0
  g_return_val_if_fail (TRACKER_IS_SPARQL_STATEMENT (stmt), NULL);
639
0
  g_return_val_if_fail (G_IS_ASYNC_RESULT (result), NULL);
640
0
  g_return_val_if_fail (!error || !*error, NULL);
641
642
0
  return TRACKER_SPARQL_STATEMENT_GET_CLASS (stmt)->serialize_finish (stmt,
643
0
                                                                      result,
644
0
                                                                      error);
645
0
}