@@ -53,6 +53,7 @@ def make_index_name(table_name, column_name):
5353from .misc import AUTO , log_progress , safe_eval , version_gte
5454from .orm import env , invalidate
5555from .pg import (
56+ PGRegexp ,
5657 SQLStr ,
5758 alter_column_type ,
5859 column_exists ,
@@ -64,6 +65,7 @@ def make_index_name(table_name, column_name):
6465 get_columns ,
6566 get_value_or_en_translation ,
6667 parallel_execute ,
68+ pg_replace ,
6769 pg_text2html ,
6870 remove_column ,
6971 table_exists ,
@@ -1409,11 +1411,11 @@ def _update_field_usage_multi(cr, models, old, new, domain_adapter=None, skip_in
14091411 _validate_model (model )
14101412
14111413 p = {
1412- "old" : r"\y%s \y" % (re .escape (old ), ),
1413- "old_pattern" : r"""[.'"]{0}\y""" .format (re .escape (old )),
1414+ "old" : PGRegexp ( r"\y{} \y" . format (re .escape (old )) ),
1415+ "old_pattern" : PGRegexp ( r"""[.'"]{0}\y""" .format (re .escape (old ) )),
14141416 "new" : new ,
1415- "def_old" : r"\ydefault_%s \y" % (re .escape (old ), ),
1416- "def_new" : "default_%s" % (new , ),
1417+ "def_old" : PGRegexp ( r"\ydefault_{} \y" . format (re .escape (old )) ),
1418+ "def_new" : "default_{}" . format (new ),
14171419 "models" : tuple (only_models ) if only_models else (),
14181420 }
14191421
@@ -1520,26 +1522,26 @@ def _update_field_usage_multi(cr, models, old, new, domain_adapter=None, skip_in
15201522 col_prefix = ""
15211523 if not column_exists (cr , "ir_filters" , "sort" ):
15221524 col_prefix = "--" # sql comment the line
1523- q = """
1524- UPDATE ir_filters
1525- SET {col_prefix} sort = regexp_replace(sort, %(old)s, %(new)s, 'g'),
1526- context = regexp_replace(regexp_replace(context,
1527- %(old)s, %(new)s, 'g'),
1528- %(def_old)s, %(def_new)s, 'g')
1529- """
15301525
1531- if only_models :
1532- q += " WHERE model_id IN %(models)s AND "
1533- else :
1534- q += " WHERE "
1535- q += """
1536- (
1526+ q = format_query (
1527+ cr ,
1528+ """
1529+ UPDATE ir_filters
1530+ SET {col_prefix} sort = {sort_repl},
1531+ context = {context_repl}
1532+ WHERE {cond}
1533+ AND (
15371534 context ~ %(old)s
15381535 OR context ~ %(def_old)s
15391536 {col_prefix} OR sort ~ %(old)s
1540- )
1541- """
1542- cr .execute (q .format (col_prefix = col_prefix ), p )
1537+ )
1538+ """ ,
1539+ col_prefix = SQLStr (col_prefix ),
1540+ sort_repl = pg_replace ("sort" , [(p ["old" ], p ["new" ])]),
1541+ context_repl = pg_replace ("context" , [(p ["old" ], p ["new" ]), (p ["def_old" ], p ["def_new" ])]),
1542+ cond = SQLStr ("model_id IN %(models)s" ) if only_models else SQLStr ("true" ),
1543+ )
1544+ cr .execute (q , p )
15431545
15441546 # ir.exports.line, base_import.mapping # noqa
15451547 if only_models :
0 commit comments