Michael Bayer ha scritto:
> read the thread, no idea what a space has to do with anything. can
> you be more specific.
>
pySQLite read the first word of the column spec to find the converter.
Here is a full example:
import decimal
from pysqlite2 import dbapi2 as sqlite
from sqlalchemy import *
db = create_engine('sqlite:///',
connect_args={'detect_types': sqlite.PARSE_DECLTYPES})
conn = db.contextual_connect()
# To avoid the conversion to float
sqlite.register_converter("NUMERIC", lambda s: s)
class Decimal(TypeEngine):
def __init__(self, precision=10, length=2):
self.precision = precision
self.length = length
def get_col_spec(self):
if 1:
# Make sure to add a spece after the first string
prefix = 'NUMERIC '
else:
prefix = 'NUMERIC'
return prefix + '(%(precision)s, %(length)s)' % {'precision':
self.precision, 'length' : self.length}
def convert_bind_param(self, value, dialect):
return str(value)
def convert_result_value(self, value, dialect):
return decimal.Decimal(value)
metadata = BoundMetaData(db)
a = Table(
'a', metadata,
Column('x', Decimal(7, 3)),
Column('y', Decimal(10, 5)),
)
metadata.create_all()
i = a.insert()
conn.execute(i, x=decimal.Decimal('12.42'), y=decimal.Decimal('1'))
s = a.select()
print conn.execute(s).fetchone()
Whitout the space after 'NUMERIC', pysqlite does not call the converter
I have registered.
Regards Manlio Perillo
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---