@@ -207,7 +207,11 @@ def sql_type_from_oid(self, oid, qi = quote_ident):
207207 if oid in self .typinfo :
208208 nsp , name , * _ = self .typinfo [oid ]
209209 return qi (nsp ) + '.' + qi (name )
210- return 'pg_catalog.' + pg_types .oid_to_name .get (oid )
210+ name = pg_types .oid_to_name .get (oid )
211+ if name :
212+ return 'pg_catalog.%s' % name
213+ else :
214+ return None
211215
212216 def type_from_oid (self , oid ):
213217 if oid in self ._cache :
@@ -2038,19 +2042,14 @@ class Transaction(pg_api.Transaction):
20382042
20392043 mode = None
20402044 isolation = None
2041- gid = None
20422045
2043- _e_factors = ('database' , 'gid' , ' isolation' , 'mode' )
2046+ _e_factors = ('database' , 'isolation' , 'mode' )
20442047
20452048 def _e_metas (self ):
20462049 yield (None , self .state )
20472050
2048- def __init__ (self , database , isolation = None , mode = None , gid = None ):
2051+ def __init__ (self , database , isolation = None , mode = None ):
20492052 self .database = database
2050- self .gid = gid
2051- if gid is not None :
2052- # XXX: remove in 1.1
2053- warnings .warn ("two phase interfaces will not exist in 1.1; do not use the 'gid' parameter" , DeprecationWarning , stacklevel = 3 )
20542053 self .isolation = isolation
20552054 self .mode = mode
20562055 self .state = 'initialized'
@@ -2081,26 +2080,10 @@ def __exit__(self, typ, value, tb):
20812080 # If an error occurs, clean up the transaction state
20822081 # and raise as needed.
20832082 except pg_exc .ActiveTransactionError as err :
2084- ##
2085- # Failed COMMIT PREPARED <gid>?
2086- # Likely cases:
2087- # - User exited block without preparing the transaction.
2088- ##
2089- if not self .database .closed and self .gid is not None :
2083+ if not self .database .closed :
20902084 # adjust the state so rollback will do the right thing and abort.
20912085 self .state = 'open'
20922086 self .rollback ()
2093- ##
2094- # The other exception that *can* occur is
2095- # UndefinedObjectError in which:
2096- # - User issued C/RB P <gid> before exit, but not via xact methods.
2097- # - User adjusted gid after prepare().
2098- #
2099- # But the occurrence of this exception means it's not in an active
2100- # transaction, which means no cleanup other than raise is necessary.
2101- err .details ['cause' ] = \
2102- "The prepared transaction was not " \
2103- "prepared prior to the block's exit."
21042087 raise
21052088 elif issubclass (typ , Exception ):
21062089 # There's an exception, so only rollback if the connection
@@ -2146,7 +2129,7 @@ def start(self):
21462129 )
21472130 else :
21482131 self .type = 'savepoint'
2149- if (self .gid , self . isolation , self .mode ) != (None , None ,None ):
2132+ if (self .isolation , self .mode ) != (None ,None ):
21502133 em = element .ClientError ((
21512134 (b'S' , 'ERROR' ),
21522135 (b'C' , '--OPE' ),
@@ -2159,60 +2142,15 @@ def start(self):
21592142 self .state = 'open'
21602143 begin = start
21612144
2162- @staticmethod
2163- def _prepare_string (id ):
2164- "2pc prepared transaction 'gid'"
2165- return "PREPARE TRANSACTION '" + id .replace ("'" , "''" ) + "';"
2166-
21672145 @staticmethod
21682146 def _release_string (id ):
21692147 'release "";'
21702148 return 'RELEASE "xact(' + id .replace ('"' , '""' ) + ')";'
21712149
2172- def prepare (self ):
2173- if self .state == 'prepared' :
2174- return
2175- if self .state != 'open' :
2176- em = element .ClientError ((
2177- (b'S' , 'ERROR' ),
2178- (b'C' , '--OPE' ),
2179- (b'M' , "transaction state must be 'open' in order to prepare" ),
2180- ))
2181- self .database .typio .raise_client_error (em , creator = self )
2182- if self .type != 'block' :
2183- em = element .ClientError ((
2184- (b'S' , 'ERROR' ),
2185- (b'C' , '--OPE' ),
2186- (b'M' , "improper transaction type to prepare" ),
2187- ))
2188- self .database .typio .raise_client_error (em , creator = self )
2189- q = self ._prepare_string (self .gid )
2190- self .database .execute (q )
2191- self .state = 'prepared'
2192-
2193- def recover (self ):
2194- if self .state != 'initialized' :
2195- em = element .ClientError ((
2196- (b'S' , 'ERROR' ),
2197- (b'C' , '--OPE' ),
2198- (b'M' , "improper state for prepared transaction recovery" ),
2199- ))
2200- self .database .typio .raise_client_error (em , creator = self )
2201- if self .database .sys .xact_is_prepared (self .gid ):
2202- self .state = 'prepared'
2203- self .type = 'block'
2204- else :
2205- em = element .ClientError ((
2206- (b'S' , 'ERROR' ),
2207- (b'C' , '42704' ), # UndefinedObjectError
2208- (b'M' , "prepared transaction does not exist" ),
2209- ))
2210- self .database .typio .raise_client_error (em , creator = self )
2211-
22122150 def commit (self ):
22132151 if self .state == 'committed' :
22142152 return
2215- if self .state not in ( 'prepared' , ' open') :
2153+ if self .state != ' open' :
22162154 em = element .ClientError ((
22172155 (b'S' , 'ERROR' ),
22182156 (b'C' , '--OPE' ),
@@ -2221,19 +2159,8 @@ def commit(self):
22212159 self .database .typio .raise_client_error (em , creator = self )
22222160
22232161 if self .type == 'block' :
2224- if self .gid is not None :
2225- # User better have prepared it.
2226- q = "COMMIT PREPARED '" + self .gid .replace ("'" , "''" ) + "';"
2227- else :
2228- q = 'COMMIT'
2162+ q = 'COMMIT'
22292163 else :
2230- if self .gid is not None :
2231- em = element .ClientError ((
2232- (b'S' , 'ERROR' ),
2233- (b'C' , '--OPE' ),
2234- (b'M' , "savepoint configured with global identifier" ),
2235- ))
2236- self .database .typio .raise_client_error (em , creator = self )
22372164 q = self ._release_string (hex (id (self )))
22382165 self .database .execute (q )
22392166 self .state = 'committed'
@@ -2254,10 +2181,7 @@ def rollback(self):
22542181 self .database .typio .raise_client_error (em , creator = self )
22552182
22562183 if self .type == 'block' :
2257- if self .state == 'prepared' :
2258- q = "ROLLBACK PREPARED '" + self .gid .replace ("'" , "''" ) + "'"
2259- else :
2260- q = 'ABORT;'
2184+ q = 'ABORT;'
22612185 elif self .type == 'savepoint' :
22622186 q = self ._rollback_to_string (hex (id (self )))
22632187 else :
@@ -2339,8 +2263,8 @@ def do(self, language : str, source : str,
23392263 sql = "DO " + qlit (source ) + " LANGUAGE " + qid (language ) + ";"
23402264 self .execute (sql )
23412265
2342- def xact (self , gid = None , isolation = None , mode = None ):
2343- x = Transaction (self , gid = gid , isolation = isolation , mode = mode )
2266+ def xact (self , isolation = None , mode = None ):
2267+ x = Transaction (self , isolation = isolation , mode = mode )
23442268 return x
23452269
23462270 def prepare (self ,
0 commit comments