Chris Withers wrote:
> Hi Michael,
>
> Thanks for this, I thought I asked this separately but I can't find the
> mail now...
>
> How would you recommend I work this now in 0.5.8 until I can move to
> 0.6.0? (which will take some months :-S)
>
> I seem to remember you suggesting a custom type. Where can I find
> examples of those to work against?
>
> Has anyone (hi, list, talking to you too!) already done a custom type
> for this specific problem?

people do custom types for all sorts of things.  In the case of the
Decimal here I'd likely subclass sqlalchemy.databases.sqlite.SLNumeric
which should ensure that your own bind_processor() and result_processor()
methods can be called.  Or as in the doc below you can subclass TypeEngine
directly.

http://www.sqlalchemy.org/docs/05/reference/sqlalchemy/types.html#custom-types


>
> cheers,
>
> Chris
>
> Michael Bayer wrote:
>> fixed in r6859.  please don't use those crappy pysqlite converters.
>>
>>
>> On Feb 26, 2010, at 8:50 AM, Chris Withers wrote:
>>
>>> from sqlalchemy import create_engine
>>> from sqlalchemy.orm import sessionmaker
>>> from sqlalchemy.orm.session import Session
>>> from sqlalchemy.ext.declarative import declarative_base
>>> from sqlalchemy.schema import Column
>>> from sqlalchemy.types import String, Numeric, Integer
>>>
>>> import unittest
>>> from decimal import Decimal
>>>
>>> class Test(unittest.TestCase):
>>>
>>>    def test_truncate(self):
>>>        # setup
>>>        engine = create_engine("sqlite://")
>>>        self.Session = sessionmaker(
>>>            bind=engine,
>>>            autoflush=True,
>>>            autocommit=False
>>>            )
>>>        Base = declarative_base(bind=engine)
>>>        class MyModel(Base):
>>>            __tablename__ = 'test'
>>>            id = Column(Integer, primary_key=True)
>>>            value = Column(Numeric(precision=36,scale=12))
>>>        Base.metadata.create_all()
>>>        session = self.Session()
>>>
>>>        # precision=36 scale=12 should mean this can handle 12 decimal
>>> places
>>>        # and this has 12 decimal places.
>>>        session.add(MyModel(value="152.737826714556"))
>>>        session.commit()
>>>
>>>        obj = session.query(MyModel).one()
>>>
>>>        # this will fail with the output, it shouldn't
>>>        # Decimal("152.737826715") != Decimal("152.737826714556")
>>>        self.assertEqual(obj.value, Decimal("152.737826714556"))
>>
>
> --
> Simplistix - Content Management, Batch Processing & Python Consulting
>              - http://www.simplistix.co.uk
>
> --
> You received this message because you are subscribed to the Google Groups
> "sqlalchemy" group.
> To post to this group, send email to sqlalch...@googlegroups.com.
> To unsubscribe from this group, send email to
> sqlalchemy+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/sqlalchemy?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to