dbapi.py
changeset 4768 430b89aed996
parent 4721 8f63691ccb7f
child 4850 bd640b137f50
equal deleted inserted replaced
4767:74b8e39d4825 4768:430b89aed996
   396         except KeyError:
   396         except KeyError:
   397             pass
   397             pass
   398 
   398 
   399     def check(self):
   399     def check(self):
   400         """raise `BadSessionId` if the connection is no more valid"""
   400         """raise `BadSessionId` if the connection is no more valid"""
       
   401         if self._closed is not None:
       
   402             raise ProgrammingError('Closed connection')
   401         self._repo.check_session(self.sessionid)
   403         self._repo.check_session(self.sessionid)
   402 
   404 
   403     def set_session_props(self, **props):
   405     def set_session_props(self, **props):
   404         """raise `BadSessionId` if the connection is no more valid"""
   406         """raise `BadSessionId` if the connection is no more valid"""
       
   407         if self._closed is not None:
       
   408             raise ProgrammingError('Closed connection')
   405         self._repo.set_session_props(self.sessionid, props)
   409         self._repo.set_session_props(self.sessionid, props)
   406 
   410 
   407     def get_shared_data(self, key, default=None, pop=False):
   411     def get_shared_data(self, key, default=None, pop=False):
   408         """return value associated to `key` in shared data"""
   412         """return value associated to `key` in shared data"""
       
   413         if self._closed is not None:
       
   414             raise ProgrammingError('Closed connection')
   409         return self._repo.get_shared_data(self.sessionid, key, default, pop)
   415         return self._repo.get_shared_data(self.sessionid, key, default, pop)
   410 
   416 
   411     def set_shared_data(self, key, value, querydata=False):
   417     def set_shared_data(self, key, value, querydata=False):
   412         """set value associated to `key` in shared data
   418         """set value associated to `key` in shared data
   413 
   419 
   414         if `querydata` is true, the value will be added to the repository
   420         if `querydata` is true, the value will be added to the repository
   415         session's query data which are cleared on commit/rollback of the current
   421         session's query data which are cleared on commit/rollback of the current
   416         transaction, and won't be available through the connexion, only on the
   422         transaction, and won't be available through the connexion, only on the
   417         repository side.
   423         repository side.
   418         """
   424         """
       
   425         if self._closed is not None:
       
   426             raise ProgrammingError('Closed connection')
   419         return self._repo.set_shared_data(self.sessionid, key, value, querydata)
   427         return self._repo.set_shared_data(self.sessionid, key, value, querydata)
   420 
   428 
   421     def get_schema(self):
   429     def get_schema(self):
   422         """Return the schema currently used by the repository.
   430         """Return the schema currently used by the repository.
   423 
   431 
   499         return self._repo.source_defs()
   507         return self._repo.source_defs()
   500 
   508 
   501     def user(self, req=None, props=None):
   509     def user(self, req=None, props=None):
   502         """return the User object associated to this connection"""
   510         """return the User object associated to this connection"""
   503         # cnx validity is checked by the call to .user_info
   511         # cnx validity is checked by the call to .user_info
       
   512         if self._closed is not None:
       
   513             raise ProgrammingError('Closed connection')
   504         eid, login, groups, properties = self._repo.user_info(self.sessionid,
   514         eid, login, groups, properties = self._repo.user_info(self.sessionid,
   505                                                               props)
   515                                                               props)
   506         if req is None:
   516         if req is None:
   507             req = self.request()
   517             req = self.request()
   508         rset = req.eid_rset(eid, 'CWUser')
   518         rset = req.eid_rset(eid, 'CWUser')
   519                 self.close()
   529                 self.close()
   520             except:
   530             except:
   521                 pass
   531                 pass
   522 
   532 
   523     def describe(self, eid):
   533     def describe(self, eid):
       
   534         if self._closed is not None:
       
   535             raise ProgrammingError('Closed connection')
   524         return self._repo.describe(self.sessionid, eid)
   536         return self._repo.describe(self.sessionid, eid)
   525 
   537 
   526     def close(self):
   538     def close(self):
   527         """Close the connection now (rather than whenever __del__ is called).
   539         """Close the connection now (rather than whenever __del__ is called).
   528 
   540 
   533         changes first will cause an implicit rollback to be performed.
   545         changes first will cause an implicit rollback to be performed.
   534         """
   546         """
   535         if self._closed:
   547         if self._closed:
   536             raise ProgrammingError('Connection is already closed')
   548             raise ProgrammingError('Connection is already closed')
   537         self._repo.close(self.sessionid)
   549         self._repo.close(self.sessionid)
       
   550         del self._repo # necessary for proper garbage collection
   538         self._closed = 1
   551         self._closed = 1
   539 
   552 
   540     def commit(self):
   553     def commit(self):
   541         """Commit any pending transaction to the database. Note that if the
   554         """Commit any pending transaction to the database. Note that if the
   542         database supports an auto-commit feature, this must be initially off. An
   555         database supports an auto-commit feature, this must be initially off. An