Re: [SQLObject] mapping DB to legacy python objects
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: Ian B. <ia...@co...> - 2004-03-24 23:25:49
|
On Mar 24, 2004, at 4:31 PM, Charles Brandt wrote: > I'm in the process of trying to add persistence using SQLObject to some > python objects in an existing project. I'm hitting a snag since the > object > has (private-ish) variables that begin with "__". When I try simply > creating corresponding columns in the database with SQLObject, ie: > __remote_address = STringCol(length=32) > __creation_time = DateTimeCol(default=SQLBuilder.func.NOW()) > > I get: > AssertionError: Name must be SQL-safe (letters, numbers, underscores): > '_StickySessions__remote_address' > > I was hoping to avoid renaming them, since that would mean over riding > all > methods that access that data too. Seemed rather brittle, but is > looking > like the best option at this point. > > I also tried to just create an alias pointing to the variable like > this: > remote_address = STringCol(length=32) > __remote_address = remote_address > but that didn't work either. No, that definitely won't work. SQLObject uses the attribute name as a heuristic to determine the database column name, when you don't give a column name explicitly. So renaming the attribute will only confuse things (and I think actually make SQLObject expect two columns in that case. You can rename the column explicitly with the colName keyword argument to *Col, I think -- this is specifically meant to keep you from having to propagate bad legacy names. Or if your attributes are the legacy names, you can keep those from propagating to your database. You might still hit that assertion error, though I'm not quite sure why -- maybe the leading underscores. You could probably disable that assertion if that's the case. SQLObject should be a little smarter about that, and probably put quotes of some sort around the name if it isn't SQL-safe. Ian |