Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Paul Graydon
erp5
Commits
018f1105
Commit
018f1105
authored
Nov 15, 2023
by
Kazuhiko Shiozaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ZMySQLDA: automatically switch isolation level by SELECT query or not.
parent
c60fc5a5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
5 deletions
+17
-5
product/ZMySQLDA/connectionAdd.dtml
product/ZMySQLDA/connectionAdd.dtml
+3
-1
product/ZMySQLDA/db.py
product/ZMySQLDA/db.py
+14
-4
No files found.
product/ZMySQLDA/connectionAdd.dtml
View file @
018f1105
...
...
@@ -107,7 +107,9 @@
!<em>isolation_level</em> at the begining of the connection string
will set the transaction isolation level in each transaction. The
value should be one of REPEATABLE-READ, READ-COMMITTED,
READ-UNCOMMITTED or SERIALIZABLE.
READ-UNCOMMITTED or SERIALIZABLE. If not specified, REPEATABLE-READ
is used for if the first query in a Zope transaction is SELECT query,
otherwise READ-COMMITTED is used.
</dd>
<dd>
Transactions are highly recommended. Using a named lock in
...
...
product/ZMySQLDA/db.py
View file @
018f1105
...
...
@@ -301,7 +301,7 @@ class DB(TM):
FIELD_TYPE.TINY: "i", FIELD_TYPE.YEAR: "i",
}
_p_oid=_p_changed=_registered=None
_p_oid=_p_changed=_registered=
_current_isolation_level=
None
def __del__(self):
if self.db is not None:
...
...
@@ -439,7 +439,6 @@ class DB(TM):
def
query
(
self
,
query_string
,
max_rows
=
1000
):
"""Execute 'query_string' and return at most 'max_rows'."""
self
.
_use_TM
and
self
.
_register
()
desc
=
None
if
isinstance
(
query_string
,
six
.
text_type
):
query_string
=
query_string
.
encode
(
'utf-8'
)
...
...
@@ -448,6 +447,17 @@ class DB(TM):
# Unfortunately, MySQLdb does not want to be graceful.
if
query_string
[
-
1
:]
==
b';'
:
query_string
=
query_string
[:
-
1
]
if
self
.
_use_TM
and
not
self
.
_registered
:
if
self
.
_isolation_level
:
self
.
_current_isolation_level
=
self
.
_isolation_level
else
:
for
qs
in
query_string
.
split
(
b'
\
0
'
):
if
match_select
(
qs
.
strip
()):
self
.
_current_isolation_level
=
'REPEATABLE-READ'
break
else
:
self
.
_current_isolation_level
=
'READ-COMMITTED'
self
.
_register
()
for
qs
in
query_string
.
split
(
b'
\
0
'
):
qs
=
qs
.
strip
()
if
qs
:
...
...
@@ -491,8 +501,8 @@ class DB(TM):
try
:
self
.
_transaction_begun
=
True
if
self
.
_transactions
:
if
self
.
_isolation_level
:
self
.
_query
(
"SET TRANSACTION ISOLATION LEVEL %s"
%
self
.
_isolation_level
.
replace
(
'-'
,
' '
))
if
self
.
_
current_
isolation_level
:
self
.
_query
(
"SET TRANSACTION ISOLATION LEVEL %s"
%
self
.
_
current_
isolation_level
.
replace
(
'-'
,
' '
))
self
.
_query
(
"BEGIN"
,
allow_reconnect
=
True
)
if
self
.
_mysql_lock
:
self
.
_query
(
"SELECT GET_LOCK('%s',0)"
%
self
.
_mysql_lock
,
allow_reconnect
=
not
self
.
_transactions
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment