/** * midgard_query_constraint_set_operator: * @self: #MidgardQueryConstraint instance * @op: operator to associate with constraint * * Check midgard_query_constraint_new() for valid operator types. * * Returns: %TRUE on success, %FALSE otherwise * Since: 10.05 */ gboolean midgard_query_constraint_set_operator (MidgardQueryConstraint *self, const gchar *op) { g_return_val_if_fail (self != NULL, FALSE); GdaSqlOperatorType op_type; if (!__query_constraint_operator_is_valid (op, &op_type)) return FALSE; self->priv->op = g_strdup (op); self->priv->op_type = op_type; return TRUE; }
/** * midgard_sql_query_constraint_set_operator: * @self: #MidgardSqlQueryConstraint instance * @op: operator to associate with constraint * @error: pointer to store returned error * * Check midgard_query_constraint_new() for valid operator types. * * Since: 10.05.6 */ void midgard_sql_query_constraint_set_operator (MidgardSqlQueryConstraint *self, const gchar *op, GError **error) { g_return_if_fail (self != NULL); GdaSqlOperatorType op_type; if (!__query_constraint_operator_is_valid (op, &op_type)) { g_set_error (error, MIDGARD_VALIDATION_ERROR, MIDGARD_VALIDATION_ERROR_VALUE_INVALID, "Invalid '%s' operator", op); return; } self->priv->op = g_strdup (op); self->priv->op_type = op_type; }
/** * midgard_query_constraint_new: * @property: #MidgardQueryProperty instance * @op: constraint operator * @holder: #MidgardQueryHolder instance * @storage: (allow-none): optional #MidgardQueryStorage to use with constraint * * Valid @op operators are: '=', '<', '>', '!=', '<>', '<=', '>=', 'LIKE', 'NOT LIKE', 'IN', 'NOT IN' * * Returns: new #MidgardQueryConstraint instance, or %NULL on failure * Since: 10.05 */ MidgardQueryConstraint * midgard_query_constraint_new (MidgardQueryProperty *property, const gchar *op, MidgardQueryHolder *holder, MidgardQueryStorage *storage) { g_return_val_if_fail (property != NULL, NULL); g_return_val_if_fail (op != NULL, NULL); g_return_val_if_fail (holder != NULL, NULL); GdaSqlOperatorType op_type; if (!__query_constraint_operator_is_valid (op, &op_type)) return NULL; MidgardQueryConstraint *self = g_object_new (MIDGARD_TYPE_QUERY_CONSTRAINT, "property", property, "operator", op, "holder", holder, NULL); /* Allow NULL storage */ if (storage) midgard_query_constraint_set_storage (self, storage); return self; }
static void __midgard_query_constraint_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) { MidgardQueryConstraint *self = (MidgardQueryConstraint *) (object); GdaSqlOperatorType op_type; gchar *op; switch (property_id) { case MIDGARD_QUERY_CONSTRAINT_PROPERTY: midgard_query_constraint_set_property (self, g_value_get_object (value)); break; case MIDGARD_QUERY_CONSTRAINT_OP: op = (gchar *)g_value_get_string (value); if (__query_constraint_operator_is_valid (op, &op_type)) { g_free (self->priv->op); self->priv->op = g_strdup (op); self->priv->op_type = op_type; } break; case MIDGARD_QUERY_CONSTRAINT_HOLDER: if (self->priv->holder) g_object_unref (self->priv->holder); self->priv->holder = g_value_dup_object (value); break; case MIDGARD_QUERY_CONSTRAINT_STORAGE: midgard_query_constraint_set_storage (self, g_value_get_object (value)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (self, property_id, pspec); break; } }
/* Validable iface */ static void _midgard_sql_query_constraint_validable_iface_validate (MidgardValidable *iface, GError **error) { g_return_if_fail (iface != NULL); MidgardSqlQueryConstraint *self = MIDGARD_SQL_QUERY_CONSTRAINT (iface); self->priv->is_valid = FALSE; /* Column, TODO */ /* Storage, TODO */ /* Value, TODO */ /* Operator */ if (!__query_constraint_operator_is_valid (self->priv->op, NULL)) { g_set_error (error, MIDGARD_VALIDATION_ERROR, MIDGARD_VALIDATION_ERROR_TYPE_INVALID, "Invalid operator type '%s'", self->priv->op); return; } MIDGARD_SQL_QUERY_CONSTRAINT (self)->priv->is_valid = TRUE; return; }