Mike,

Mike wrote:
> Hi,
>
> Here's what I'm doing. I have a timesheet application written in
> wxPython. It works, but I think it would work better if I changed the
> database calls into SA calls. There are 3 databases. I created one and
> the other two are pre-existing. The one I created is the one I store
> all the user entered data into. I read from the official accounting
> database and I read from a couple of views in the third database. The
> two databases I read from are for checking purposes to make sure that
> I am doing the calculations correctly in my program and also for
> authentication and certain bits of user data, such as employee number,
> name and such.
>
> Anyway, I dumped the close calls I had and put them in the OnExit
> method, which is something I've never used before. I'm not sure that I
> have that set up right, but at this point it doesn't matter. I am
> still receiving the same error.
>
> If I take all of my SA setup out of the wxPython code and stick it in
> my own module, it works. Here's what that looks like:
>
>
> <code>
>
> import ts_info
> from db_tables import Acct_Prefs, TimeEntries
> from sqlalchemy import Table
> from sqlalchemy.orm import mapper, sessionmaker
>
> # Connect to the database
> print 'connecting to MCISAccounting DB...'
> conn, engine, meta = ts_info.setupDB('acct')
>
> # Load the tables
> print 'loading tables...'
> entry_table = Table('tbl_TimeEntries', meta, autoload=True)
> prefs_table = Table('tbl_Acct_Prefs', meta, autoload=True)
>
> # Map the tables
> print 'mapping tables...'
> mapper(TimeEntries, entry_table)
> mapper(Acct_Prefs, prefs_table)
>
> # Create a session object
> print 'creating session...'
> Session = sessionmaker(bind=engine)
> session = Session()
>
> pref = self.session.query(Acct_Prefs).filter_by(empID=self.emp_id,
> pref_name='last_payPeriod').first()
> pref.pref_value = SomeValue
> self.session.commit()
>
> </code>
>
> For some weird reason, if I do those last three lines in one of my
> wxPython methods, I get an error. I know it has to be something really
> stupid, but I'm just not seeing it...
>
> Mike
>
>   
I did a small test based on the test/demo project I am working on.

Just duplicated the database and changed the application to read from 
one database and show a list of countries and to read/update from a 
second database.  I can view both without problem and update the 2nd db 
without getting an error.

The way I set them up is:
class BoaApp(wx.App):
    def OnInit(self):
       
        self.ConnectDb()
       
        self.main = demoFrame2db.create(None)
        self.main.Show()
        self.SetTopWindow(self.main)
        return True
   
    def OnExit(self):
        self.session.close_all()
        self.engine.dispose()
   
    def ConnectDb(self):
        # db 1
        database = u'C:/Dev/BoaTest04/dbsampleSAnew/database.sqldb'
        dburl = sa.engine.url.URL('sqlite', username=None, 
password=None, host=None, port=None, database=database)
        self.engine = sa.create_engine(dburl, encoding='utf8', echo=False)
        Session = sao.sessionmaker()
        Session.configure(bind=self.engine)
        self.session = Session()
       
        # db 2
        database2 = u'C:/Dev/BoaTest04/dbsampleSAnew/database2.sqldb'
        dburl = sa.engine.url.URL('sqlite', username=None, 
password=None, host=None, port=None, database=database2)
        self.engine2 = sa.create_engine(dburl, encoding='utf8', echo=False)
        Session2 = sao.sessionmaker()
        Session2.configure(bind=self.engine2)
        self.session2 = Session2()
       
    def Getds(self):
        return self.session

    def Getds2(self):
        return self.session2

In my primary frame I then do:
       self.theList.SetSession(wx.GetApp().Getds())
        self.theList.InitObjectListView()
        self.theList.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnItemSelected)

        # a list from a 2 db
        self.theList2.SetSession(wx.GetApp().Getds2())
        self.theList2.InitObjectListView()
 
when selecting items from theList I display some details and I can 
update these details and commit.

Maybe this helps, but maybe it just causes more confusion?

Werner

>
>
> On Aug 28, 10:29 am, "Werner F. Bruhin" <[EMAIL PROTECTED]> wrote:
>   
>> Mike,
>>
>> Mike wrote:
>>
>> ...
>>
>>     
>>> Does this work for multiple databases? This particular program I am
>>> working on will be connecting to 2 or 3 databases and a table or three
>>> in each of those. I'm pretty sure I have to create separate engines
>>> for each db and probably bind separate sessions for those.
>>>       
>> I don't think so, using sessions and engines I would think you have to
>> have one per database.
>>
>> You probably need to explain a bit more what you are doing with these
>> databases, i.e. are you moving data from one to the other, or are they
>> independent databases or ......
>>
>> Werner
>>     
> >
>
>
>   


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to