The unified diff between revisions [900934c7..] and [84d2685c..] is displayed below. It can also be downloaded as a raw diff.

This diff has been restricted to the following files: 'sqlite-backend.c'

#
#
# patch "sqlite-backend.c"
#  from [9396b2d5c05b0c4802dd5c7e19f076cf97a48426]
#    to [eba591f8c420338f2011bc2039376a1fba141423]
#
============================================================
--- sqlite-backend.c	9396b2d5c05b0c4802dd5c7e19f076cf97a48426
+++ sqlite-backend.c	eba591f8c420338f2011bc2039376a1fba141423
@@ -40,6 +40,15 @@
 #define ROOT_DIRECTORY_PARENT			-1
 #define ROOT_DIRECTORY_NAME			""

+/* used for columns, they indicate which gconf type we're actually storing */
+#define T_STRING				"s"
+#define T_INT					"i"
+#define T_FLOAT					"f"
+#define T_BOOL					"b"
+#define T_SCHEMA				"c"
+#define T_LIST					"l"
+#define T_PAIR					"p"
+
 /*
  * VTable functions
  */
@@ -328,7 +337,7 @@ commit_transaction (SqliteSource *ss)
 	return rv;
 }

-gboolean
+static gboolean
 get_value_id_in_directory (SqliteSource *ss, SqliteDirectory *dir, const char *name, long long int *id)
 {
 	long long int possible_id, nrow;
@@ -378,7 +387,7 @@ get_value_id_in_directory (SqliteSource
 	return rv;
 }

-gboolean
+static gboolean
 delete_old_list (SqliteSource *ss, long long int id)
 {
 	gboolean rv;
@@ -396,7 +405,7 @@ delete_old_list (SqliteSource *ss, long
 	return rv;
 }

-gboolean
+static gboolean
 delete_old_pair (SqliteSource *ss, long long int id)
 {
 	gboolean rv;
@@ -414,14 +423,35 @@ delete_old_pair (SqliteSource *ss, long
 	return rv;
 }

-gboolean
+static const char *
+get_type_for_column (GConfValueType t)
+{
+	const char *lt;
+
+	if (t == GCONF_VALUE_STRING) {
+		lt = T_STRING;
+	} else if (t == GCONF_VALUE_INT) {
+		lt = T_INT;
+	} else if (t == GCONF_VALUE_FLOAT) {
+		lt = T_FLOAT;
+	} else if (t == GCONF_VALUE_BOOL) {
+		lt = T_BOOL;
+	} else {
+		lt = NULL;
+	}
+
+	return lt;
+}
+
+static gboolean
 insert_or_update_value (SqliteSource *ss, SqliteDirectory *dir, const char *name, const GConfValue *value)
 {
 	gchar *mod_user;
 	GTime mod_time;
 	gboolean rv;
 	GConfValueType list_type;
-	char *query, *lt, *err_mesg;
+	char *query, *err_mesg;
+	const char *lt;

 	g_return_val_if_fail (ss != NULL, FALSE);
 	g_return_val_if_fail (dir != NULL, FALSE);
@@ -432,13 +462,6 @@ insert_or_update_value (SqliteSource *ss
 	mod_time = time (NULL);

 #define BASIC_INSERT	"INSERT OR REPLACE INTO keys (name, directory_id, mod_user, mod_time, value_type, value) VALUES "
-#define T_STRING	"s"
-#define T_INT		"i"
-#define T_FLOAT		"f"
-#define T_BOOL		"b"
-#define T_SCHEMA	"c"
-#define T_LIST		"l"
-#define T_PAIR		"p"

 	rv = TRUE;
 	query = NULL;
@@ -465,20 +488,12 @@ insert_or_update_value (SqliteSource *ss
 			break;
 		case GCONF_VALUE_LIST:
 			list_type = gconf_value_get_list_type (value);
-			if (list_type == GCONF_VALUE_STRING) {
-				lt = T_STRING;
-			} else if (list_type == GCONF_VALUE_INT) {
-				lt = T_INT;
-			} else if (list_type == GCONF_VALUE_FLOAT) {
-				lt = T_FLOAT;
-			} else if (list_type == GCONF_VALUE_BOOL) {
-				lt = T_BOOL;
-			} else {
+			lt = get_type_for_column (list_type);
+			if (!lt) {
 				gconf_log (GCL_ERR, "(insert_or_update_value) List is of invalid type.");
 				rv = FALSE;
 				break;
 			}
-			printf("%lld\n", dir->id);
 			query = sqlite3_mprintf (BASIC_INSERT "('%q', %lld, '%q', %d, '%q', '%q')",
 					name, dir->id, mod_user, mod_time, T_LIST, lt);
 			break;
@@ -511,17 +526,84 @@ insert_or_update_value (SqliteSource *ss
 	return rv;
 }

-gboolean
-insert_list_for_key (SqliteSource *ss, const GConfValue *value, long long int last_rowid)
+#define BASIC_LIST_INSERT	"INSERT INTO lists (key_id, list_idx, value) "
+
+static char *
+list_sql_string (long long int key, long long int idx, const void *v)
 {
+	return sqlite3_mprintf (BASIC_LIST_INSERT "VALUES (%lld, %lld, '%q')", key, idx, *(const char *)v);
+}
+
+static char *
+list_sql_int (long long int key, long long int idx, const void *v)
+{
+	return sqlite3_mprintf (BASIC_LIST_INSERT "VALUES (%lld, %lld, %d)", key, idx, *(const int *)v);
+}
+
+static char *
+list_sql_float (long long int key, long long int idx, const void *v)
+{
+	return sqlite3_mprintf (BASIC_LIST_INSERT "VALUES (%lld, %lld, %f)", key, idx, *(const double *)v);
+}
+
+static char *
+list_sql_bool (long long int key, long long int idx, const void *v)
+{
+	return sqlite3_mprintf (BASIC_LIST_INSERT "VALUES (%lld, %lld, %d)", key, idx, *(const gboolean *)v);
+}
+
+static gboolean
+insert_list_for_key (SqliteSource *ss, const GConfValue *value, long long int key)
+{
+	GConfValueType list_type;
+	long long int idx;
+	GSList *list;
+	gboolean rv;
+	char *query;
+	char *err_mesg;
+	char *(*list_sql_func)(long long int, long long int, const void *);
+
 	g_return_val_if_fail (ss != NULL, FALSE);
 	g_return_val_if_fail (value != NULL, FALSE);

-	return FALSE;
+	list_type = gconf_value_get_list_type (value);
+	/* overly paranoid perhaps? */
+	g_return_val_if_fail (get_type_for_column (list_type) != NULL, FALSE);
+
+	switch (list_type) {
+		case GCONF_VALUE_STRING: list_sql_func = list_sql_string; break;
+		case GCONF_VALUE_INT: list_sql_func = list_sql_int; break;
+		case GCONF_VALUE_FLOAT: list_sql_func = list_sql_float; break;
+		case GCONF_VALUE_BOOL: list_sql_func = list_sql_bool; break;
+		default: list_sql_func= NULL;
+	}
+	g_return_val_if_fail (list_sql_func != NULL, FALSE);
+
+	rv = TRUE;
+	idx = 0;
+	list = gconf_value_get_list (value);
+	while (list) {
+		query = list_sql_func (key, idx, list->data);
+		printf ("list thing is : %s\n", query);
+
+		if (sqlite3_exec (ss->db, query, NULL, NULL, &err_mesg) != SQLITE_OK) {
+			gconf_log (GCL_ERR, "(insert_list_for_key) SQL error: %s", err_mesg);
+			sqlite3_free (query);
+			sqlite3_free (err_mesg);
+			rv = FALSE;
+			break;
+		}
+
+		sqlite3_free (query);
+		list = g_slist_next (list);
+		idx++;
+	}
+
+	return rv;
 }

-gboolean
-insert_pair_for_key (SqliteSource *ss, const GConfValue *value, long long int last_rowid)
+static gboolean
+insert_pair_for_key (SqliteSource *ss, const GConfValue *value, long long int key)
 {
 	g_return_val_if_fail (ss != NULL, FALSE);
 	g_return_val_if_fail (value != NULL, FALSE);
@@ -529,8 +611,8 @@ insert_pair_for_key (SqliteSource *ss, c
 	return FALSE;
 }

-gboolean
-insert_schema_for_key (SqliteSource *ss, const GConfValue *value, long long int last_rowid)
+static gboolean
+insert_schema_for_key (SqliteSource *ss, const GConfValue *value, long long int key)
 {
 	g_return_val_if_fail (ss != NULL, FALSE);
 	g_return_val_if_fail (value != NULL, FALSE);
@@ -538,7 +620,7 @@ insert_schema_for_key (SqliteSource *ss,
 	return FALSE;
 }

-gboolean
+static gboolean
 set_value_in_directory (SqliteSource *ss, SqliteDirectory *dir, const char *name, const GConfValue *value, GError **error)
 {
 	char *query = NULL;