Data handling

A single Value — Assorted functions for dealing with GValue values
Custom data validation
GdaHolder controls
GdaSet controls
GdaDataProxy controls
Advanced GdaDataSelect usage
Automatic re-run of the SELECT statement
Invalid parameters
Blobs — Binary data and BLOBs handling
GdaDataModel — Data model interface
GdaDataSelect — Base class for data models returned by the execution of a SELECT statement
GdaDataModel columns — Management of GdaDataModel column attributes
GdaDataModelIter — Data model iterator
GdaDataModelImport — Importing data from a string or a file
GdaDataPivot — A data model for data summarisation
GdaDataAccessWrapper — Offers a random access on top of a cursor-only access data model
GdaDataModelArray — An implementation of GdaDataModel based on a GArray
GdaRow — Individual row of a GdaDataModelArray object
GdaDataModelLdap — GdaDataModel to extract LDAP information
GdaDataModelBdb — GdaDataModel to access Berkeley DB database contents
GdaDataModelDir — GdaDataModel to list files in filesystem
GdaDataProxy — Proxy to hold modifications for any GdaDataModel, providing the GdaDataModel interface itself
GdaDataComparator — Simple data model's contents comparison
Implementing your own data model
Virtual methods
Signalling changes

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, YOUR_DOMAIN, YOUR_CODE, "NULL values are not allowed!");
        else if (g_value_get_int (value) >= 5)
                g_set_error (&error, YOUR_DOMAIN, YOUR_CODE, "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