On Thursday, October 23, 2014 7:11:19 AM UTC-7, Niphlod wrote:
>
> you can't reference fields from different databases. 
>
>
To work around that, you'd do a select on db1 to get the data you want, and 
then an update on db?

/dps

 

> On Thursday, October 23, 2014 3:07:50 PM UTC+2, Carl Petersen wrote:
>>
>> Hello,
>>
>> I'm trying to reference the auth_user table in one database from a field 
>> definition for a table in a different database.  Hopefully the code below 
>> will clarify:
>>
>> db1 = 
>> DAL('postgres://user:password@host1/database1',pool_size=1,check_reserved=None,migrate=False)
>> db = 
>> DAL('postgres://user:password@host/database',pool_size=1,check_reserved=['all'],migrate=False)
>>
>> db1.executesql("set search_path to 'devxref','public';")
>> db.executesql("set search_path to 'po','xref','dw','public';")
>>
>> *db*.define_table('x_vendor',
>>     Field('source_vendor_dwid',db.d_supplier_source),
>>     Field('source_vendor_id'),
>>     Field('source_system_dwid',db.d_source),
>>     Field('source_system_id'),
>>     Field('gp_vendor_dwid',db.d_supplier_source),
>>     Field('gp_vendor_id'),
>>     Field('changed_date_time','datetime',
>>           default=request.now, update=request.now, writable=False),
>>     Field('changed_user_id','reference *db1*.auth_user',
>>           default=auth.user_id, update=auth.user_id, writable=False),
>>     format='%(x_vendor)s')
>>
>> I get the following errors in the dump:
>>
>> Traceback (most recent call last):
>>   File "/opt/web-apps/web2py/gluon/restricted.py", line 224, in restricted
>>     exec ccode in environment
>>   File "/opt/web-apps/web2py/applications/wspg/controllers/x_vendor.py" 
>> <https://dc1ux544/admin/default/edit/wspg/controllers/x_vendor.py>, line 
>> 127, in <module>
>>   File "/opt/web-apps/web2py/gluon/globals.py", line 392, in <lambda>
>>     self._caller = lambda f: f()
>>   File "/opt/web-apps/web2py/applications/wspg/controllers/x_vendor.py" 
>> <https://dc1ux544/admin/default/edit/wspg/controllers/x_vendor.py>, line 85, 
>> in add
>>     if form.process().accepted:
>>   File "/opt/web-apps/web2py/gluon/html.py", line 2303, in process
>>     self.validate(**kwargs)
>>   File "/opt/web-apps/web2py/gluon/html.py", line 2240, in validate
>>     if self.accepts(**kwargs):
>>   File "/opt/web-apps/web2py/gluon/sqlhtml.py", line 1671, in accepts
>>     self.vars.id = self.table.insert(**fields)
>>   File "/opt/web-apps/web2py/gluon/dal.py", line 9320, in insert
>>     ret =  self._db._adapter.insert(self, self._listify(fields))
>>   File "/opt/web-apps/web2py/gluon/dal.py", line 1354, in insert
>>     query = self._insert(table, fields)
>>   File "/opt/web-apps/web2py/gluon/dal.py", line 2903, in _insert
>>     values = ','.join(self.expand(v, f.type) for f, v in fields)
>>   File "/opt/web-apps/web2py/gluon/dal.py", line 2903, in <genexpr>
>>     values = ','.join(self.expand(v, f.type) for f, v in fields)
>>   File "/opt/web-apps/web2py/gluon/dal.py", line 1555, in expand
>>     return str(self.represent(expression, field_type))
>>   File "/opt/web-apps/web2py/gluon/dal.py", line 3079, in represent
>>     return BaseAdapter.represent(self, obj, fieldtype)
>>   File "/opt/web-apps/web2py/gluon/dal.py", line 2016, in represent
>>     ftype = self.db[p[0]][p[2]].type
>>   File "/opt/web-apps/web2py/gluon/dal.py", line 8512, in __getitem__
>>     return self.__getattr__(str(key))
>>   File "/opt/web-apps/web2py/gluon/dal.py", line 8522, in __getattr__
>>     return ogetattr(self, key)
>> AttributeError: 'DAL' object has no attribute 'db1'
>>
>>
>>
>> Any assistance would be greatly appreciated.
>>
>> Thanks!
>>
>> Carl
>>
>

-- 
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