Thanks. That seems to work. Wouldn't it make sense for auto_import to look 
for all .table files though?

On Monday, 14 May 2012 19:00:08 UTC+1, Anthony wrote:
>
> I don't really understand the point of auto_import or what it does exactly 
>> but it does *NOT* read the database. Per the book it reads the metadata in 
>> the .table files (which your code is deleting 
>> with os.remove(dbfolder+"/test.table")).
>
>
> Correct, auto_import looks at the *.table files in the /databases folder, 
> not directly at the database. However, although he is deleting the 
> 'test.table' file, it should then get re-created with the subsequent 
> define_table call. The problem is that auto_import=True doesn't work when 
> you give a custom name to the .table metadata file. Instead, you have to 
> let web2py automatically generate the default .table file names, which is 
> what auto_import will look for. So, the following should work:
>
> db1 = DAL('sqlite://storage.sqlite', folder=dbfolder, auto_import=True)
> print(db1.tables)
>
>
> db1.executesql("DROP TABLE IF EXISTS test;")
> print(db1._timings)
> try:
>     os.remove(dbfolder + '/%s_test.table' %  db._uri_hash)
> except:
>     pass
>     
> db1.define_table('test', Field('testfield'), migrate=True)
> db1.commit()
> print(db1.tables)
>
>
> db2 = DAL('sqlite://storage.sqlite', folder=dbfolder, auto_import=True)
> print(db2.tables)
>
> Anthony
>

Reply via email to