try this:

from guon.sql import Expression

db.define_table(.....,Field(...,default=Expression('CURRENT_DATE')),....)

On Aug 27, 9:19 pm, Adrian Klaver <[email protected]> wrote:
> On Friday 27 August 2010 5:42:04 pm Bruno Rocha wrote:
>
>
>
> > Looking sql.py I found:
>
> > 'notnull': 'NOT NULL DEFAULT %(default)s'
>
> > If I understand it well, that could be yor solution.
>
> > SQL_DIALECTS = {    'sqlite': {        'boolean': 'CHAR(1)',
> > 'string': 'CHAR(%(length)s)',        'text': 'TEXT',
> > 'password': 'CHAR(%(length)s)',        'blob': 'BLOB',
> > 'upload': 'CHAR(%(length)s)',        'integer': 'INTEGER',
> > 'double': 'DOUBLE',        'decimal': 'DOUBLE',        'date': 'DATE',
> >        'time': 'TIME',        'datetime': 'TIMESTAMP',        'id':
> > 'INTEGER PRIMARY KEY AUTOINCREMENT',        'reference': 'INTEGER
> > REFERENCES %(foreign_key)s ON DELETE %(on_delete_action)s',
> > 'lower': 'LOWER(%(field)s)',        'upper': 'UPPER(%(field)s)',
> >  'is null': 'IS NULL',        'is not null': 'IS NOT NULL',
> > 'extract': "web2py_extract('%(name)s',%(field)s)",        'left join':
> > 'LEFT JOIN',        'random': 'Random()',        'notnull': 'NOT NULL
> > DEFAULT %(default)s',        'substring':
> > 'SUBSTR(%(field)s,%(pos)s,%(length)s)',        'primarykey': 'PRIMARY
> > KEY (%s)'        },
>
> Yes and no. That is how the DEFAULT clause is constructed using the string
> passed to the default argument in Field()
> ex: Field('grade_date','date',default='2010/8/27',required=True,notnull=True)
> becomes;
> grade_date DATE NOT NULL DEFAULT '2010-08-27'
>
> The problem is CURRENT_DATE is not a string but an SQL function. If I include 
> it
> as a string then the default becomes the string literal 'CURRENT_DATE'. If I 
> do
> not quote it as string then Python complains because it is not a declared
> variable.
>
> Thanks,
> --
> Adrian Klaver
> [email protected]

Reply via email to