DbFieldInfo Interface

This interface is used to describe and provide common implementations to any field in a table. To access values and update values in a database, you must use DbField interface.

Check for table's field compatibility

Table compatibility, as defined in Gda Vala Extensions, is a set of tests to garanty one field is able to copy data to another.

The following tests are performed when F.compatible(F2) is called:

  1. Values' type are equal

  2. If F can be null, then F2 must allow null values too

This codes checks for compatibility between two table's fields definition.
Table a = new Table ();
a.name = "user2"; // set to a database's table name
a.connection = connection;
a.update (); // Get definition from database metadata
Table b = new Table ();
b.name = "users"; // set to a database's table name
b.connection = connection;
b.update (); // Get definition from database metadata
var aid = a.get_field ("id");
var bid = b.get_field ("id");
if (aid.compatible (bid))
	stdout.printf (@"You can copy data from field  $(aid.name) to table $(bid.name)");
			

Check for table's field definition equivalent

Field equivalency, as defined in Gda Vala Extensions, is a set of tests to verify that most important properties and attributes are present in other field. Then is recomended to check equivalency of a hard coded definition, agains a database table's field that had been getted from a table using update() method.

The following tests are performed when F.equivalent(F2) is called:

  1. Name are equal

  2. Type are equal

  3. If one of the following attributes of type DbFieldInfo.Attribute are pressent, they must be pressent in the other field: PRIMARY_KEY, UNIQUE, CHECK, CAN_BE_NULL

Field equivalency are performed by equivalent() method defined in DbFieldInfo interface.

This codes checks for equivalency between a template and a database field.
Table a = new Table ();
a.name = "pre-defined";
create_definition (a); // See at Table class to see how define a table
Table b = new Table ();
b.name = "users"; // set to a database's table name
b.connection = connection;
b.update (); // Get definition from database metadata
aid = a.get_field ("id");
bid = b.get_field ("id");
if (aid.equivalent (bid))
	stdout.printf (@"Database field $(bid.name) is based on template field $(aid.name)");