@@ -50,8 +50,41 @@ def _check_name_buggy_characters(self, table, name, report_columns):
5050 cursor .execute (query )
5151 return cursor
5252
53+ def _check_name_trailing_slash (self , table , name , report_columns ):
54+ query = "SELECT {} FROM {} WHERE {} != '/' AND {} LIKE '%/' {}" .format ( "," .join (report_columns ), table , name , name , self ._get_prefix_condition (table ))
55+ cursor = self .connection .cursor ("{}._check_name_trailing_slash" .format (self .get_name ()))
56+ cursor .execute (query )
57+ return cursor
58+
5359 def run (self ):
5460 issue_found = False
61+
62+ def _do_output (type_name , report_columns , query_result ):
63+ """Internal function for translating query results of a check to a generic
64+ output dictionary and feeding it to the output processor. Also translates
65+ collection IDs to collection names for readability."""
66+ nonlocal issue_found
67+
68+ for row in query_result :
69+ output = {'type' : type_name , 'check_name' : check_name , 'report_columns' : {}}
70+ column_num = 0
71+ for report_column in report_columns :
72+ if str (report_column ) == 'coll_id' :
73+ coll_name = utils .get_collection_name (
74+ self .connection , str (row [column_num ]))
75+ if coll_name is not None :
76+ output ['report_columns' ]['Collection name' ] = coll_name
77+ else :
78+ output ['report_columns' ][str (report_column )] = str (
79+ row [column_num ])
80+ column_num = column_num + 1
81+
82+ self .output_item (output )
83+ issue_found = True
84+
85+ query_result .close ()
86+ return issue_found
87+
5588 for check_name , check_params in self ._get_name_check_data ():
5689 if self .args .v :
5790 self .print_progress ("Running empty name test for: " + check_name )
@@ -60,16 +93,18 @@ def run(self):
6093 check_params ['table' ],
6194 check_params ['name' ],
6295 check_params ['report_columns' ])
63- for row in result_empty :
64- output = {'type' : 'empty_name' , 'check_name' : check_name , 'report_columns' : {}}
65- column_num = 0
66- for report_column in check_params ['report_columns' ]:
67- output ['report_columns' ][str (report_column )] = str (
68- row [column_num ])
69- column_num = column_num + 1
70- self .output_item (output )
71- issue_found = True
72- result_empty .close ()
96+ _do_output ("empty_name" , check_params ['report_columns' ], result_empty )
97+
98+
99+ if check_name in ["data object" , "collection" ]:
100+ if self .args .v :
101+ self .print_progress ("Running trailing slash test for: " + check_name )
102+
103+ result_trailing_slash = self ._check_name_trailing_slash (
104+ check_params ['table' ],
105+ check_params ['name' ],
106+ check_params ['report_columns' ])
107+ _do_output ("trailing_slash" , check_params ['report_columns' ], result_trailing_slash )
73108
74109 if self .args .v :
75110 self .print_progress ("Running problematic character name test for: " + check_name )
@@ -78,21 +113,6 @@ def run(self):
78113 check_params ['table' ],
79114 check_params ['name' ],
80115 check_params ['report_columns' ])
81- for row in result_buggy_characters :
82- output = {'type' : 'buggy_characters' , 'check_name' : check_name , 'report_columns' : {}}
83- column_num = 0
84- for report_column in check_params ['report_columns' ]:
85- if str (report_column ) == 'coll_id' :
86- coll_name = utils .get_collection_name (
87- self .connection , str (row [column_num ]))
88- if coll_name is not None :
89- output ['report_columns' ]['Collection name' ] = coll_name
90- else :
91- output ['report_columns' ][str (report_column )] = str (
92- row [column_num ])
93- column_num = column_num + 1
94- self .output_item (output )
95- issue_found = True
96- result_buggy_characters .close ()
116+ _do_output ("buggy_characters" , check_params ['report_columns' ], result_buggy_characters )
97117
98118 return issue_found
0 commit comments