In my quest to get default values out of the Postgres metadata (the default
values are given as a string representation), SQLBuilder.const would see the
best way to go (since some things can't be eval'ed). For instance,
Postgress represents a default of "current_date" internally as
"('now'::text)::date":
>>> from SQLObject.SQLBuilder import *
>>> now = getattr(const, "('now'::text)::date")
>>> now
('now'::text)::date
>>> two = getattr(const, '2')
>>> two
2
>>> foo = getattr(const, "'foo'")
>>> foo
'foo'
So far seems just what I need.
However at object creation time the constants all get parens tacked onto
them, e.g:
INSERT INTO disc_info (purchase_date, shelf_space, disc_count, disc_id,
release_year, media_id, disc_title, price, lent_to, comments, id) VALUES
(('now'::text)::date(), 1.0(), 1(), 3, '1996', NULL, '', '10.00'(), '', '', 3)
Setting a value manually in the new statement does work as expected:
di = DiscInfo.new(disc=disc,
purchaseDate=getattr(SQLBuilder.const, "('now'::text)::date"),
shelfSpace=getattr(SQLBuilder.const, '1'),
discTitle='', releaseYear='1996', media=None, lentTo='', comments='')
results in
INSERT INTO disc_info (shelf_space, media_id, disc_count, disc_id,
release_year, purchase_date, disc_title, price, lent_to, comments, id)
VALUES (1, NULL, 1(), 3, '1996', ('now'::text)::date, '', '10.00'(), '', '',
6)
Do I misunderstand SQLBuilder.const?
Dave Cook
|