Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit21fc671

Browse files
committed
implement begin() (with isolation level support), commit(), rollback() for NodeConnection
1 parent8fe7527 commit21fc671

File tree

1 file changed

+40
-4
lines changed

1 file changed

+40
-4
lines changed

‎testgres/testgres.py

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,45 @@ def __enter__(self):
7676
def__exit__(self,type,value,tb):
7777
self.connection.close()
7878

79-
defexecute(self,query):
80-
self.cursor.execute(query)
81-
returnself.cursor.fetchall()
79+
defbegin(self,isolation_level=0):
80+
levels= ['read uncommitted',
81+
'read committed',
82+
'repeatable read',
83+
'serializable' ]
84+
85+
# Check if level is int [0..3]
86+
ifisinstance(isolation_level,int)and \
87+
isolation_levelinrange(0,4):
88+
89+
# Replace index with isolation level type
90+
isolation_level=levels[isolation_level]
91+
92+
# Or it might be a string
93+
elifisinstance(isolation_level,str)and \
94+
str.lower(isolation_level)inlevels:
95+
96+
# Nothing to do here
97+
pass
98+
99+
# Something is wrong, emit exception
100+
else:
101+
raiseQueryException('Invalid isolation level "%s"'
102+
%isolation_level)
103+
104+
self.cursor.execute('SET TRANSACTION ISOLATION LEVEL %s'
105+
%isolation_level)
106+
107+
defcommit(self):
108+
self.connection.commit()
109+
110+
defrollback(self):
111+
self.connection.rollback()
112+
113+
defexecute(self,query,*args):
114+
self.cursor.execute(query,args)
115+
116+
ifself.cursor.rowcount>0:
117+
returnself.cursor.fetchall()
82118

83119
defclose(self):
84120
self.connection.close()
@@ -359,7 +395,7 @@ def backup(self, name):
359395

360396
returnbackup_path
361397

362-
defconnect(self,dbname):
398+
defconnect(self,dbname='postgres'):
363399
returnNodeConnection(parent_node=self,dbname=dbname)
364400

365401

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp