On Tuesday, May 23, 2017 at 12:25:27 PM UTC-7, Dave S wrote:
>
>
>
> On Tuesday, May 23, 2017 at 7:28:42 AM UTC-7, Lisandro wrote:
>>
>> I think I got it solved, I had to use another DAL parameter: table_hash
>>
>> If you look into databases folder, you will see that every .table file 
>> begins with a hash. 
>> That hash was initialy generated by web2py when the tables were created, 
>> the first time the models were run.
>> I think that web2py generates that hash using the connection string 
>> parameters, such as the db username used for the connection.
>>
>>
>> Anyway, here is what I did in APP2 to be able to connect to the APP1's 
>> database, using a different db username:
>>
>>
>> # gets the table_hash from the first .table file present in the databases 
>> folder
>> table_hash = None
>> databases_folder = CONFIG.path_web2py, 'applications', 'app1', 
>> 'databases')
>> for tablefile in os.listdir(databases_folder):
>>     if tablefile.endswith('.table'):
>>         table_hash = archivo.split('_')[0]
>>         break
>>
>> # connects to the DB using auto_import and table_hash
>> db_app1 = DAL('postgres://%s:%s@%s/%s' % ('otheruser', 'mypassword', 
>> 'localhost', 'george'),
>>     migrate=False,
>>     folder=databases_folder,
>>     auto_import=True,
>>     table_hash=table_hash)
>>
>>
>>
>>
>  
>
>> I couldn't find much in the documentation about table_hash:
>>
>> http://www.web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#DAL-signature
>>
>>
> Looking in gluon/packages/dal/pydal/base.py, the API documentation shows
>
>  table_hash: database identifier with .tables. If your connection hash
>                     change you can still using old .tables if they have 
> db_hash
>                     as prefix
>
>
>  
>

This seems to match http://pydal.readthedocs.io/en/latest/index.html, which 
is good, because Niphlod has warned that docstrings have gotten a bit buggy 
as they've aged.

/dps
 

>
>> Maybe some clarification about table_hash needs to be added in the 
>> section "Using DAL without define tables":
>>
>> http://www.web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#Using-DAL-without-define-tables
>>
>
> I never noticed it in the signature.  It doesn't seem to be needed often, 
> as you seem to be the first to discuss it while I've been reading the list.
>
>
>  
>
>> Anyway, I hope this helps if anywan runs into the same.
>>
>
> Good to have in the archives.
>  
>
>> Best regards,
>> Lisandro.
>>
>
>
> /dps
>
>

-- 
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to