static void _midgard_query_constraint_instance_init (GTypeInstance *instance, gpointer g_class) { MidgardQueryConstraint *self = MIDGARD_QUERY_CONSTRAINT (instance); self->priv = g_new (MidgardQueryConstraintPrivate, 1); self->priv->property_value = NULL; self->priv->op = NULL; self->priv->storage = NULL; self->priv->holder = NULL; }
static void _midgard_query_constraint_finalize (GObject *object) { MidgardQueryConstraint *self = MIDGARD_QUERY_CONSTRAINT (object); g_free (self->priv->op); self->priv->op = NULL; g_free (self->priv); self->priv = NULL; parent_class->finalize (object); }
static PHP_METHOD(midgard_query_constraint, set_operator) { char *operator = NULL; int operator_len = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &operator, &operator_len) == FAILURE) { return; } MidgardQueryConstraint *constraint = MIDGARD_QUERY_CONSTRAINT(__php_gobject_ptr(getThis())); zend_bool result = (zend_bool) midgard_query_constraint_set_operator(constraint, operator); RETURN_BOOL(result); }
static PHP_METHOD(midgard_query_constraint, get_operator) { if (zend_parse_parameters_none() == FAILURE) return; MidgardQueryConstraint *constraint = MIDGARD_QUERY_CONSTRAINT(__php_gobject_ptr(getThis())); const gchar *operator = midgard_query_constraint_get_operator(constraint); if (!operator) { return; } RETURN_STRING(operator, 1); }
static PHP_METHOD(midgard_query_constraint, set_property) { zval *z_property = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &z_property, php_midgard_query_property_class) == FAILURE) { return; } MidgardQueryConstraint *constraint = MIDGARD_QUERY_CONSTRAINT(__php_gobject_ptr(getThis())); MidgardQueryProperty *property = MIDGARD_QUERY_PROPERTY(__php_gobject_ptr(z_property)); zend_bool result = midgard_query_constraint_set_property(constraint, property); RETURN_BOOL(result); }
static PHP_METHOD(midgard_query_constraint, set_storage) { zval *z_storage = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &z_storage, php_midgard_query_storage_class) == FAILURE) { return; } MidgardQueryConstraint *constraint = MIDGARD_QUERY_CONSTRAINT(__php_gobject_ptr(getThis())); MidgardQueryStorage *storage = MIDGARD_QUERY_STORAGE(__php_gobject_ptr(z_storage)); zend_bool result = midgard_query_constraint_set_storage(constraint, storage); RETURN_BOOL(result); }
static PHP_METHOD(midgard_query_constraint, get_storage) { if (zend_parse_parameters_none() == FAILURE) return; MidgardQueryConstraint *constraint = MIDGARD_QUERY_CONSTRAINT(__php_gobject_ptr(getThis())); MidgardQueryStorage *storage = midgard_query_constraint_get_storage(constraint); if (!storage) { return; } object_init_ex(return_value, php_midgard_query_storage_class); MGD_PHP_SET_GOBJECT(return_value, storage); // ^^^ no need to call constructor, as constructor doesn't do any magic here }
void _midgard_query_constraint_add_conditions_to_statement (MidgardQueryExecutor *executor, MidgardQueryConstraintSimple *constraint_simple, GdaSqlStatement *stmt, GdaSqlExpr *where_expr_node) { MidgardQueryConstraint *self = MIDGARD_QUERY_CONSTRAINT (constraint_simple); //GdaConnection *cnc = executor->priv->mgd->priv->connection; MidgardDBObjectClass *dbklass = NULL; if (self->priv->storage && (self->priv->storage != MIDGARD_QUERY_EXECUTOR (executor)->priv->storage)) { dbklass = self->priv->storage->priv->klass; MQE_SET_TABLE_ALIAS (executor, self->priv->storage); } if (!dbklass) dbklass = executor->priv->storage->priv->klass; g_return_if_fail (dbklass != NULL); /* Get table */ //const gchar *table = midgard_core_class_get_table (dbklass); /* Get field name */ GValue field_value = {0, }; midgard_query_holder_get_value (MIDGARD_QUERY_HOLDER (MIDGARD_QUERY_CONSTRAINT (constraint_simple)->priv->property_value), &field_value); GdaSqlStatementSelect *select = stmt->contents; GdaSqlExpr *top_where, *where, *expr; GdaSqlOperation *top_operation, *cond; GValue *value; if (where_expr_node) { top_where = where_expr_node; top_operation = top_where->cond; } else { top_where = select->where_cond; top_operation = top_where->cond; } where = gda_sql_expr_new (GDA_SQL_ANY_PART (top_operation)); top_operation->operands = g_slist_append (top_operation->operands, where); cond = gda_sql_operation_new (GDA_SQL_ANY_PART (where)); where->cond = cond; cond->operator_type = self->priv->op_type; /* Create table_alias.field name */ gchar *table_alias_field; expr = gda_sql_expr_new (GDA_SQL_ANY_PART (cond)); table_alias_field = midgard_core_query_compute_constraint_property (executor, MIDGARD_QUERY_CONSTRAINT (constraint_simple)->priv->storage, g_value_get_string (&field_value)); if (!table_alias_field) g_warning ("Null table.field alias for given '%s'", g_value_get_string (&field_value)); /* TODO, handle error case when table_alias_field is NULL */ g_value_take_string ((value = gda_value_new (G_TYPE_STRING)), table_alias_field); expr->value = value; cond->operands = g_slist_append (cond->operands, expr); expr = gda_sql_expr_new (GDA_SQL_ANY_PART (cond)); /* Create value */ GValue val = {0, }; midgard_query_holder_get_value (MIDGARD_QUERY_CONSTRAINT (constraint_simple)->priv->holder, &val); /*GType v_type = G_VALUE_TYPE (&val); //FIXME, create parameter name::type */ //GValue *dval = gda_value_new (G_TYPE_STRING); //g_value_transform (&val, dval); //expr->param_spec = gda_sql_param_spec_new (dval); //expr->param_spec->g_type = v_type; expr->value = gda_value_new (G_TYPE_STRING); __set_expression_value (expr->value, &val); g_value_unset (&val); cond->operands = g_slist_append (cond->operands, expr); /* increase executor's constraints number */ executor->priv->n_constraints++; }