yes sqlite

On Jun 18, 3:30 am, Massimo Di Pierro <massimo.dipie...@gmail.com>
wrote:
> I need to think about this. The sum(...) is performed at the db level
> and therefore - on sqlite -  it is computed as float. The result
> should be converted back to decimal anyway.
>
> You are using sqlite, correct?
>
> On Jun 17, 6:15 pm, apple <simo...@gmail.com> wrote:
>
>
>
>
>
>
>
> > Here is some test code. It prints the type of testfield as decimal;
> > and the type of summary(sumtest) as float.
>
> >  model:
>
> >    db.define_table('test',
> >     Field('testfield', 'decimal(8,2)'))
>
> > controller:
>
> >     db.test.insert(testfield=3.2)
> >     db.test.insert(testfield=7.8)
> >     db.commit()
> >     test1=db(db.test.testfield<5).select()[0]
> >     print(test1.testfield, type(test1.testfield))
> >     sumtest=db.test.testfield.sum()
> >     summary=db(db.test.testfield>0).select(sumtest).first()
> >     print(summary(sumtest), type(summary(sumtest)))
>
> > On Jun 17, 9:56 pm, Massimo Di Pierro <massimo.dipie...@gmail.com>
> > wrote:
>
> > > unless there is a bug, Field('name','decimal(5,2)') will always treat
> > > the number as decimal.Decimal at the web2py level. The problem is how
> > > is it stored in the database. If the database supports decimal is it
> > > stored accordingly. If the database does not (sqlite) that it is
> > > converted to float and stored as float.
>
> > > I am not sure I answered the question. perhaps I misunderstood.
>
> > > On Jun 17, 12:54 pm, apple <simo...@gmail.com> wrote:
>
> > > > Yes sqlite.
>
> > > > The book says "SQLite does not handle the decimal type so internally
> > > > we treat it as a double". However wouldn't it be logical to convert it
> > > > back to decimal if that is what my tabledef says?
>
> > > > On Jun 17, 6:40 pm, Anthony <abasta...@gmail.com> wrote:
>
> > > > > On Friday, June 17, 2011 1:13:26 PM UTC-4, apple wrote:
>
> > > > > > I am using the DAL to aggregate SUM a decimal field and the result 
> > > > > > is
> > > > > > a float. Shouldn't the DAL keep it in same format as the underlying
> > > > > > field?
>
> > > > > Are you using SQLite? As far as I know, it doesn't support decimal 
> > > > > fields,
> > > > > so I think web2py has to treat them as doubles. 
> > > > > Seehttp://web2py.com/book/default/chapter/06#DAL,-Table,-Field.
>
> > > > > Anthony

Reply via email to