|
7 | 7 | from concurrent.futures import ProcessPoolExecutor |
8 | 8 |
|
9 | 9 | from lxml import etree, html |
| 10 | +from psycopg2 import sql |
10 | 11 | from psycopg2.extensions import quote_ident |
11 | 12 | from psycopg2.extras import Json |
12 | 13 |
|
@@ -64,19 +65,17 @@ def add_snippet_names_on_html_field(cr, table, column, snippets, regex): |
64 | 65 | Will search for all the snippets in the fields mentionned (should be html fields) and add |
65 | 66 | the corresponding data-snippet on them. |
66 | 67 | """ |
67 | | - |
68 | | - def quote(ident): |
69 | | - return quote_ident(ident, cr._cnx) |
70 | | - |
71 | 68 | query = cr.mogrify( |
72 | | - f""" |
73 | | - SELECT id, array((SELECT regexp_matches({quote(column)}, %(regex)s, 'g'))), {column} |
74 | | - FROM {quote(table)} |
75 | | - WHERE {quote(column)} ~ %(regex)s |
76 | | - """, |
| 69 | + sql.SQL( |
| 70 | + """ |
| 71 | + SELECT id, array((SELECT regexp_matches({column}, %(regex)s, 'g'))), {column} |
| 72 | + FROM {table} |
| 73 | + WHERE {column} ~ %(regex)s |
| 74 | + """ |
| 75 | + ).format(column=sql.Identifier(column), table=sql.Identifier(table)), |
77 | 76 | {"regex": regex}, |
78 | 77 | ).decode() |
79 | | - where = cr.mogrify(f"{quote(column)} ~ %s", [regex]).decode() |
| 78 | + where = cr.mogrify(sql.SQL("{column} ~ %s").format(column=sql.Identifier(column)), [regex]).decode() |
80 | 79 | ids_ranges = determine_chunk_limit_ids(cr, table, [column], where) |
81 | 80 | for id0, id1 in ids_ranges: |
82 | 81 | add_snippet_names(cr, table, column, snippets, query + f" AND id BETWEEN {id0} AND {id1}") |
|
0 commit comments