• Welcome to Valhalla Legends Archive.
 

Development of an Object-Relational tool

Started by Banana fanna fo fanna, August 23, 2003, 10:48 PM

Previous topic - Next topic

Banana fanna fo fanna

Well, I've finally got a pretty stressful web programming job. I have many, many PHP horror stories to tell you (use templates!!!), but I'll spare them for now.

It would be a hell of a lot easier if I could serialize objects to SQL and read them back again. I can already create tables and insert data, but reading the data back is a problem. It's easy to read back until you hit another object or an array, at which point you have to perform a join.

My question is...how can I take a standard sql SELECT resultset (key/value pairs, however, you don't know which column belongs to which table) and deserialize that into objects? Each object class has metadata embedded in it, that is, it knows what its variable names are and their types.

Any suggestions? I can port from most semi-high level languages, pseudo, and plain old advice would just be great.

Thanks a ton.

Camel

Your question as is appears to be a little vague so I'm not sure if this is what you want; perhaps you could post specificly what you're trying to do or even your workaround code, it would help me to understand the problem better.

For a standard array, you might try INSERTing as as string that can be read back through an eval() statement. For example, INSERT INTO table SET something = "Some => 'Thing', Blah => 'Whatever'"; and then after you SELECT, you can do eval('$array = array(' . $row[column] . ')');
You could then write a function to break down an array into a string in said form.

Banana fanna fo fanna

That's a good idea, however, I'd kind of like this to look as "natural" as possible, y'know?

Camel

#3
Fine, I'll try again.

<sql>
   <table name="arrays" primary_key="id">
       <!-- This is the table for all of your arrays, minus the data. -->
       <column name="id" type=number />
       <column name="name" type=text />
   </table>
   <table name="arraydata">
       <!-- Array data goes in this table. -->
       <column name="id" type=number link="[arrays].[id]" />
       <column name="name" type=text />
       <column name="value" type=text />
   </table>
</sql>


You could could subclass this further using the same concept.

[edit] Sp.

Banana fanna fo fanna

Interesting idea...perhaps I will do it that way except express them as Python objects...

If I combined Python, web programming, databases, and XML...I'd have a buzzword...and I don't want that :)

Camel

How would XML have anything to do with it? I only used XML to simplify the explanation...

Adron

So you mean that xml description can't be directly read into a tool that produces the application? How eww! ;)

Banana fanna fo fanna

I was thinking of an api along the lines of:


class SQLObjectL:
___def fromResultset(self,resultset):
_______"Deserialize ourself from a resultset. Call this on any complex members of this class, unless marked otherwise."
_______pass
____def insertStatement(self):
_______"Get a SQL INSERT statement. Call on all complex members and return a semicolon-separated list of INSERTS."
_______pass
____def generateCreate(self):
_______"Make a CREATE TABLE statement"
_______pass