static GList
*zak_bks_db_plugin_get_bookmarks (ZakBksPluggable *pluggable)
{
+ GdaExSqlBuilder *sqlb;
+ GdaDataModel *dm;
+ GdaDataModelIter *iter;
+ GList *ret;
+
+ ZakBksDBPluginPrivate *priv = ZAK_BKS_DB_PLUGIN_GET_PRIVATE (pluggable);
+
+ ret = NULL;
+
+ sqlb = gdaex_sql_builder_new (GDA_SQL_STATEMENT_SELECT);
+
+ gdaex_sql_builder_from (sqlb, "bookmarks", NULL);
+
+ gdaex_sql_builder_order (sqlb, "name", NULL);
+
+ dm = gdaex_sql_builder_query (sqlb, priv->gdaex, NULL);
+ if (!gdaex_data_model_is_empty (dm))
+ {
+ iter = gda_data_model_create_iter (dm);
+ while (gda_data_model_iter_next (dm, iter))
+ {
+ ZakBksBookmark *bk;
+ bk = g_new0 (ZakBksBookmark, 1);
+ bk->name = gdaex_data_model_iter_get_field_value_stringify_at (iter, "name");
+ bk->url = gdaex_data_model_iter_get_field_value_stringify_at (iter, "url");
+
+ ret = g_list_append (ret, bk);
+ }
+ }
+
+ return ret;
}
static void
zak_bks_db_plugin_add_bookmark (ZakBksPluggable *pluggable, ZakBksBookmark *bk)
{
+ GdaExSqlBuilder *sqlb;
+ GdaDataModel *dm;
+ GValue *gval;
+
+ ZakBksDBPluginPrivate *priv = ZAK_BKS_DB_PLUGIN_GET_PRIVATE (pluggable);
+
+ sqlb = gdaex_sql_builder_new (GDA_SQL_STATEMENT_SELECT);
+ gdaex_sql_builder_from (sqlb, "bookmarks", NULL);
+
+ gval = g_new0 (GValue, 1);
+ g_value_init (gval, G_TYPE_STRING);
+ g_value_set_string (gval, bk->url);
+ gdaex_sql_builder_where (sqlb, 0,
+ "bookmarks", "url", "",
+ GDA_SQL_OPERATOR_TYPE_EQ,
+ gval,
+ NULL);
+ g_value_unset (gval);
+
+ dm = gdaex_sql_builder_query (sqlb, priv->gdaex, NULL);
+ if (!gdaex_data_model_is_empty (dm))
+ {
+ sqlb = gdaex_sql_builder_new (GDA_SQL_STATEMENT_INSERT);
+
+ gval = g_new0 (GValue, 1);
+ g_value_init (gval, G_TYPE_STRING);
+ g_value_set_string (gval, bk->name);
+ gdaex_sql_builder_field (sqlb,
+ "bookmarks", "name", NULL,
+ gval);
+ g_value_unset (gval);
+
+ gval = g_new0 (GValue, 1);
+ g_value_init (gval, G_TYPE_STRING);
+ g_value_set_string (gval, bk->url);
+ gdaex_sql_builder_field (sqlb,
+ "bookmarks", "url", NULL,
+ gval);
+ g_value_unset (gval);
+
+ gdaex_sql_builder_execute (sqlb, priv->gdaex, NULL);
+ }
+ else
+ {
+ sqlb = gdaex_sql_builder_new (GDA_SQL_STATEMENT_UPDATE);
+
+ gval = g_new0 (GValue, 1);
+ g_value_init (gval, G_TYPE_STRING);
+ g_value_set_string (gval, bk->name);
+ gdaex_sql_builder_field (sqlb,
+ "bookmarks", "name", NULL,
+ gval);
+ g_value_unset (gval);
+
+ gval = g_new0 (GValue, 1);
+ g_value_init (gval, G_TYPE_STRING);
+ g_value_set_string (gval, bk->url);
+ gdaex_sql_builder_where (sqlb, 0,
+ "bookmarks", "url", "",
+ GDA_SQL_OPERATOR_TYPE_EQ,
+ gval,
+ NULL);
+ g_value_unset (gval);
+
+ gdaex_sql_builder_execute (sqlb, priv->gdaex, NULL);
+ }
}
static void
zak_bks_db_plugin_remove_bookmark (ZakBksPluggable *pluggable, ZakBksBookmark *bk)
{
+ GdaExSqlBuilder *sqlb;
+ GValue *gval;
+
+ ZakBksDBPluginPrivate *priv = ZAK_BKS_DB_PLUGIN_GET_PRIVATE (pluggable);
+
+ sqlb = gdaex_sql_builder_new (GDA_SQL_STATEMENT_DELETE);
+
+ gdaex_sql_builder_from (sqlb, "bookmarks", NULL);
+
+ gval = g_new0 (GValue, 1);
+ g_value_init (gval, G_TYPE_STRING);
+ g_value_set_string (gval, bk->url);
+ gdaex_sql_builder_where (sqlb, 0,
+ "bookmarks", "url", "",
+ GDA_SQL_OPERATOR_TYPE_EQ,
+ gval,
+ NULL);
+ g_value_unset (gval);
+ gdaex_sql_builder_execute (sqlb, priv->gdaex, NULL);
}
static void