An old thread - but I seem to have some problems using 'rowid' as id.

The statement Field('rowid', 'id') causes the error: <type 
'exceptions.SyntaxError'> invalid table/column name "rowid" is a "ALL" 
reserved SQL/NOSQL keyword

What could I be possibly doing wrong? (I tried rowid in lower as well as 
upper case)

Thanks.

=========================================================================

On Monday, July 15, 2013 at 4:35:03 AM UTC+5:30, Woody wrote:
>
> This may be something that is known by people with more experience than 
> me, but it took me a lot of experimenting to figure it out, so I thought I 
> would post it here so others will find it.
>
> I have legacy sqlite tables that do not have an id field.  This makes it 
> difficult to update them using SQLFORM.
>
> ROWID is a hidden auto-increment integer field that's included in all 
> sqlite tables.  You can make ROWID explicit by declaring it as the first 
> field in a table definition, then you can assign it the 'id' alias.
>
> Here's an example:
>
> db.define_table('my_sqlite_table',
>                 Field('ROWID', 'id'),
>                 Field('some_field', 'string'),
>                 Field('some_other_field', 'integer'),
>                 ........
>                 migrate=False)
>
> You can then use 'id' as a field name just as if your table had an actual 
> id field defined in the underlying table.  As far as I can tell, this hack 
> works without any problems.  The use of the 'id' alias is documented, but 
>  I haven't seen the use of 'ROWID' with the alias discussed.  This might be 
> something that could be tested and added to the documentation.
>

-- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to