Hi Ben, Inside my app folder I do have the table defined, but not in my script (accessing the db outside web2py). I thought that the folder path reference solved this (*). Should i add the define table in my script? Thanks and regards, Jon.
(*) I guess that’s why .table files are kept even when SQLite is no longer usted. El El vie, 8 feb 2019 a las 14:28, Ben Duncan <linux...@gmail.com> escribió: > Did you set up the db_define table for the database in models. > > For example, the accounting package I am working on for our Supreme Court > has and external postgres database. > From the DDL, I've created, for example, the "ship to code" file (we reuse > for something else) > > --------------------------------------------------------------------------------------------------------------------- > db.define_table('ar_ship_code', > Field('company_number', type='reference company.company_number', > ondelete='CASCADE'), > Field('code', type='string', length=10), > Field('short_desc', type='string', length=20), > Field('description', type='string', length=255), > Field('notes', type='text'), > primarykey=['company_number','code'], > migrate=False) > > --------------------------------------------------------------------------------------------------------------------------- > > For each table you want to access, you will need a "db.define_table" entry > in the model directory. > > Hope this helps > *Ben Duncan* > DBA / Chief Software Architect > Mississippi State Supreme Court > Electronic Filing Division > > > On Fri, Feb 8, 2019 at 7:17 AM Jon Subscripted <jonsubscripti...@gmail.com> > wrote: > >> Hi everyone, >> I'm trying to access the data stored in my app db from a different piece >> of software (apart from my web2py app). But I get an error AttributeError. >> >> Based on the manual: >> >> >> http://www.web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#Using-DAL-without-define-tables >> >> I used the code below (from IDLE): >> >> import sys >> >> sys.path.append(r'C:\Users\Jon\Downloads\web2py_src\web2py\gluon') >> >> from gluon import DAL >> >> dbpath = >> r'C:\Users\Jon\Downloads\web2py_src\web2py\applications\xakemate_scratch\databases' >> problemsuri = 'mysql://root:web2py@localhost/xakemate' >> pos = 'test_position' >> >> db = DAL(problemsuri,folder=dbpath,auto_import=True) >> query = (db.problem.fen == pos) >> problem = db(query).select(orderby=db.problem.id).first() >> >> I get the following error: >> >> Traceback (most recent call last): >> File "<pyshell#33>", line 1, in <module> >> query = (dbproblems.problem.fen == posFEN) >> File "C:\Python27\lib\site-packages\gluon\dal.py", line 7150, in >> __getattr__ >> return ogetattr(self, key) >> AttributeError: 'DAL' object has no attribute 'problem' >> >> From what I understood the tables should be auto-imported and thus known >> to my code. Why is it not finding the table? >> >> In addition to that I've got a couple of questions: >> >> 1st Should I import PYDAL (from pydal import DAL) or GLUON.DAL (as I >> did)? >> >> 2nd Even when using the db different from SQLite should we point to >> "applications/myapp/databases"? >> >> Thanks in advance, Jon. >> >> >> <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail> >> Libre >> de virus. www.avast.com >> <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail> >> <#m_-6215750885323799383_m_5787271047422858639_m_-5898545075541849496_DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2> >> >> -- >> 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. >> > -- > 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. > -- 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.