Werner, On Aug 28, 11:24 am, "Werner F. Bruhin" <[EMAIL PROTECTED]> wrote: > 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
Your code makes sense. I tried to create a small runnable example, but my sample works and my original does not. I'm not seeing the difference, but obviously something is wrong with my original code. I may have to just re-write it from scratch. I have a feeling that the end of the traceback has a clue, but I don't know how to read it: raise exceptions.DBAPIError.instance(statement, parameters, e, connection_invalidated=is_disconnect) sqlalchemy.exceptions.DatabaseError: (DatabaseError) internal error: None 'UPDATE [tbl_Acct_Prefs] SET pref_value=%(pref_value)s WHERE [tbl_Acct_Prefs].[empID] = %(tbl_Acct_Prefs_empID)s AND [tbl_Acct_Prefs].pref_name = % (tbl_Acct_Prefs_pref_name)s' {'pref_value': u'4', 'tbl_Acct_Prefs_pref_name': 'last_payPeriod', 'tbl_Acct_Prefs_empID': 258} Is it saying the connection to the database was dropped (i.e. "connection_invalidated=is_disconnect")? Mike --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---