Commit ce9c16db authored by Vincent Pelletier's avatar Vincent Pelletier Committed by Matevz Golob

ZMySQLDA.db: Drop special handling of syntax errors.

The same error code can be used for different causes. Specifically, it can
be used for SQL-level syntax error (which this code intended to handle),
or it can be used for fulltext syntax error (which makes this code raise).
Also, drop forced-reconnection, because this means a still-established
connection make be kept around and completely detected from current
transaction, which may cause a database snapshot to be kept indefinitely
(actually, until mariadb's timeout), in turn causing performance issue
because of associated InnoDB snapshot.
parent 60c17e9b
...@@ -365,33 +365,9 @@ class DB(TM): ...@@ -365,33 +365,9 @@ class DB(TM):
# Hm. maybe the db is hosed. Let's restart it. # Hm. maybe the db is hosed. Let's restart it.
self._forceReconnection() self._forceReconnection()
self.db.query(query) self.db.query(query)
except ProgrammingError, exception: except ProgrammingError:
LOG('ZMySQLDA', ERROR, 'query failed: %s' % (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
# 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