Hi,
I have been able to access legacy databases that don't have an id
field. In the following example 'pointnumber' is the primary key, and
is unique. I was able to read values from this table with DAL. I used
the following model:
db2.define_table('statuspoint',
Field('pointnumber','integer'),
Field('pointname','string'),
Field('pointaccessarea','integer'),
Field('station','integer'),
Field('statefeatures','integer'),
Field('indication','integer'),
primarykey=['pointnumber'],
)
Some parts of web2py(such as SQLFORM.grid) appear to require the 'id'.
To allow this, I created a view in my database(mysql) to rename the
pointnumber field to id.
CREATE VIEW view_statuspoint AS
SELECT pointnumber id,pointname,pointaccessarea,
station,statefeatures,indication
from statuspoint;
The following model uses the view:
db2.define_table('view_statuspoint',
Field('id','integer'),
Field('pointname','string'),
Field('pointaccessarea','integer'),
Field('station','integer'),
Field('statefeatures','integer'),
Field('indication','integer'),
Field('dog_assignment_fko','integer'),
migrate=False
)
This allowed me to create a form with SQLFORM.grid and to update
records. That's all I've tested.
- Tom
On Oct 11, 9:04 am, Cory Coager <[email protected]> wrote:
> I have created some database tables externally to web2py. Does web2py
> require an id field for tables? The reason why I'm asking is, when I
> use the DAL to do an insert, web2py tries to retrieve the currval of
> the insert. Seeing how I don't have an id, this throws an exception.
> How should I handle this?