Thread: [SQLObject] SQLBuilder.const: parens get tacked on in insert?
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: David M. C. <da...@da...> - 2003-04-19 03:01:06
|
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 |
From: David M. C. <da...@da...> - 2003-04-20 00:46:54
|
On Fri, Apr 18, 2003 at 08:01:04PM -0700, David M. Cook wrote: > 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, I solved this for now by commenting out elif callable(self._default): return self._default() in Col.py. However, I suspect just commenting out code is just a good way to get into trouble later ;} Dave |
From: Ian B. <ia...@co...> - 2003-04-21 07:42:16
|
On Sat, 2003-04-19 at 19:46, David M. Cook wrote: > I solved this for now by commenting out > > elif callable(self._default): > return self._default() > > in Col.py. However, I suspect just commenting out code is just a good way > to get into trouble later ;} Oh, yes, that explains it. I put in a line to fix that (in CVS), at least for the case of SQLBuilder consts... maybe the callable() stuff should be taken out, and you just use a different keyword argument for dynamic defaults... Ian |
From: David M. C. <da...@da...> - 2003-04-21 08:03:22
|
On Mon, Apr 21, 2003 at 02:43:00AM -0500, Ian Bicking wrote: > Oh, yes, that explains it. I put in a line to fix that (in CVS), at > least for the case of SQLBuilder consts... maybe the callable() stuff > should be taken out, and you just use a different keyword argument for > dynamic defaults... Time to start checking out from CVS, then! Perhaps the implementation of a __call__ method could be moved down lower in the SQLExpression class hierarchy? Dave |
From: David M. C. <da...@da...> - 2003-04-21 10:09:24
|
On Mon, Apr 21, 2003 at 02:43:00AM -0500, Ian Bicking wrote: > Oh, yes, that explains it. I put in a line to fix that (in CVS), at > least for the case of SQLBuilder consts... maybe the callable() stuff Great, using SQLBuilder.const works for defaults now. I submitted a patch for this (also fixes the regexp that got munged.) Dave |