Bugs item #1012374, was opened at 2004-08-19 22:08
Message generated for change (Comment added) made by phd
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=540672&aid=1012374&group_id=74338
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: General
Group: SQLObject from repository
>Status: Closed
>Resolution: Fixed
Priority: 5
Private: No
Submitted By: Andrew Bennetts (spiv)
>Assigned to: Oleg Broytmann (phd)
Summary: Cannot use DEFAULT values defined in SQL.
Initial Comment:
Given a table with a column like:
CREATE TABLE Foo (
datecreated timestamp NOT NULL DEFAULT
(CURRENT_TIMESTAMP AT TIME ZONE 'UTC'),
....
)
There is no way to utilise that default value when
constructing a Foo. e.g., if that is the only column
in Foo, it should be possible in Python to do:
f1 = Foo()
But even though the default value for the DateTimeCol's
default argument is NoDefault, SQLObject still insists
that an argument is passed to Foo's constructor.
For backwards compatibility, probably what should be
done is define a new magic value, e.g.
'NoDefaultRequired', so that the Foo class could be
defined as:
class Foo(SQLObject):
datecreated = DateTimeCol(notNull=True,
default=NoDefaultRequired)
----------------------------------------------------------------------
>Comment By: Oleg Broytmann (phd)
Date: 2008-03-07 17:47
Message:
Logged In: YES
user_id=4799
Originator: NO
Starting with SQLObject 0.9.4 one can define defaultSQL for a column and
do not pass a value to the constructor.
----------------------------------------------------------------------
Comment By: Viktor Ferenczi (complex)
Date: 2005-03-13 05:58
Message:
Logged In: YES
user_id=142612
Do you generate your table class from the SQL database?
(See "Automatic Class Generation" in the SQLObject manual.)
I don't know that such a complex default value could be imported by
SQLObject from the SQL database schema, but it's technically possible.
If you don't use automatic class generation, then try to define a default
value in your python class, such as:
from sqlobject import *
class Foo(SQLObject):
dt=DateTimeCol(default=func.NOW())
foo=Foo()
print foo.dt
This does not work with PySQLite, but you can use
datetime.datetime.today() instead.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=540672&aid=1012374&group_id=74338
|