History

perf scripts python: exported-sql-viewer.py: Fix pattern matching with Python 3

The script allows the user to enter patterns to find symbols. The pattern matching characters are converted for use in SQL. For PostgreSQL the conversion involves using the Python maketrans() method which is slightly different in Python 3 compared with Python 2. Fix to work in Python 3.

Adrian Hunter committed 1 year ago

Commit 17e54841 parent 352b0881 file · +4 −1Browse files

Showing the changes to tools/perf/scripts/python (1 of 1 file). Show all

Unified · Split

tools/perf/scripts/python/exported-sql-viewer.py+4−1
@@ -680,7 +680,10 @@ class CallGraphModelBase(TreeModel): · 679 unmodified lines
680680 s = value.replace("%", "\\%")
681681 s = s.replace("_", "\\_")
682682 # Translate * and ? into SQL LIKE pattern characters % and _
683− trans = string.maketrans("*?", "%_")
683+ if sys.version_info[0] == 3:
684+ trans = str.maketrans("*?", "%_")
685+ else:
686+ trans = string.maketrans("*?", "%_")
684687 match = " LIKE '" + str(s).translate(trans) + "'"
685688 else:
686689 match = " GLOB '" + str(value) + "'"