DAL, legacy Database, field name as python keyword

133 views
Skip to first unread message

xaver

unread,
May 13, 2016, 5:55:40 AM5/13/16
to web2py-users
Hi,

I'm using web2py DAL for a legacy database which has a Table users with a field named "pass".
I've used the "rname" to alias the "pass" field.
unfortunately doesn't work.

db.define_table('users',
Field('uid', 'integer'),
Field('name','string'),
Field('pass', rname='passwd'),
Field('mail','string'),
Field('theme','string'),
Field('signature','string'),
Field('signature_format','string'),
Field('created','integer'),
Field('access','integer'),
Field('login','integer'),
Field('status','integer'),
Field('timezone','string'),
Field('language','string'),
Field('picture','integer'),
Field('init','string'),
Field('data','blob'),
primarykey=['uid'],
migrate=False)
Traceback (most recent call last):
  File "/home/sas/PycharmProjects/pydal/index.py", line 8, in <module>
    Field('pass', rname='passwd'),
  File "/home/sas/virtualpy/local/lib/python2.7/site-packages/pydal/objects.py", line 1438, in __init__
    'use rname for "funny" names' % fieldname)
SyntaxError: Field: invalid field name: pass, use rname for "funny" names

Another question; I do I define with(define_table) only some field of the DB-Table.
Because commenting out the "pass" field  it throws many errors which I do not completely understand:

Traceback (most recent call last):
  File "/home/sas/PycharmProjects/pydal/index.py", line 41, in <module>
    users = db().select(db.users.ALL)
  File "/home/sas/virtualpy/local/lib/python2.7/site-packages/pydal/objects.py", line 2020, in select
    return adapter.select(self.query, fields, attributes)
  File "/home/sas/virtualpy/local/lib/python2.7/site-packages/pydal/adapters/base.py", line 1296, in select
    return self._select_aux(sql,fields,attributes)
  File "/home/sas/virtualpy/local/lib/python2.7/site-packages/pydal/adapters/base.py", line 1277, in _select_aux
    return processor(rows,fields,self._colnames,cacheable=cacheable)
  File "/home/sas/virtualpy/local/lib/python2.7/site-packages/pydal/adapters/base.py", line 1767, in parse
    for row in rows]
  File "/home/sas/virtualpy/local/lib/python2.7/site-packages/pydal/adapters/base.py", line 1677, in _parse
    value = self.parse_value(value, ft, blob_decode)
  File "/home/sas/virtualpy/local/lib/python2.7/site-packages/pydal/adapters/base.py", line 1527, in parse_value
    return self.parsemap[key](value,field_type)
  File "/home/sas/virtualpy/local/lib/python2.7/site-packages/pydal/adapters/base.py", line 1592, in parse_blob
    return base64.b64decode(str(value))
  File "/usr/lib/python2.7/base64.py", line 76, in b64decode
    raise TypeError(msg)
TypeError: Incorrect padding

Thks.

Xaver

Anthony

unread,
May 13, 2016, 8:21:04 AM5/13/16
to web2py-users

I'm using web2py DAL for a legacy database which has a Table users with a field named "pass".
I've used the "rname" to alias the "pass" field.
unfortunately doesn't work.

db.define_table('users',
Field('uid', 'integer'),
Field('name','string'),
Field('pass', rname='passwd'),

Field('passwd', rname='pass')

 

Field('data','blob'),
primarykey=['uid'],
migrate=False)

  File "/home/sas/virtualpy/local/lib/python2.7/site-packages/pydal/adapters/base.py", line 1592, in parse_blob
    return base64.b64decode(str(value))
  File "/usr/lib/python2.7/base64.py", line 76, in b64decode
    raise TypeError(msg)
TypeError: Incorrect padding

The DAL base64 encodes/decodes blob fields, but presumably the blob data stored in your legacy database is not base64 encoded. As an alternative, you could define a custom field type that doesn't do the encoding/decoding:

http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#Custom-Field-types--experimental-

Anthony

Saverio Scavelli

unread,
May 13, 2016, 9:08:37 AM5/13/16
to web...@googlegroups.com
Many Thks. It looks nice:)
I'll give a try

bye
 

--
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 a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/R8K1RvyoXA0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages