Commit ed452b33 authored by Vincent Pelletier's avatar Vincent Pelletier

Revert a change accidentally included in an unrelated commit.

This partially reverts:

commit 76e3c115
Author: Vincent Pelletier <vincent@nexedi.com>
Date:   Mon Dec 10 16:40:48 2018 +0900

    Base: Fix isAncestryIndexable implementation.

as it accidentally carried over a totally unrelated (and unfinished)
change.
parent 76e3c115
...@@ -354,20 +354,44 @@ class DB(TM): ...@@ -354,20 +354,44 @@ class DB(TM):
try: try:
self.db.query(query) self.db.query(query)
except OperationalError, m: except OperationalError, m:
__traceback_info__ = (str(m), query) if m[0] in query_syntax_error:
if m[0] in hosed_connection and self._use_TM and allow_reconnect: raise OperationalError(m[0], '%s: %s' % (m[1], query))
self._forceReconnection()
return self._query(query, allow_reconnect=False)
if m[0] in lock_error: if m[0] in lock_error:
raise ConflictError raise ConflictError('%s: %s: %s' % (m[0], m[1], query))
raise OperationalError if not allow_reconnect and self._use_TM or \
except ProgrammingError, exception: m[0] not in hosed_connection:
__traceback_info__ = (str(exception), query) LOG('ZMySQLDA', ERROR, 'query failed: %s' % (query,))
# XXX sometimes, after a programming error, the database object raise
# gets fully broken and non-functional. So recover it by # Hm. maybe the db is hosed. Let's restart it.
# recreation.
self._forceReconnection() self._forceReconnection()
raise ProgrammingError self.db.query(query)
except ProgrammingError, exception:
LOG('ZMySQLDA', ERROR, 'query failed: %s' % (query,))
# XXX sometimes, after a programming error, the database object
# gets fully broken and non-functional. So recover it by
# recreation.
self._forceReconnection()
if exception[0] == ER.PARSE_ERROR:
# You have an error in your SQL syntax
# Replace MySQL brain dead error message with a more meaningful
# one. (MySQL only reports the SQL query *from* the error place,
# which strips important contextual information).
error_text = exception[1]
prefix, suffix = error_text.split("'", 1)
if prefix == "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ":
sql, suffix = suffix.rsplit("'", 1)
try:
line_number = int(suffix.rsplit(' ', 1)[-1])
except TypeError:
pass
else:
reference_sql = query
split_reference_sql = reference_sql.split('\n')
candidate_sql = '\n'.join(split_reference_sql[line_number - 1:])
error_position = len(reference_sql) - len(candidate_sql) + candidate_sql.find(sql)
if error_position > -1:
raise ProgrammingError(exception[0], "%s '%s' HERE '%s' %s" % (prefix, reference_sql[:error_position], reference_sql[error_position:], suffix))
raise exception
return self.db.store_result() return self.db.store_result()
def query(self, query_string, max_rows=1000): def query(self, query_string, max_rows=1000):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment