Database Idea

Database Idea

Seing the wonders of Dia2Code, the ability to create a program skeleton by creating a UML diagram in Dia, has made we wonder wether this could be applied to database access too.

Although there are several Dia2SQL converters out there, that is not what i'm proposing. What i'm proposing is a program that converts an UML diagram to some data access classes, one for each table seems the most resonable to me.

This could be useful when doing any kind of programming involving a database, f.x consider the following UML diagram, and the (supposedly) created class.

No alternative to graphics, sorry

This is just a suggestion as to how it could be made. As you can see we need to kind of static system wide dbConnection object, that all the classes should use, how this should be handled i am not completely sure.

Another interesting field of exploration is the methods on the object, to find a user you could make getUserById, getUserByName ... but another thing might be much smarter: to use all the parameters of a table and just use the parameters you would like. This requires the arguments to have an default value so the method can determine which parameters were used - this could cause trouble. However, Python supports the *args parameter that just eats up all parameters, that would get rid of the default values. Something similar is possible in C using the va_args system and PHP could probably do it.

Another interesting possibility is the possibility of "row classes" f.x. the User class that could be useful, that is, instead of having a lot of setNameForId ( 5, "Guido van Rossum" ); you could just use userobject.setName ( "Guido van Rossum" ); other good uses for this could be iteration.

That is the basic things that i would like the system to do, a whole other thing is the way that merges should be handled, what should the following SQL query be translated into?

select users.name as name, firm.name as firm from users, firm where
users.id=firm.owner;