Commit 0fb08f53 authored by Vincent Pelletier's avatar Vincent Pelletier

Replace default MySQL error text (for sql syntax error) with more complete -...

Replace default MySQL error text (for sql syntax error) with more complete - though as uggly - error.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@25472 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent a948a2f5
...@@ -404,8 +404,20 @@ class DB(TM): ...@@ -404,8 +404,20 @@ 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: except ProgrammingError, exception:
LOG('ZMySQLDA', ERROR, 'query failed: %s' % (query,)) LOG('ZMySQLDA', ERROR, 'query failed: %s' % (query,))
if exception[0] == 1064:
# 1064 = 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)
reference_sql = query
error_position = len(reference_sql) - len(sql)
raise ProgrammingError(exception[0], "%s '%s' HERE '%s' %s" % (prefix, reference_sql[:error_position], reference_sql[error_position:], suffix))
raise raise
return self.db.store_result() return self.db.store_result()
......
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