Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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.

Fixes: beda0e725e5f06ac ("perf script python: Add Python3 support to exported-sql-viewer.py")
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Tony Jones <tonyj@suse.de>
Link: https://lore.kernel.org/r/20250512093932.79854-4-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Adrian Hunter and committed by
Arnaldo Carvalho de Melo
17e54840 352b0881

+4 -1
+4 -1
tools/perf/scripts/python/exported-sql-viewer.py
··· 680 680 s = value.replace("%", "\\%") 681 681 s = s.replace("_", "\\_") 682 682 # 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("*?", "%_") 684 687 match = " LIKE '" + str(s).translate(trans) + "'" 685 688 else: 686 689 match = " GLOB '" + str(value) + "'"