Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neoppod
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
Carlos Ramos Carreño
neoppod
Commits
93aef5ed
Commit
93aef5ed
authored
Jun 23, 2015
by
Julien Muchembled
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mysql: log failed query in case of database failure
parent
f8ce322b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
27 deletions
+28
-27
neo/storage/database/mysqldb.py
neo/storage/database/mysqldb.py
+28
-27
No files found.
neo/storage/database/mysqldb.py
View file @
93aef5ed
...
@@ -33,6 +33,11 @@ from neo.lib.exception import DatabaseFailure
...
@@ -33,6 +33,11 @@ from neo.lib.exception import DatabaseFailure
from
neo.lib.protocol
import
CellStates
,
ZERO_OID
,
ZERO_TID
,
ZERO_HASH
from
neo.lib.protocol
import
CellStates
,
ZERO_OID
,
ZERO_TID
,
ZERO_HASH
def
getPrintableQuery
(
query
,
max
=
70
):
return
''
.
join
(
c
if
c
in
string
.
printable
and
c
not
in
'
\
t
\
x0b
\
x0c
\
r
'
else
'
\
\
x%02x'
%
ord
(
c
)
for
c
in
query
)
class
MySQLDatabaseManager
(
DatabaseManager
):
class
MySQLDatabaseManager
(
DatabaseManager
):
"""This class manages a database on MySQL."""
"""This class manages a database on MySQL."""
...
@@ -92,35 +97,31 @@ class MySQLDatabaseManager(DatabaseManager):
...
@@ -92,35 +97,31 @@ class MySQLDatabaseManager(DatabaseManager):
def
query
(
self
,
query
):
def
query
(
self
,
query
):
"""Query data from a database."""
"""Query data from a database."""
conn
=
self
.
conn
if
LOG_QUERIES
:
try
:
logging
.
debug
(
'querying %s...'
,
if
LOG_QUERIES
:
getPrintableQuery
(
query
.
split
(
'
\
n
'
,
1
)[
0
][:
70
]))
printable_char_list
=
[]
while
1
:
for
c
in
query
.
split
(
'
\
n
'
,
1
)[
0
][:
70
]:
conn
=
self
.
conn
if
c
not
in
string
.
printable
or
c
in
'
\
t
\
x0b
\
x0c
\
r
'
:
try
:
c
=
'
\
\
x%02x'
%
ord
(
c
)
conn
.
query
(
query
)
printable_char_list
.
append
(
c
)
if
query
.
startswith
(
"SELECT "
):
query_part
=
''
.
join
(
printable_char_list
)
r
=
conn
.
store_result
()
logging
.
debug
(
'querying %s...'
,
query_part
)
return
tuple
([
tuple
([
d
.
tostring
()
if
isinstance
(
d
,
array
)
else
d
conn
.
query
(
query
)
for
d
in
row
])
if
query
.
startswith
(
"SELECT "
):
for
row
in
r
.
fetch_row
(
r
.
num_rows
())])
r
=
conn
.
store_result
()
break
return
tuple
([
except
OperationalError
,
m
:
tuple
([
d
.
tostring
()
if
isinstance
(
d
,
array
)
else
d
if
self
.
_active
or
m
[
0
]
not
in
(
SERVER_GONE_ERROR
,
SERVER_LOST
):
for
d
in
row
])
raise
DatabaseFailure
(
'MySQL error %d: %s
\
n
Query: %s'
for
row
in
r
.
fetch_row
(
r
.
num_rows
())])
%
(
m
[
0
],
m
[
1
],
getPrintableQuery
(
query
[:
1000
])))
r
=
query
.
split
(
None
,
1
)[
0
]
if
r
in
(
"INSERT"
,
"REPLACE"
,
"DELETE"
,
"UPDATE"
):
self
.
_active
=
1
else
:
assert
r
in
(
"ALTER"
,
"CREATE"
,
"DROP"
,
"TRUNCATE"
),
query
except
OperationalError
,
m
:
if
m
[
0
]
in
(
SERVER_GONE_ERROR
,
SERVER_LOST
)
and
not
self
.
_active
:
logging
.
info
(
'the MySQL server is gone; reconnecting'
)
logging
.
info
(
'the MySQL server is gone; reconnecting'
)
self
.
_connect
()
self
.
_connect
()
return
self
.
query
(
query
)
r
=
query
.
split
(
None
,
1
)[
0
]
raise
DatabaseFailure
(
'MySQL error %d: %s'
%
(
m
[
0
],
m
[
1
]))
if
r
in
(
"INSERT"
,
"REPLACE"
,
"DELETE"
,
"UPDATE"
):
self
.
_active
=
1
else
:
assert
r
in
(
"ALTER"
,
"CREATE"
,
"DROP"
,
"TRUNCATE"
),
query
@
property
@
property
def
escape
(
self
):
def
escape
(
self
):
...
...
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