[tracker/int64] libtracker-{db, data}: Support storing and retrieving 64-bit integers
- From: Jürg Billeter <juergbi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/int64] libtracker-{db, data}: Support storing and retrieving 64-bit integers
- Date: Tue, 15 Jun 2010 15:32:02 +0000 (UTC)
commit f02264b2054d4b68faaef3e78f6d9a9857a60969
Author: Jürg Billeter <j bitron ch>
Date: Tue Jun 15 17:19:00 2010 +0200
libtracker-{db,data}: Support storing and retrieving 64-bit integers
Fixes NB#174162.
src/libtracker-data/tracker-data-manager.c | 16 ++++----
src/libtracker-data/tracker-data-update.c | 45 +++++++++++------------
src/libtracker-data/tracker-sparql-query.vala | 2 +
src/libtracker-db/tracker-db-interface-sqlite.c | 30 +++++-----------
src/libtracker-db/tracker-db-interface.c | 12 +++---
src/libtracker-db/tracker-db-interface.h | 5 +--
tests/libtracker-data/tracker-ontology-test.c | 4 +-
tests/libtracker-data/tracker-sparql-test.c | 4 +-
8 files changed, 51 insertions(+), 67 deletions(-)
---
diff --git a/src/libtracker-data/tracker-data-manager.c b/src/libtracker-data/tracker-data-manager.c
index 40c3730..359d253 100644
--- a/src/libtracker-data/tracker-data-manager.c
+++ b/src/libtracker-data/tracker-data-manager.c
@@ -1373,7 +1373,7 @@ db_get_static_data (TrackerDBInterface *iface)
tracker_db_cursor_get_value (cursor, 2, &value);
if (G_VALUE_TYPE (&value) != 0) {
- notify = (g_value_get_int (&value) == 1);
+ notify = (g_value_get_int64 (&value) == 1);
g_value_unset (&value);
} else {
/* NULL */
@@ -1462,7 +1462,7 @@ db_get_static_data (TrackerDBInterface *iface)
tracker_db_cursor_get_value (cursor, 4, &value);
if (G_VALUE_TYPE (&value) != 0) {
- multi_valued = (g_value_get_int (&value) > 1);
+ multi_valued = (g_value_get_int64 (&value) > 1);
g_value_unset (&value);
} else {
/* nrl:maxCardinality not set
@@ -1473,7 +1473,7 @@ db_get_static_data (TrackerDBInterface *iface)
tracker_db_cursor_get_value (cursor, 5, &value);
if (G_VALUE_TYPE (&value) != 0) {
- indexed = (g_value_get_int (&value) == 1);
+ indexed = (g_value_get_int64 (&value) == 1);
g_value_unset (&value);
} else {
/* NULL */
@@ -1485,7 +1485,7 @@ db_get_static_data (TrackerDBInterface *iface)
tracker_db_cursor_get_value (cursor, 7, &value);
if (G_VALUE_TYPE (&value) != 0) {
- fulltext_indexed = (g_value_get_int (&value) == 1);
+ fulltext_indexed = (g_value_get_int64 (&value) == 1);
g_value_unset (&value);
} else {
/* NULL */
@@ -1495,7 +1495,7 @@ db_get_static_data (TrackerDBInterface *iface)
tracker_db_cursor_get_value (cursor, 8, &value);
if (G_VALUE_TYPE (&value) != 0) {
- fulltext_no_limit = (g_value_get_int (&value) == 1);
+ fulltext_no_limit = (g_value_get_int64 (&value) == 1);
g_value_unset (&value);
} else {
/* NULL */
@@ -1505,7 +1505,7 @@ db_get_static_data (TrackerDBInterface *iface)
tracker_db_cursor_get_value (cursor, 9, &value);
if (G_VALUE_TYPE (&value) != 0) {
- transient = (g_value_get_int (&value) == 1);
+ transient = (g_value_get_int64 (&value) == 1);
g_value_unset (&value);
} else {
/* NULL */
@@ -1515,7 +1515,7 @@ db_get_static_data (TrackerDBInterface *iface)
tracker_db_cursor_get_value (cursor, 10, &value);
if (G_VALUE_TYPE (&value) != 0) {
- annotation = (g_value_get_int (&value) == 1);
+ annotation = (g_value_get_int64 (&value) == 1);
g_value_unset (&value);
} else {
/* NULL */
@@ -1527,7 +1527,7 @@ db_get_static_data (TrackerDBInterface *iface)
tracker_db_cursor_get_value (cursor, 11, &value);
if (G_VALUE_TYPE (&value) != 0) {
- writeback = (g_value_get_int (&value) == 1);
+ writeback = (g_value_get_int64 (&value) == 1);
g_value_unset (&value);
} else {
/* NULL */
diff --git a/src/libtracker-data/tracker-data-update.c b/src/libtracker-data/tracker-data-update.c
index 97619ec..a8ab034 100644
--- a/src/libtracker-data/tracker-data-update.c
+++ b/src/libtracker-data/tracker-data-update.c
@@ -594,18 +594,15 @@ statement_bind_gvalue (TrackerDBStatement *stmt,
case G_TYPE_STRING:
tracker_db_statement_bind_text (stmt, (*idx)++, g_value_get_string (value));
break;
- case G_TYPE_INT:
- tracker_db_statement_bind_int (stmt, (*idx)++, g_value_get_int (value));
- break;
case G_TYPE_INT64:
- tracker_db_statement_bind_int64 (stmt, (*idx)++, g_value_get_int64 (value));
+ tracker_db_statement_bind_int (stmt, (*idx)++, g_value_get_int64 (value));
break;
case G_TYPE_DOUBLE:
tracker_db_statement_bind_double (stmt, (*idx)++, g_value_get_double (value));
break;
default:
if (type == TRACKER_TYPE_DATE_TIME) {
- tracker_db_statement_bind_int64 (stmt, (*idx)++, tracker_date_time_get_time (value));
+ tracker_db_statement_bind_int (stmt, (*idx)++, tracker_date_time_get_time (value));
tracker_db_statement_bind_int (stmt, (*idx)++, tracker_date_time_get_local_date (value));
tracker_db_statement_bind_int (stmt, (*idx)++, tracker_date_time_get_local_time (value));
} else {
@@ -748,7 +745,7 @@ tracker_data_resource_buffer_flush (GError **error)
if (stmt) {
tracker_db_statement_bind_int (stmt, 0, resource_buffer->id);
g_warn_if_fail (resource_time != 0);
- tracker_db_statement_bind_int64 (stmt, 1, (gint64) resource_time);
+ tracker_db_statement_bind_int (stmt, 1, (gint64) resource_time);
tracker_db_statement_bind_int (stmt, 3, tracker_data_update_get_next_modseq ());
tracker_db_statement_execute (stmt, &actual_error);
g_object_unref (stmt);
@@ -1036,11 +1033,11 @@ cache_create_service_decomposed (TrackerClass *cl,
g_ptr_array_add (resource_buffer->types, cl);
- g_value_init (&gvalue, G_TYPE_INT);
+ g_value_init (&gvalue, G_TYPE_INT64);
cache_insert_row (cl);
- g_value_set_int (&gvalue, ensure_resource_id (tracker_class_get_uri (cl), NULL));
+ g_value_set_int64 (&gvalue, ensure_resource_id (tracker_class_get_uri (cl), NULL));
cache_insert_value ("rdfs:Resource_rdf:type", "rdf:type", &gvalue,
graph != NULL ? ensure_resource_id (graph, NULL) : graph_id,
TRUE, FALSE, FALSE);
@@ -1077,8 +1074,8 @@ value_equal (GValue *value1,
switch (type) {
case G_TYPE_STRING:
return (strcmp (g_value_get_string (value1), g_value_get_string (value2)) == 0);
- case G_TYPE_INT:
- return g_value_get_int (value1) == g_value_get_int (value2);
+ case G_TYPE_INT64:
+ return g_value_get_int64 (value1) == g_value_get_int64 (value2);
case G_TYPE_DOUBLE:
/* does RDF define equality for floating point values? */
return g_value_get_double (value1) == g_value_get_double (value2);
@@ -1201,7 +1198,7 @@ get_property_values (TrackerProperty *property)
if (tracker_property_get_data_type (property) == TRACKER_PROPERTY_TYPE_DATETIME) {
gint time;
- time = g_value_get_int (&gvalue);
+ time = g_value_get_int64 (&gvalue);
g_value_unset (&gvalue);
g_value_init (&gvalue, TRACKER_TYPE_DATE_TIME);
/* UTC offset is irrelevant for comparison */
@@ -1298,14 +1295,14 @@ string_to_gvalue (const gchar *value,
g_value_set_string (gvalue, value);
break;
case TRACKER_PROPERTY_TYPE_INTEGER:
- g_value_init (gvalue, G_TYPE_INT);
- g_value_set_int (gvalue, atoi (value));
+ g_value_init (gvalue, G_TYPE_INT64);
+ g_value_set_int64 (gvalue, atoll (value));
break;
case TRACKER_PROPERTY_TYPE_BOOLEAN:
- /* use G_TYPE_INT to be compatible with value stored in DB
+ /* use G_TYPE_INT64 to be compatible with value stored in DB
(important for value_equal function) */
- g_value_init (gvalue, G_TYPE_INT);
- g_value_set_int (gvalue, strcmp (value, "true") == 0);
+ g_value_init (gvalue, G_TYPE_INT64);
+ g_value_set_int64 (gvalue, strcmp (value, "true") == 0);
break;
case TRACKER_PROPERTY_TYPE_DOUBLE:
g_value_init (gvalue, G_TYPE_DOUBLE);
@@ -1318,8 +1315,8 @@ string_to_gvalue (const gchar *value,
break;
case TRACKER_PROPERTY_TYPE_RESOURCE:
object_id = ensure_resource_id (value, NULL);
- g_value_init (gvalue, G_TYPE_INT);
- g_value_set_int (gvalue, object_id);
+ g_value_init (gvalue, G_TYPE_INT64);
+ g_value_set_int64 (gvalue, object_id);
break;
default:
g_warn_if_reached ();
@@ -1376,8 +1373,8 @@ cache_set_metadata_decomposed (TrackerProperty *property,
return FALSE;
}
} else {
- g_value_init (&gvalue, G_TYPE_INT);
- g_value_set_int (&gvalue, value_id);
+ g_value_init (&gvalue, G_TYPE_INT64);
+ g_value_set_int64 (&gvalue, value_id);
}
if (!value_set_add_value (old_values, &gvalue)) {
@@ -1461,8 +1458,8 @@ delete_metadata_decomposed (TrackerProperty *property,
return FALSE;
}
} else {
- g_value_init (&gvalue, G_TYPE_INT);
- g_value_set_int (&gvalue, value_id);
+ g_value_init (&gvalue, G_TYPE_INT64);
+ g_value_set_int64 (&gvalue, value_id);
}
if (!value_set_remove_value (old_values, &gvalue)) {
@@ -1660,8 +1657,8 @@ resource_buffer_switch (const gchar *graph,
}
}
- g_value_init (&gvalue, G_TYPE_INT);
- g_value_set_int (&gvalue, tracker_data_update_get_next_modseq ());
+ g_value_init (&gvalue, G_TYPE_INT64);
+ g_value_set_int64 (&gvalue, tracker_data_update_get_next_modseq ());
cache_insert_value ("rdfs:Resource", "tracker:modified", &gvalue,
0,
FALSE, FALSE, FALSE);
diff --git a/src/libtracker-data/tracker-sparql-query.vala b/src/libtracker-data/tracker-sparql-query.vala
index 4eba6d5..c4a2d9e 100644
--- a/src/libtracker-data/tracker-sparql-query.vala
+++ b/src/libtracker-data/tracker-sparql-query.vala
@@ -964,6 +964,8 @@ public class Tracker.Sparql.Query : Object {
{
if (value.type () == typeof (int)) {
return value.get_int ().to_string ();
+ } else if (value.type () == typeof (int64)) {
+ return value.get_int64 ().to_string ();
} else if (value.type () == typeof (double)) {
return value.get_double ().to_string ();
} else if (value.type () == typeof (string)) {
diff --git a/src/libtracker-db/tracker-db-interface-sqlite.c b/src/libtracker-db/tracker-db-interface-sqlite.c
index 6cf8953..c80e5cc 100644
--- a/src/libtracker-db/tracker-db-interface-sqlite.c
+++ b/src/libtracker-db/tracker-db-interface-sqlite.c
@@ -689,8 +689,8 @@ add_row (TrackerDBResultSet *result_set,
g_value_set_string (&value, (gchar *) sqlite3_column_text (stmt, i));
break;
case SQLITE_INTEGER:
- g_value_init (&value, G_TYPE_INT);
- g_value_set_int (&value, sqlite3_column_int (stmt, i));
+ g_value_init (&value, G_TYPE_INT64);
+ g_value_set_int64 (&value, sqlite3_column_int64 (stmt, i));
break;
case SQLITE_FLOAT:
g_value_init (&value, G_TYPE_DOUBLE);
@@ -1070,21 +1070,9 @@ tracker_db_statement_bind_double (TrackerDBStatement *stmt,
}
void
-tracker_db_statement_bind_int (TrackerDBStatement *stmt,
- int index,
- int value)
-{
- g_return_if_fail (TRACKER_IS_DB_STATEMENT (stmt));
-
- g_assert (!stmt->stmt_is_sunk);
-
- sqlite3_bind_int (stmt->stmt, index + 1, value);
-}
-
-void
-tracker_db_statement_bind_int64 (TrackerDBStatement *stmt,
- int index,
- gint64 value)
+tracker_db_statement_bind_int (TrackerDBStatement *stmt,
+ int index,
+ gint64 value)
{
g_return_if_fail (TRACKER_IS_DB_STATEMENT (stmt));
@@ -1179,8 +1167,8 @@ tracker_db_cursor_get_value (TrackerDBCursor *cursor, guint column, GValue *val
g_value_set_string (value, (gchar *) sqlite3_column_text (cursor->stmt, column));
break;
case SQLITE_INTEGER:
- g_value_init (value, G_TYPE_INT);
- g_value_set_int (value, sqlite3_column_int (cursor->stmt, column));
+ g_value_init (value, G_TYPE_INT64);
+ g_value_set_int64 (value, sqlite3_column_int64 (cursor->stmt, column));
break;
case SQLITE_FLOAT:
g_value_init (value, G_TYPE_DOUBLE);
@@ -1195,10 +1183,10 @@ tracker_db_cursor_get_value (TrackerDBCursor *cursor, guint column, GValue *val
}
-gint
+gint64
tracker_db_cursor_get_int (TrackerDBCursor *cursor, guint column)
{
- return (gint) sqlite3_column_int (cursor->stmt, column);
+ return (gint64) sqlite3_column_int64 (cursor->stmt, column);
}
gdouble
diff --git a/src/libtracker-db/tracker-db-interface.c b/src/libtracker-db/tracker-db-interface.c
index 5d0aa99..d3c8275 100644
--- a/src/libtracker-db/tracker-db-interface.c
+++ b/src/libtracker-db/tracker-db-interface.c
@@ -203,11 +203,11 @@ _tracker_db_result_set_set_value (TrackerDBResultSet *result_set,
}
switch (result_set->col_types [column]) {
- case G_TYPE_INT: {
- gint *val;
+ case G_TYPE_INT64: {
+ gint64 *val;
- val = g_new (gint, 1);
- *val = g_value_get_int (value);
+ val = g_new (gint64, 1);
+ *val = g_value_get_int64 (value);
row[column] = val;
break;
}
@@ -232,8 +232,8 @@ fill_in_value (GValue *value,
gpointer data)
{
switch (G_VALUE_TYPE (value)) {
- case G_TYPE_INT:
- g_value_set_int (value, *((gint*) data));
+ case G_TYPE_INT64:
+ g_value_set_int64 (value, *((gint64*) data));
break;
case G_TYPE_DOUBLE:
g_value_set_double (value, *((gdouble *) data));
diff --git a/src/libtracker-db/tracker-db-interface.h b/src/libtracker-db/tracker-db-interface.h
index 0d2f255..56a851d 100644
--- a/src/libtracker-db/tracker-db-interface.h
+++ b/src/libtracker-db/tracker-db-interface.h
@@ -104,9 +104,6 @@ void tracker_db_statement_bind_double (TrackerDBStatement
double value);
void tracker_db_statement_bind_int (TrackerDBStatement *stmt,
int index,
- int value);
-void tracker_db_statement_bind_int64 (TrackerDBStatement *stmt,
- int index,
gint64 value);
void tracker_db_statement_bind_null (TrackerDBStatement *stmt,
int index);
@@ -147,7 +144,7 @@ void tracker_db_cursor_get_value (TrackerDBCursor
const gchar* tracker_db_cursor_get_string (TrackerDBCursor *cursor,
guint column,
gint *length);
-gint tracker_db_cursor_get_int (TrackerDBCursor *cursor,
+gint64 tracker_db_cursor_get_int (TrackerDBCursor *cursor,
guint column);
gdouble tracker_db_cursor_get_double (TrackerDBCursor *cursor,
guint column);
diff --git a/tests/libtracker-data/tracker-ontology-test.c b/tests/libtracker-data/tracker-ontology-test.c
index 2cafdc2..9781e85 100644
--- a/tests/libtracker-data/tracker-ontology-test.c
+++ b/tests/libtracker-data/tracker-ontology-test.c
@@ -157,8 +157,8 @@ query_helper (const gchar *query_filename, const gchar *results_filename)
_tracker_db_result_set_get_value (result_set, col, &value);
switch (G_VALUE_TYPE (&value)) {
- case G_TYPE_INT:
- g_string_append_printf (test_results, "\"%d\"", g_value_get_int (&value));
+ case G_TYPE_INT64:
+ g_string_append_printf (test_results, "\"%" G_GINT64_FORMAT "\"", g_value_get_int64 (&value));
break;
case G_TYPE_DOUBLE:
g_string_append_printf (test_results, "\"%f\"", g_value_get_double (&value));
diff --git a/tests/libtracker-data/tracker-sparql-test.c b/tests/libtracker-data/tracker-sparql-test.c
index 7fa0557..bb5ddc4 100644
--- a/tests/libtracker-data/tracker-sparql-test.c
+++ b/tests/libtracker-data/tracker-sparql-test.c
@@ -160,8 +160,8 @@ check_result (TrackerDBResultSet *result_set,
_tracker_db_result_set_get_value (result_set, col, &value);
switch (G_VALUE_TYPE (&value)) {
- case G_TYPE_INT:
- g_string_append_printf (test_results, "\"%d\"", g_value_get_int (&value));
+ case G_TYPE_INT64:
+ g_string_append_printf (test_results, "\"%" G_GINT64_FORMAT "\"", g_value_get_int64 (&value));
break;
case G_TYPE_DOUBLE:
g_string_append_printf (test_results, "\"%f\"", g_value_get_double (&value));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]