I tried the following:
import datetime
from pydal.parsers import for_type
def _blob(self,value):
return to_native(to_bytes(value))
def _time(self, value):
if isinstance(value, datetime.time):
return value.time()
return datetime.time(int(value[0:2]), int(value[2:4]))
BLOBPARSER = for_type(_blob)
TIMEPARSER = for_type(_time)
if SQLSRVER >= 2012:
ADAPTER = 'mssql4'
elif SQLSRVER >=2008:
ADAPTER = 'mssql3'
else:
ADAPTER = 'mssql'
db = DAL('%s://...'%(ADAPTER, ...))
db._adapter.parser._declared_parsers_['_blob'] = BLOBPARSER
db._adapter.parser._declared_parsers_['_time'] = TIMEPARSER
but it does not work
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "C:\Python2711\lib\site-packages\pydal\objects.py", line 2250, in
select
return adapter.select(self.query, fields, attributes)
File "C:\Python2711\lib\site-packages\pydal\adapters\base.py", line 762,
in select
return self._select_aux(sql, fields, attributes, colnames)
File "C:\Python2711\lib\site-packages\pydal\adapters\base.py", line 741,
in _select_aux
return processor(rows, fields, colnames, cacheable=cacheable)
File "C:\Python2711\lib\site-packages\pydal\adapters\base.py", line 305,
in parse
for row in rows
File "C:\Python2711\lib\site-packages\pydal\adapters\base.py", line 231,
in _parse
value = self.parse_value(value, fit, ft, blob_decode)
File "C:\Python2711\lib\site-packages\pydal\adapters\base.py", line 198,
in parse_value
return self.parser.parse(value, field_itype, field_type)
File "C:\Python2711\lib\site-packages\pydal\parsers\__init__.py", line 101
, in parse
return self.registered[field_itype](value, field_type)
File "C:\Python2711\lib\site-packages\pydal\parsers\__init__.py", line 76,
in __call__
return self.call(value, field_type)
File "C:\Python2711\lib\site-packages\pydal\parsers\__init__.py", line 73,
in _call
return self.f(self.parser, value)
File "C:\Python2711\lib\site-packages\pydal\parsers\base.py", line 37, in
_blob
return to_native(b64decode(to_bytes(value)))
File "C:\Python2711\lib\base64.py", line 77, in b64decode
raise TypeError(msg)
TypeError: Incorrect padding
which I kind of expected.
Is there a way to modify the parser before the adapter is used to define
the db without adding to the source?.
Thanks,
Denes
On Thursday, January 18, 2018 at 11:14:31 AM UTC-5, DenesL wrote:
>
> Hello
>
> in an older version of web2py I had code to create a custom adapter.
> This code does not work in the latest version of web2py so I tried to
> update it, but web2py has changed so much internally that I am having a bit
> of trouble.
> Any hints on how to rewrite the following are appreciated:
>
> from pydal.adapters import ADAPTERS
> if SQLSRVER == '2008' or SQLSRVER == '2008R2':
> from pydal.adapters.mssql import MSSQL3Adapter
> class MSSQLSBO(MSSQL3Adapter):
> def parse_blob(self, value, field_type):
> return value
> def parse_time(self, value, field_type):
> if not isinstance(value, datetime.time):
> value = datetime.time(int(value[0:2]), int(value[2:4]))
> return value
> elif SQLSRVER == '2012':
> from pydal.adapters.mssql import MSSQL4Adapter
> class MSSQLSBO(MSSQL4Adapter):
> def parse_blob(self, value, field_type):
> return value
> def parse_time(self, value, field_type):
> if not isinstance(value, datetime.time):
> value = datetime.time(int(value[0:2]), int(value[2:4]))
> return value
> else:
> from pydal.adapters.mssql import MSSQL2Adapter
> class MSSQLSBO(MSSQL2Adapter):
> def parse_blob(self, value, field_type):
> return value
> def parse_time(self, value, field_type):
> if not isinstance(value, datetime.time):
> value = datetime.time(int(value[0:2]), int(value[2:4]))
> return value
> ADAPTERS['mssqlsbo'] = MSSQLSBO
>
> Thank you,
> Denes
>
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.