コード例 #1
0
ファイル: postgresql.py プロジェクト: jmcfarlane/chula
    def connect(self):
        if self.conn is None:
            uri = 'pg:%(session_username)s@%(session_host)s/%(session_db)s'
            uri = uri % self.config
            try:
                self.conn = DataStoreFactory(uri, self.config.session_password)
            except Exception, ex:
                self.log.error('Unable to connect', exc_info=True, extra=EXTRA)

            try:
                self.cursor = self.conn.cursor()
            except Exception, ex:
                self.log.error('Cursor error', exc_info=True, extra=EXTRA)
コード例 #2
0
ファイル: test_functions.py プロジェクト: jmcfarlane/chula
 def test_datatore_tuple(self):
     conn = DataStoreFactory('pg:chula@localhost/chula_test', 'chula')
     cursor = conn.cursor(type='tuple')
     try:
         cursor.execute('SELECT * FROM cars LIMIT 1;')
         values = cursor.fetchone()
         self.assertEquals(values, (1, 'Honda', 'Civic'))
     finally:
         conn.rollback()
         conn.close()
コード例 #3
0
ファイル: test_functions.py プロジェクト: jmcfarlane/chula
 def test_datatore_basic(self):
     conn = DataStoreFactory('pg:chula@localhost/chula_test', 'chula')
     cursor = conn.cursor()
     try:
         cursor.execute('SELECT * FROM cars LIMIT 1;')
         keys = cursor.fetchone().keys()
         keys.sort()
         self.assertEquals(keys, ['make', 'model', 'uid'])
     finally:
         conn.rollback()
         conn.close()
コード例 #4
0
ファイル: postgresql.py プロジェクト: jmcfarlane/chula
class Backend(base.Backend):
    def __init__(self, config, guid):
        super(Backend, self).__init__(config, guid)
        self.cursor = None
        self.log = logger.Logger(config).logger('chula.session.postgresql')

        self.connect()

    def connect(self):
        if self.conn is None:
            uri = 'pg:%(session_username)s@%(session_host)s/%(session_db)s'
            uri = uri % self.config
            try:
                self.conn = DataStoreFactory(uri, self.config.session_password)
            except Exception, ex:
                self.log.error('Unable to connect', exc_info=True, extra=EXTRA)

            try:
                self.cursor = self.conn.cursor()
            except Exception, ex:
                self.log.error('Cursor error', exc_info=True, extra=EXTRA)

            if not self.conn is None and not self.cursor is None:
                self.log.debug('Successfull connection to postgresql')
コード例 #5
0
ファイル: test_functions.py プロジェクト: jmcfarlane/chula
 def test_invalid_cursor(self):
     conn = DataStoreFactory('pg:chula@localhost/chula_test', 'chula')
     self.assertRaises(UnsupportedUsageError, conn.cursor, type='list')
     conn.close()