Permalink
Browse files

Merge pull request #160 from piotras/ratatoskr

Minor updates
  • Loading branch information...
2 parents 77f7399 + 3fea42f commit 2045c83993b15a356020e59c93273d641ad78368 @piotras piotras committed May 17, 2012
View
@@ -192,7 +192,6 @@ src_libmidgard2_la_public_SOURCES = \
src/midgard_collector.c \
src/midgard_dbus.h \
src/midgard_dbus.c \
- src/midgard_dbus_interface.h \
src/midgard_executable.c \
src/midgard_object_parameter.c \
src/midgard_object_attachment.c \
@@ -238,6 +237,12 @@ src_libmidgard2_la_public_SOURCES = \
src/sql/midgard_sql_query_constraint.c \
$(NULL)
+if MIDGARD_DBUS_SUPPORT
+src_libmidgard2_la_dbus_SOURCES = src/midgard_dbus_interface.h
+else
+src_libmidgard2_la_dbus_SOURCES =
+endif
+
pkgdatadir = $(datadir)/midgard2
pkglibdir = $(libdir)/midgard2
libmidgardincludedir = $(includedir)/midgard2
@@ -249,7 +254,7 @@ libsubmidgardinclude_HEADERS = $(midgard_public_h) src/midgard.h
libmidgardsqlincludedir = $(includedir)/midgard2/midgard/sql
libmidgardsqlinclude_HEADERS = $(midgard_sql_public_h)
-src_libmidgard2_la_SOURCES = $(src_libmidgard2_la_public_SOURCES) $(src_libmidgard2_la_core_SOURCES)
+src_libmidgard2_la_SOURCES = $(src_libmidgard2_la_public_SOURCES) $(src_libmidgard2_la_core_SOURCES) $(src_libmidgard2_la_dbus_SOURCES)
mgdschemasdir = $(datadir)/midgard2/schema
@@ -379,7 +379,7 @@ gboolean __query_select_data_add_joins (MidgardSqlQuerySelectData *self, GdaSqlO
GdaSqlStatementSelect *select = (GdaSqlStatementSelect *) sql_stm->contents;
GdaSqlSelectFrom *from = select->from;
GdaSqlSelectJoin *join;
-
+
for (l = MIDGARD_QUERY_EXECUTOR (self)->priv->joins; l != NULL; l = l->next) {
qsj *_sj = (qsj*) l->data;
@@ -417,7 +417,8 @@ gboolean __query_select_data_add_joins (MidgardSqlQuerySelectData *self, GdaSqlO
midgard_query_holder_get_value (MIDGARD_QUERY_HOLDER (_sj->right_property), &rval);
/* Set qualifier as default table and alias */
- const gchar *qualifier = midgard_query_column_get_qualifier (MIDGARD_QUERY_COLUMN (_sj->right_property), NULL);
+ const gchar *qualifier= NULL;
+ qualifier = midgard_query_column_get_qualifier (MIDGARD_QUERY_COLUMN (_sj->right_property), NULL);
MidgardQueryProperty *qproperty = midgard_query_column_get_query_property (MIDGARD_QUERY_COLUMN (_sj->right_property), NULL);
gchar *table_name = (gchar *) qualifier;
@@ -440,22 +441,37 @@ gboolean __query_select_data_add_joins (MidgardSqlQuerySelectData *self, GdaSqlO
g_value_unset (&rval);
join->expr = expr;
- join->position = ++executor->priv->joinid;
/* Add right qualifier to targets */
gda_sql_select_from_take_new_join (from , join);
GdaSqlSelectTarget *s_target = gda_sql_select_target_new (GDA_SQL_ANY_PART (from));
s_target->table_name = g_strdup (table_name);
- s_target->as = g_strdup (qualifier);
- //gda_sql_select_from_take_new_target (from, s_target);
-
- /* Set target expression */
- GdaSqlExpr *texpr = gda_sql_expr_new (GDA_SQL_ANY_PART (s_target));
- GValue *tval = g_new0 (GValue, 1);
- g_value_init (tval, G_TYPE_STRING);
- g_value_set_string (tval, table_name);
- texpr->value = tval;
- s_target->expr = texpr;
+ s_target->as = g_strdup (qualifier);
+
+ GSList *l = NULL;
+ guint i = 0;
+ gboolean duplicate = FALSE;
+ for (l = from->targets; l != NULL; l = l->next, i++) {
+ if (g_str_equal(((GdaSqlSelectTarget*)(l->data))->as, qualifier)) {
+ duplicate = TRUE;
+ break;
+ }
+ }
+
+ if (duplicate) {
+ join->position = i;
+ } else {
+ gda_sql_select_from_take_new_target (from, s_target);
+ join->position = g_slist_length(from->targets)-1;
+
+ /* Set target expression, cause we set new target */
+ GdaSqlExpr *texpr = gda_sql_expr_new (GDA_SQL_ANY_PART (s_target));
+ GValue *tval = g_new0 (GValue, 1);
+ g_value_init (tval, G_TYPE_STRING);
+ g_value_set_string (tval, table_name);
+ texpr->value = tval;
+ s_target->expr = texpr;
+ }
}
return TRUE;
@@ -687,6 +703,12 @@ _midgard_sql_query_select_data_executable_iface_execute (MidgardExecutable *ifac
g_object_unref (qprop);
MidgardDBObjectClass *dbklass = storage->priv->klass;
const gchar *table_alias = midgard_query_column_get_qualifier (MIDGARD_QUERY_COLUMN(columns[i]), NULL);
+ if (!table_alias || (table_alias && *table_alias == '\0')) {
+ g_set_error (error, MIDGARD_EXECUTION_ERROR, MIDGARD_EXECUTION_ERROR_COMMAND_INVALID_DATA,
+ "Expected non null qualifier for '%s'",
+ midgard_query_column_get_name (MIDGARD_QUERY_COLUMN(columns[i]), NULL));
+ return;
+ }
const gchar *property_table = midgard_core_class_get_table (dbklass);
const gchar *property_field = midgard_core_class_get_property_colname (dbklass, property);
View
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+npm install vows
+npm install gir
+# Create symlink in case npm is too old
+ln -s default node_modules/gir/build/Release
@@ -0,0 +1,19 @@
+
+var vows = require('vows'),
+ assert = require('assert');
+
+var gir = require('gir');
+gir.init();
+
+var Midgard, gir, config, mgd;
+Midgard = gir.load('Midgard');
+Midgard.init();
+
+config = new Midgard.Config();
+config.__set_property__("dbdir", "/tmp");
+config.__set_property__("dbtype", "SQLite");
+config.__set_property__("database", "node_gir");
+
+mgd = new Midgard.Connection();
+
+exports.cnc = mgd;
View
@@ -0,0 +1,27 @@
+
+var vows = require('vows'),
+ assert = require('assert');
+
+var gir = require('gir');
+gir.init();
+
+var Midgard, gir, config, mgd;
+Midgard = gir.load('Midgard');
+Midgard.init();
+
+config = new Midgard.Config();
+config.__set_property__("dbdir", "/tmp");
+config.__set_property__("dbtype", "SQLite");
+config.__set_property__("database", "node_gir");
+
+mgd = new Midgard.Connection();
+
+var suite = vows.describe('Midgard.Config');
+suite.addBatch({
+ 'Open Config' : {
+ topic: mgd.__call__('open_config', config),
+ 'should be true': function (topic) {
+ assert.isTrue(topic);
+ }
+ }
+}).run();
View
@@ -0,0 +1,30 @@
+
+var vows = require('vows'),
+ assert = require('assert');
+
+var gir = require('gir');
+gir.init();
+
+var Midgard, gir, config, mgd;
+Midgard = gir.load('Midgard');
+Midgard.init();
+
+var mgd = require('./midgard_connection');
+
+console.log(mgd.cnc);
+
+var suite = vows.describe('Midgard.Config');
+suite.addBatch({
+ 'Create Storage' : {
+ 'Base' : {
+ topic : function () {
+ s = new Midgard.Storage();
+ console.log(mgd.cnc);
+ return s.__call__('create_base_storage', mgd.cnc);
+ },
+ 'created' : function (topic) {
+ assert.isTrue (topic)
+ }
+ }
+ }
+}).run();

0 comments on commit 2045c83

Please sign in to comment.