tracker-0.16.2/src/libtracker-data/tracker-db-interface.c

No issues found

 1 /*
 2  * Copyright (C) 2008, Nokia <ivan.frade@nokia.com>
 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 #include <string.h>
21 
22 #include <gobject/gvaluecollector.h>
23 
24 #include "tracker-db-interface.h"
25 
26 GQuark
27 tracker_db_interface_error_quark (void)
28 {
29 	return g_quark_from_static_string ("tracker-db-interface-error-quark");
30 }
31 
32 void
33 tracker_db_interface_execute_query (TrackerDBInterface  *interface,
34                                     GError             **error,
35                                     const gchar         *query,
36                                     ...)
37 {
38 	va_list args;
39 
40 	va_start (args, query);
41 	tracker_db_interface_execute_vquery (interface,
42 	                                                  error,
43 	                                                  query,
44 	                                                  args);
45 	va_end (args);
46 }
47 
48 gboolean
49 tracker_db_interface_start_transaction (TrackerDBInterface *interface)
50 {
51 	GError *error = NULL;
52 
53 	tracker_db_interface_execute_query (interface,
54 	                                    &error,
55 	                                    "BEGIN TRANSACTION");
56 
57 	if (error) {
58 		g_warning ("%s", error->message);
59 		g_error_free (error);
60 		return FALSE;
61 	}
62 
63 	return TRUE;
64 }
65 
66 gboolean
67 tracker_db_interface_end_db_transaction (TrackerDBInterface  *interface,
68                                          GError             **error)
69 {
70 	GError *internal_error = NULL;
71 
72 	tracker_db_interface_execute_query (interface, &internal_error, "COMMIT");
73 
74 	if (internal_error) {
75 		g_propagate_error (error, internal_error);
76 		/* We propagate the error, ROLLBACK happens later */
77 		return FALSE;
78 	}
79 
80 	return TRUE;
81 }