Commit 7025dfd3 authored by Vincent Pelletier's avatar Vincent Pelletier

Fix error position computation: MySQL limits the length of the output SQL...

Fix error position computation: MySQL limits the length of the output SQL chunk, requiring more tricks to find offset error correctly.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@25473 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 0fb08f53
...@@ -415,10 +415,18 @@ class DB(TM): ...@@ -415,10 +415,18 @@ class DB(TM):
prefix, suffix = error_text.split("'", 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 ": 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) sql, suffix = suffix.rsplit("'", 1)
reference_sql = query try:
error_position = len(reference_sql) - len(sql) line_number = int(suffix.rsplit(' ', 1)[-1])
raise ProgrammingError(exception[0], "%s '%s' HERE '%s' %s" % (prefix, reference_sql[:error_position], reference_sql[error_position:], suffix)) except TypeError:
raise 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