Data handling

Gda Value
Custom data validation
GdaHolder controls
GdaSet controls
GdaDataProxy controls
Advanced GdaDataSelect usage
Automatic re-run of the SELECT statement
Invalid parameters
GdaBlobOp
GdaDataModel
GdaDataSelect
GdaColumn
GdaDataModelIter
GdaDataModelImport
GdaDataAccessWrapper
GdaDataModelArray
GdaRow
GdaDataModelBdb
GdaDataModelDir
GdaDataProxy
GdaDataComparator

Libgda being a data oriented library, data handling is a central point of the library:

Custom data validation

Libgda allows the programmer to specify some rules of his own to control data changes (for example business rules). This section details the various control points, how to implement them, and how or when they are invoked.

GdaHolder controls

The GdaHolder object holds a single value (as a GValue). When that value is to be modified, using for example gda_holder_set_value(), then the proposed new value's validation process is executed:

  1. it is determined if the proposed new value is of the correct type and if it respects the holder's policy (for example a NULL value won't be accepted if the holder can't be NULL). If the proposed value does not respect the policy, then the value change will be rejected

  2. the "validate-change" signal is emitted. If any handler for this signal returns a pointer to a filled GError structure, then the signal's propagation is stopped and the value change will be rejected.

An example illustrating how to use the "validate-change" signal is:

static GError *
my_validate_change_cb (GdaHolder *h, const GValue *value, gpointer data)
{
        GError *error = NULL;

        /* for example check that value is inferior to 5 and not NULL */
        if (gda_value_is_null (value)) 
                g_set_error (&error, 0, 0, "NULL values are not allowed!");
        else if (g_value_get_int (value) >= 5)
                g_set_error (&error, 0, 0, "Value sould be inferior to 5");

        return error;
}

{
        GdaHolder *holder;
        GError *error = NULL;
        [...]
        g_signal_connect (G_OBJECT (holder), "validate-change",
                G_CALLBACK (my_validate_change_cb), NULL);
        if (! gda_holder_set_value (holder, value, &error)) {
                g_print ("Error: %s\n", error->message);
                g_error_free (error);
		[...]
	}
}
      

GdaHolder's value change control

GdaSet controls

The GdaSet object is an ordered list (or vector) of values, each represented by a GdaHolder object. One can place controls at two key events:

  • When any value of a GdaHolder changes, where the "validate-holder-change" signal is emitted. If any handler for this signal returns a pointer to a filled GError structure, then the signal's propagation is stopped and the value change will be rejected. This key event allows one to control each holder's value change as they occur.

  • When the gda_set_is_valid() method is called, the "validate-set" signal is emitted. If any handler for this signal returns a pointer to a filled GError structure, then the signal's propagation is stopped and the calling method will return the generated error. This key event allows one to control the validity of a set of values altogether (for example before writing to a table).

GdaSet's changes controls

GdaDataProxy controls

The GdaDataProxy data model allows one to store temporary modifications to a data model, and then apply (write to the proxied data model) those modifications row by row. Before applying any row modification, the GdaDataProxy data model emits the "validate-row-changes" signal, and if handler for this signal returns a pointer to a filled GError structure, then the signal's propagation is stopped and the row's modifications are not applied.

GdaDataProxy's changes controls