18
18
_logger = logging .getLogger (__name__ )
19
19
20
20
21
- def read_spreadsheet_attachments (cr , like_pattern = "% " ):
21
+ def read_spreadsheet_attachments (cr , like_pattern = "" ):
22
22
yield from read_spreadsheet_initial_data (cr , like_pattern )
23
23
yield from read_spreadsheet_snapshots (cr , like_pattern )
24
24
25
25
26
- def read_spreadsheet_snapshots (cr , like_pattern = "% " ):
26
+ def read_spreadsheet_snapshots (cr , like_pattern = "" ):
27
27
cr .execute (
28
28
"""
29
29
SELECT id, res_model, res_id, db_datas
30
30
FROM ir_attachment
31
31
WHERE res_model IN ('spreadsheet.dashboard', 'documents.document')
32
32
AND res_field = 'spreadsheet_snapshot'
33
- AND db_datas LIKE %s
33
+ AND position(%s::bytea in db_datas) > 0
34
34
""" ,
35
35
[like_pattern ],
36
36
)
37
- # TODO LIKE probably doesn't work because the field is of type bytea
37
+ # TODO rename 'like_pattern', it's not LIKE because LIKE doesn't work because the field is of type bytea
38
38
for attachment_id , res_model , res_id , db_datas in cr .fetchall ():
39
39
if db_datas :
40
40
yield attachment_id , res_model , res_id , json .loads (db_datas .tobytes ())
41
41
42
42
43
- def read_spreadsheet_initial_data (cr , like_pattern = "% " ):
43
+ def read_spreadsheet_initial_data (cr , like_pattern = "" ):
44
44
cr .execute (
45
45
"""
46
46
SELECT doc.id AS document_id, a.id AS attachment_id, a.db_datas
47
47
FROM documents_document doc
48
48
LEFT JOIN ir_attachment a ON a.id = doc.attachment_id
49
49
WHERE doc.handler='spreadsheet'
50
- AND a. db_datas LIKE %s
50
+ AND position(%s::bytea in db_datas) > 0
51
51
""" ,
52
52
[like_pattern ],
53
53
)
@@ -63,7 +63,7 @@ def read_spreadsheet_initial_data(cr, like_pattern="%"):
63
63
FROM ir_attachment
64
64
WHERE res_model = 'spreadsheet.dashboard'
65
65
AND res_field = %s
66
- AND db_datas LIKE %s
66
+ AND position(%s::bytea in db_datas) > 0
67
67
""" ,
68
68
[data_field , like_pattern ],
69
69
)
@@ -74,7 +74,7 @@ def read_spreadsheet_initial_data(cr, like_pattern="%"):
74
74
def apply_in_all_spreadsheets (cr , like_pattern , callback ):
75
75
_logger .info ("upgrading initial data and revisions" )
76
76
# upgrade the initial data and all revisions based on it
77
- for attachment_id , res_model , res_id , db_datas in read_spreadsheet_initial_data (cr ):
77
+ for attachment_id , res_model , res_id , db_datas in read_spreadsheet_initial_data (cr , like_pattern ):
78
78
revisions_data = []
79
79
revisions_ids = []
80
80
for revision_id , commands in get_revisions (cr , res_model , res_id , like_pattern ):
@@ -93,7 +93,7 @@ def apply_in_all_spreadsheets(cr, like_pattern, callback):
93
93
)
94
94
_logger .info ("upgrading snapshots" )
95
95
# upgrade snapshots
96
- for attachment_id , _res_model , _res_id , db_datas in read_spreadsheet_snapshots (cr ):
96
+ for attachment_id , _res_model , _res_id , db_datas in read_spreadsheet_snapshots (cr , like_pattern ):
97
97
data , revisions = callback (db_datas , [])
98
98
write_attachment (cr , attachment_id , data )
99
99
0 commit comments