コード例 #1
0
ファイル: dbprovider.py プロジェクト: aadidenko/umypony
    def set_transaction_mode(provider, connection, cache):
        assert not cache.in_transaction

        db_session = cache.db_session
        if db_session is not None and db_session.ddl:
            cursor = connection.cursor()
            cursor.execute("SHOW VARIABLES LIKE 'foreign_key_checks'")
            fk = cursor.fetchone()
            if fk is not None: fk = (fk[1] == 'ON')
            if fk:
                sql = 'SET foreign_key_checks = 0'
                if core.debug:
                    core.log_orm(sql)
                cursor.execute(sql)
            cache.saved_fk_state = bool(fk)
            cache.in_transaction = True

        cache.immediate = True

        if db_session is not None and db_session.serializable:
            cursor = connection.cursor()
            sql = 'SET TRANSACTION ISOLATION LEVEL SERIALIZABLE'
            if core.debug:
                core.log_orm(sql)
            cursor.execute(sql)
            cache.in_transaction = True
コード例 #2
0
ファイル: postgres.py プロジェクト: buddyli/android_intership
 def set_transaction_mode(provider, connection, optimistic):
     if optimistic:
         if core.debug: core.log_orm('SET AUTOCOMMIT = ON')
         connection.autocommit = True
     else:
         if core.debug: core.log_orm('SET TRANSACTION ISOLATION LEVEL READ COMMITTED')
         connection.set_isolation_level(extensions.ISOLATION_LEVEL_READ_COMMITTED)
コード例 #3
0
ファイル: postgres.py プロジェクト: buhtigexa/Nerit
 def connect(pool):
     if pool.con is None:
         if core.debug: log_orm('GET NEW CONNECTION')
         pool.con = pool.dbapi_module.connect(*pool.args, **pool.kwargs)
         if 'client_encoding' not in pool.kwargs:
             pool.con.set_client_encoding('UTF8')
     elif core.debug: log_orm('GET CONNECTION FROM THE LOCAL POOL')
     return pool.con
コード例 #4
0
 def create(table, provider, connection, created_tables=None):
     try:
         dbschema.Table.create(table, provider, connection, created_tables)
     except DatabaseError, e:
         if 'already exists' not in e.args[0]: raise
         if core.debug:
             log_orm('ALREADY EXISTS: %s' % e.args[0])
             log_orm('ROLLBACK')
         provider.rollback(connection)
コード例 #5
0
 def set_transaction_mode(provider, connection, optimistic):
     if optimistic:
         if core.debug: core.log_orm('SET AUTOCOMMIT = ON')
         connection.autocommit = True
     else:
         if core.debug:
             core.log_orm('SET TRANSACTION ISOLATION LEVEL READ COMMITTED')
         connection.set_isolation_level(
             extensions.ISOLATION_LEVEL_READ_COMMITTED)
コード例 #6
0
ファイル: sqlite.py プロジェクト: rlizana/pony
 def wrapper(*args, **kw):
     try:
         return func(*args, **kw)
     except:
         if core.debug:
             import traceback
             msg = traceback.format_exc()
             log_orm(msg)
         raise
コード例 #7
0
 def connect(pool):
     if pool.con is None:
         if core.debug: log_orm('GET NEW CONNECTION')
         pool.con = pool.dbapi_module.connect(*pool.args, **pool.kwargs)
         if 'client_encoding' not in pool.kwargs:
             pool.con.set_client_encoding('UTF8')
     elif core.debug:
         log_orm('GET CONNECTION FROM THE LOCAL POOL')
     return pool.con
コード例 #8
0
 def connect(pool):
     pid = os.getpid()
     if pool.pid != pid:
         pool.forked_pools.append((pool.cx_pool, pool.pid))
         pool.cx_pool = cx_Oracle.SessionPool(**pool.kwargs)
         pool.pid = os.getpid()
     if core.local.debug: log_orm('GET CONNECTION')
     con = pool.cx_pool.acquire()
     con.outputtypehandler = output_type_handler
     return con, True
コード例 #9
0
 def set_transaction_mode(provider, connection, cache):
     assert not cache.in_transaction
     db_session = cache.db_session
     if db_session is not None and db_session.serializable:
         cursor = connection.cursor()
         sql = 'SET TRANSACTION ISOLATION LEVEL SERIALIZABLE'
         if core.debug: log_orm(sql)
         cursor.execute(sql)
     cache.immediate = True
     if db_session is not None and (db_session.serializable or db_session.ddl):
         cache.in_transaction = True
コード例 #10
0
ファイル: oracle.py プロジェクト: timedcy/pony
 def set_transaction_mode(provider, connection, cache):
     assert not cache.in_transaction
     db_session = cache.db_session
     if db_session is not None and db_session.serializable:
         cursor = connection.cursor()
         sql = 'SET TRANSACTION ISOLATION LEVEL SERIALIZABLE'
         if core.debug: log_orm(sql)
         cursor.execute(sql)
     cache.immediate = True
     if db_session is not None and (db_session.serializable or db_session.ddl):
         cache.in_transaction = True
コード例 #11
0
 def release(provider, connection, cache=None):
     if cache is not None:
         db_session = cache.db_session
         if db_session is not None and db_session.ddl and cache.saved_fk_state:
             try:
                 cursor = connection.cursor()
                 sql = 'SET foreign_key_checks = 1'
                 if core.debug: log_orm(sql)
                 cursor.execute(sql)
             except:
                 provider.pool.drop(connection)
                 raise
     DBAPIProvider.release(provider, connection, cache)
コード例 #12
0
ファイル: sqlite.py プロジェクト: rlizana/pony
 def release(provider, connection, cache=None):
     if cache is not None:
         db_session = cache.db_session
         if db_session is not None and db_session.ddl and cache.saved_fk_state:
             try:
                 cursor = connection.cursor()
                 sql = 'PRAGMA foreign_keys = true'
                 if core.debug: log_orm(sql)
                 cursor.execute(sql)
             except:
                 provider.pool.drop(connection)
                 raise
     DBAPIProvider.release(provider, connection, cache)
コード例 #13
0
 def create(table, provider, connection, created_tables=None):
     commands = table.get_create_commands(created_tables)
     for i, sql in enumerate(commands):
         if core.debug: log_sql(sql)
         cursor = connection.cursor()
         try: provider.execute(cursor, sql)
         except DatabaseError, e:
             if e.exceptions[0].args[0].code == 955:
                 if core.debug: log_orm('ALREADY EXISTS: %s' % e.args[0].message)
                 if not i:
                     if len(commands) > 1:
                         log_orm('SKIP FURTHER DDL COMMANDS FOR TABLE %s\n' % table.name)
                     return
             else: raise
コード例 #14
0
ファイル: cockroach.py プロジェクト: wojteksuwala/pony
 def set_transaction_mode(provider, connection, cache):
     assert not cache.in_transaction
     db_session = cache.db_session
     if db_session is not None and db_session.ddl:
         cache.immediate = False
     if cache.immediate and connection.autocommit:
         connection.autocommit = False
         if core.local.debug:
             log_orm('SWITCH FROM AUTOCOMMIT TO TRANSACTION MODE')
     elif not cache.immediate and not connection.autocommit:
         connection.autocommit = True
         if core.local.debug: log_orm('SWITCH TO AUTOCOMMIT MODE')
     if db_session is not None and (db_session.serializable
                                    or db_session.ddl):
         cache.in_transaction = True
コード例 #15
0
 def connect(pool):
     con = pool.con
     if con is not None:
         if core.debug: core.log_orm('GET CONNECTION FROM THE LOCAL POOL')
         return con
     filename = pool.filename
     if filename != ':memory:' and not pool.create_db and not os.path.exists(filename):
         throw(IOError, "Database file is not found: %r" % filename)
     if core.debug: log_orm('GET NEW CONNECTION')
     pool.con = con = sqlite.connect(filename, isolation_level=None)
     con.text_factory = _text_factory
     con.create_function('power', 2, pow)
     con.create_function('rand', 0, random)
     if sqlite.sqlite_version_info >= (3, 6, 19):
         con.execute('PRAGMA foreign_keys = true')
     return con
コード例 #16
0
ファイル: sqlite.py プロジェクト: buhtigexa/Nerit
 def connect(pool):
     con = pool.con
     if con is not None:
         if core.debug: core.log_orm('GET CONNECTION FROM THE LOCAL POOL')
         return con
     filename = pool.filename
     if filename != ':memory:' and not pool.create_db and not os.path.exists(filename):
         throw(IOError, "Database file is not found: %r" % filename)
     if core.debug: log_orm('GET NEW CONNECTION')
     pool.con = con = sqlite.connect(filename, isolation_level=None)
     con.text_factory = _text_factory
     con.create_function('power', 2, pow)
     con.create_function('rand', 0, random)
     if sqlite.sqlite_version_info >= (3, 6, 19):
         con.execute('PRAGMA foreign_keys = true')
     return con
コード例 #17
0
 def set_transaction_mode(provider, connection, cache):
     assert not cache.in_transaction
     db_session = cache.db_session
     if db_session is not None and db_session.ddl:
         cursor = connection.cursor()
         cursor.execute("SHOW VARIABLES LIKE 'foreign_key_checks'")
         fk = cursor.fetchone()
         if fk is not None: fk = (fk[1] == 'ON')
         if fk:
             sql = 'SET foreign_key_checks = 0'
             if core.local.debug: log_orm(sql)
             cursor.execute(sql)
         cache.saved_fk_state = bool(fk)
         cache.in_transaction = True
     cache.immediate = True
     if db_session is not None and db_session.serializable:
         cursor = connection.cursor()
         sql = 'SET TRANSACTION ISOLATION LEVEL SERIALIZABLE'
         if core.local.debug: log_orm(sql)
         cursor.execute(sql)
         cache.in_transaction = True
コード例 #18
0
ファイル: sqlite.py プロジェクト: rlizana/pony
    def set_transaction_mode(provider, connection, cache):
        assert not cache.in_transaction
        if cache.immediate:
            provider.transaction_lock.acquire()
        try:
            cursor = connection.cursor()

            db_session = cache.db_session
            if db_session is not None and db_session.ddl:
                cursor.execute('PRAGMA foreign_keys')
                fk = cursor.fetchone()
                if fk is not None: fk = fk[0]
                if fk:
                    sql = 'PRAGMA foreign_keys = false'
                    if core.debug: log_orm(sql)
                    cursor.execute(sql)
                cache.saved_fk_state = bool(fk)
                assert cache.immediate

            if cache.immediate:
                sql = 'BEGIN IMMEDIATE TRANSACTION'
                if core.debug: log_orm(sql)
                cursor.execute(sql)
                cache.in_transaction = True
            elif core.debug:
                log_orm('SWITCH TO AUTOCOMMIT MODE')
        finally:
            if cache.immediate and not cache.in_transaction:
                provider.transaction_lock.release()
コード例 #19
0
ファイル: postgres.py プロジェクト: talent-tool-sets/pony
 def set_transaction_mode(provider, connection, cache):
     assert not cache.in_transaction
     if cache.immediate and connection.autocommit:
         connection.autocommit = False
         if core.debug: log_orm('SWITCH FROM AUTOCOMMIT TO TRANSACTION MODE')
     db_session = cache.db_session
     if db_session is not None and db_session.serializable:
         cursor = connection.cursor()
         sql = 'SET TRANSACTION ISOLATION LEVEL SERIALIZABLE'
         if core.debug: log_orm(sql)
         cursor.execute(sql)
     elif not cache.immediate and not connection.autocommit:
         connection.autocommit = True
         if core.debug: log_orm('SWITCH TO AUTOCOMMIT MODE')
     if db_session is not None and (db_session.serializable or db_session.ddl):
         cache.in_transaction = True
コード例 #20
0
ファイル: postgres.py プロジェクト: buhtigexa/Nerit
 def set_transaction_mode(provider, connection, cache):
     assert not cache.in_transaction
     if cache.immediate and connection.autocommit:
         connection.autocommit = False
         if core.debug: log_orm('SWITCH FROM AUTOCOMMIT TO TRANSACTION MODE')
     db_session = cache.db_session
     if db_session is not None and db_session.serializable:
         cursor = connection.cursor()
         sql = 'SET TRANSACTION ISOLATION LEVEL SERIALIZABLE'
         if core.debug: log_orm(sql)
         cursor.execute(sql)
     elif not cache.immediate and not connection.autocommit:
         connection.autocommit = True
         if core.debug: log_orm('SWITCH TO AUTOCOMMIT MODE')
     if db_session is not None and (db_session.serializable or db_session.ddl):
         cache.in_transaction = True
コード例 #21
0
ファイル: sqlite.py プロジェクト: buhtigexa/Nerit
    def set_transaction_mode(provider, connection, cache):
        assert not cache.in_transaction
        cursor = connection.cursor()

        db_session = cache.db_session
        if db_session is not None and db_session.ddl:
            cursor.execute('PRAGMA foreign_keys')
            fk = cursor.fetchone()
            if fk is not None: fk = fk[0]
            if fk:
                sql = 'PRAGMA foreign_keys = false'
                if core.debug: log_orm(sql)
                cursor.execute(sql)
            cache.saved_fk_state = bool(fk)
            cache.in_transaction = True

        if cache.immediate:
            sql = 'BEGIN IMMEDIATE TRANSACTION'
            if core.debug: log_orm(sql)
            cursor.execute(sql)
            cache.in_transaction = True
        elif core.debug: log_orm('SWITCH TO AUTOCOMMIT MODE')
コード例 #22
0
ファイル: dbprovider.py プロジェクト: aadidenko/umypony
 def rollback(self):
     if core.debug:
         core.log_orm('ROLLBACK')
     self.conn.query('rollback')
コード例 #23
0
 def start_optimistic_save(provider, connection):
     if core.debug:
         core.log_orm('SET TRANSACTION ISOLATION LEVEL READ COMMITTED')
     connection.set_isolation_level(
         extensions.ISOLATION_LEVEL_READ_COMMITTED)
コード例 #24
0
ファイル: oracle.py プロジェクト: zihuxinyu/pony
 def connect(pool):
     if core.debug: log_orm('GET CONNECTION')
     con = pool._pool.acquire()
     con.outputtypehandler = output_type_handler
     return con
コード例 #25
0
 def connect(pool):
     if core.debug: log_orm('GET CONNECTION')
     con = pool._pool.acquire()
     con.outputtypehandler = output_type_handler
     return con
コード例 #26
0
ファイル: postgres.py プロジェクト: buddyli/android_intership
 def start_optimistic_save(provider, connection):
     if core.debug: core.log_orm('SET TRANSACTION ISOLATION LEVEL READ COMMITTED')
     connection.set_isolation_level(extensions.ISOLATION_LEVEL_READ_COMMITTED)
コード例 #27
0
ファイル: dbprovider.py プロジェクト: aadidenko/umypony
 def commit(self):
     if core.debug:
         core.log_orm('COMMIT')
     self.conn.query('commit')