MySQL DAL questions

82 views
Skip to first unread message

Dave S

unread,
Aug 1, 2016, 5:00:31 PM8/1/16
to web2py-users
Trying to translate someone else's MySQL CREATE TABLE into a define_table, which of course means I need to know what to do with 2 left shoes.

1) Can I translate a BIT field as a 'boolean'?

2) For legacy tables, does a keyed table work when the ID-like field on the MySQL side is a VARCHAR marked as the PRIMARY KEY, and there is UNIQUE INDEX set based on that field?

Thanks.

/dps

Dave S

unread,
Aug 3, 2016, 4:09:58 PM8/3/16
to web2py-users

Also, mapping BIGINT to bigint seems straightforward enough, but do TINYINT, SMALLINT, and INT all map to integer?

/dps
 

Niphlod

unread,
Aug 3, 2016, 5:09:09 PM8/3/16
to web2py-users
if you need to access legacy tables, all you need - effectively - is not creating the tables: just parse the results to proper python-corresponding types. Same thing applies with inserting/updating: TINYINT, SMALLINT, INT are just integers...with a "forced" lower/upper limit. Those translates to a proper model as 

Field('thefield', 'integer', requires=IS_INT_IN_RANGE(...,....))

but that only helps you if you need to do validation before inserting. Python will manage all of those as integers anyways.
As for the primary key, as long it's unique, everything works, EXCEPT something at reaaaally high level as the grid. 
Another thing to count for is that web2py assumes a "modern" model in which you CAN'T choose the PK beforehand (this maps to an autoincrementing integer usually): using db.thetable.insert(...) could be troublesome in some edge cases.

Dave S

unread,
Aug 3, 2016, 6:59:37 PM8/3/16
to web2py-users


On Wednesday, August 3, 2016 at 2:09:09 PM UTC-7, Niphlod wrote:
if you need to access legacy tables, all you need - effectively - is not creating the tables: just parse the results to proper python-corresponding types. Same thing applies with inserting/updating: TINYINT, SMALLINT, INT are just integers...with a "forced" lower/upper limit. Those translates to a proper model as 

Field('thefield', 'integer', requires=IS_INT_IN_RANGE(...,....))

but that only helps you if you need to do validation before inserting. Python will manage all of those as integers anyways.
As for the primary key, as long it's unique, everything works, EXCEPT something at reaaaally high level as the grid. 
Another thing to count for is that web2py assumes a "modern" model in which you CAN'T choose the PK beforehand (this maps to an autoincrementing integer usually): using db.thetable.insert(...) could be troublesome in some edge cases.



Thanks for the clarification.  I'm hoping to avoid doing inserts, and instead just make queries as a restful front for the data.  Consumer rather than provider.

/dps

Dave S

unread,
Aug 3, 2016, 7:58:40 PM8/3/16
to web2py-users
On Wednesday, August 3, 2016 at 3:59:37 PM UTC-7, Dave S wrote:
[...]
Thanks for the clarification.  I'm hoping to avoid doing inserts, and instead just make queries as a restful front for the data.  Consumer rather than provider.


Uh, oh ... that table name includes '.' ; does that mean parse_as_rest() won't be able to handle the pattern and URL?

/dps
 

Massimo Di Pierro

unread,
Aug 6, 2016, 3:12:45 AM8/6/16
to web2py-users
The raw names can include "." but the web2py names cannot possibly contain a "." in the name.

Dave S

unread,
Aug 8, 2016, 10:37:55 PM8/8/16
to web...@googlegroups.com


On Saturday, August 6, 2016 at 12:12:45 AM UTC-7, Massimo Di Pierro wrote:
The raw names can include "." but the web2py names cannot possibly contain a "." in the name.

Yes, I'm trying the rname feature.  At the moment, I'm still in the "setting the table" stage, but I hope to get a URL to the real DB soon, so I can test how well I respond to coaching.

(I'm not fond of how the DB was set up, but I didn't get asked to design it.)

/dps

 
Reply all
Reply to author
Forward
0 new messages