That's great Andrew.  
BTW great to see that Anthony is helping - he is someone who really knows 
the nuts and bolts of web2py!



On Friday, 17 July 2020 08:05:40 UTC+1, Andrew Rogers wrote:
>
> Thanks for your response Villas. My reason for this approach is that i 
> have a lot of code that expects a table object and i am trying to avoid 
> having to modify it to handle the a different format.
>
> Anthony on Stack Exchange found my error. He said:
> "You probably also set DAL(..., lazy_tables=True), in which 
> case, db.define_table() returns None rather than a Table object, as the 
> table is not actually created until first accessed via db.tablename.
>
> Given your code, there is no benefit to setting lazy_tables=True, as all 
> tables are accessed (and therefore created) immediately after definition 
> anyway."
>
> On Thursday, 16 July 2020 at 03:43:40 UTC+10 villas wrote:
>
>> You don't mention...
>>
>>    - Which DB adapter you are using
>>    - Why just one of your tables is expected to be an in-memory table 
>>    and the others not
>>    - Why you don't simply maintain the list of tables in a list(), or 
>>    dict() or some other in-memory structure
>>    
>> In any case, maybe this idea might help...
>>
>> db = DAL("sqlite://storage.sqlite") # or whichever DB you are using
>> dbmemo = DAL("sqlite:memory")
>>
>> dbmemo.define_table('DatabaseModel', Field('TableName'))
>>
>> for t in db.tables:
>>     dbmemo.DatabaseModel.update_or_insert(TableName=t)
>>
>>
>> On Wednesday, 15 July 2020 07:45:36 UTC+1, Andrew Rogers wrote:
>>>
>>> This code working fine but now it fails because the db.define_table() 
>>> returns None.
>>>
>>> table = db.define_table('DatabaseModel', Field('TableName'))  # This is 
>>> not working now
>>> for t in db.tables:
>>>     table.update_or_insert(TableName=t)
>>>
>>> The only thing that I think I have changed that might have affected it 
>>> was setting migrate = false in appconfig.ini. I have changed it back 
>>> but to no avail. 
>>>
>>> What could stop db.define_table from returning a table?
>>>
>>> (I am using this to create an in-memory table which I populate with a 
>>> list of actual tables.)
>>>
>>> Thanks.
>>>
>>> PS: 
>>> https://stackoverflow.com/questions/62908908/under-what-circumstances-would-db-define-table-return-none
>>>
>>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/b3dcebaa-7aee-4e25-ab8f-fea7b28b86c5o%40googlegroups.com.

Reply via email to