[gnome-db] question: in memory table representation: please help
- From: Neil Zanella <nzanella gmail com>
- To: GNOME-DB List <gnome-db-list gnome org>
- Subject: [gnome-db] question: in memory table representation: please help
- Date: Tue, 26 Oct 2004 21:18:19 -0600
Hello,
With regards to the following link:
http://www.gnome-db.org/docs/libgda/libgda-gda-util.html
I need to create an in memory representation of an SQL table,
which happens to be just what GdaTable claims to do. That is,
I want to model the table itself in memory, and not the data it
contains. So, how would I model the following?
CREATE TABLE X (
a VARCHAR(16),
b VARCHAR(64) NOT NULL,
c INTEGER NOT NULL,
d VARCHAR(64) NOT NULL,
e VARCHAR(8096),
PRIMARY KEY (a,b),
UNIQUE(c,d),
UNIQUE(d,e),
FOREIGN KEY (b, c) REFERENCES Y
ON UPDATE CASCADE ON DELETE CASCADE,
FOREIGN KEY (catDesc) REFERENCES Z
ON UPDATE CASCADE
CHECK (a != d)
);
The API is missing some comments and I am really trying to guess:
So I could do:
GdaTable *x = gda_table_new("X");
Then I find methods gda_table_new_from_model() and
gda_table_add_field(). I assume the first method is for generic models,
not just SQL models, so I skip it and move on to gda_table_add_field():
since my tables are flat relational tables which are not object oriented, I
most likely don't need a model, I guess. So then:
void gda_table_add_field (GdaTable *table,
const GdaFieldAttributes *fa);
So I must define 5 fields a, b, c,d, e, and set attributes for them?
Fair enough...
assuming each field has it's own GdaFieldAttributes (i.e. no two fields in two
different tables will share GdaFieldAttributes, not even if they referene each
other), I proceed and try:
GdaFieldAttributes *a = gda_field_attributes_new();
gda_field_attributes_set_defined_size(a, 15);
gda_field_attributes_set_gdatype(a, GDA_VALUE_TYPE_STRING);
GdaFieldAttributes *b = gda_field_attributes_new();
gda_field_attributes_set_defined_size(b, 64);
gda_field_attributes_set_gdatype(b, GDA_VALUE_TYPE_STRING);
gda_field_attributes_set_allow_null(a, FALSE);
GdaFieldAttributes *c = gda_field_attributes_new();
gda_field_attributes_set_gdatype(c, GDA_VALUE_TYPE_INTEGER);
gda_field_attributes_set_allow_null(a, FALSE);
GdaFieldAttributes *d = gda_field_attributes_new();
gda_field_attributes_set_defined_size(d, 64);
gda_field_attributes_set_gdatype(d, GDA_VALUE_TYPE_STRING);
gda_field_attributes_set_allow_null(a, FALSE);
GdaFieldAttributes *e = gda_field_attributes_new();
gda_field_attributes_set_defined_size(e, 8096);
gda_field_attributes_set_gdatype(e, GDA_VALUE_TYPE_STRING);
gda_field_attributes_set_allow_null(a, FALSE);
...
gda_table_add_field(x, a);
gda_table_add_field(x, b);
gda_table_add_field(x, c);
gda_table_add_field(x, d);
gda_table_add_field(x, e);
But now what I don't understand is how to set unique keys. Cause I have
two of them? For primary keys, it seems like I can just:
gda_field_attributes_set_primary_key(x, a);
gda_field_attributes_set_primary_key(x, b);
so (a, b) is the primary key.
But I have two unique keys, so how could I possibly do it?
Same goes for foreign keys, there is more then one, so how
does the API support creating this in memory representation
of an SQL table if not this way?
And what about the "ON UPDATE DELETE/CASCADE" and CHECK
constraint? The former could be coded manually. The second, I guess
could also be checked manually. But how do I define two unique keys?
Thanks,
Neil
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]