[gnome-db] Re: question: in memory table representation: please help



OK, unless I receive replies here is what I am going to do:

Code an interface (the view) in XML.
Code the SQL database schema in XML.
Code the controller (connecting the interface to the database) in XML.
Then I will use libxml to parse my files, so I don't need to do anything
but OO software engineering and leave all the other details in XML.
Isn't that cool? Just that I will use libgda to execute my queries,
since I couldn't seem to make sense of its "in memory table
representation" I will have to build my own from XML files.
Maybe I will even code SQL statements to be executed
on insert, update, and delete in XML, together with the
ones to construct views. XML seems powerful and
flexible. I think I will take that approach.

Best Regards,

Neil

On Wed, 27 Oct 2004 16:07:44 -0600, Neil Zanella <nzanella gmail com> wrote:
> Sorry, the link I meant to refer to is:
> 
> http://www.gnome-db.org/docs/libgda/libgda-GdaTable.html
> 
> How do I create an in memory object for the SQL table described below...
> (i.e. a copy of the table itself, not the data it contains).
> 
> Thanks,
> 
> Neil
> 
> 
> 
> On Tue, 26 Oct 2004 21:18:19 -0600, Neil Zanella <nzanella gmail com> wrote:
> > 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]