@@ -116,7 +116,7 @@ def process_token(token: Token) -> Token:
116116 return TokenList ([process_token (t ) for t in token .tokens ])
117117 return token
118118
119- formatted_sql = self .statement_to_sql (process_token (statement ))
119+ formatted_sql = self ._clean_sql_string (process_token (statement ))
120120
121121 if idx < len (parameters ):
122122 raise DataError (
@@ -155,8 +155,8 @@ def statement_to_set(self, statement: Statement) -> Optional[SetParameter]:
155155 # Check if set statement has a valid format
156156 if len (tokens ) == 2 and isinstance (tokens [1 ], Comparison ):
157157 return SetParameter (
158- self .statement_to_sql (tokens [1 ].left ),
159- self .statement_to_sql (tokens [1 ].right ).strip ("'" ),
158+ self ._clean_sql_string (tokens [1 ].left ),
159+ self ._clean_sql_string (tokens [1 ].right ).strip ("'" ),
160160 )
161161 # Or if at least there is a comparison
162162 cmp_idx = next (
@@ -175,20 +175,21 @@ def statement_to_set(self, statement: Statement) -> Optional[SetParameter]:
175175
176176 if left_tokens and right_tokens :
177177 return SetParameter (
178- "" .join (self .statement_to_sql (t ) for t in left_tokens ),
179- "" .join (self .statement_to_sql (t ) for t in right_tokens ).strip (
178+ "" .join (self ._clean_sql_string (t ) for t in left_tokens ),
179+ "" .join (self ._clean_sql_string (t ) for t in right_tokens ).strip (
180180 "'"
181181 ),
182182 )
183183
184184 raise InterfaceError (
185- f"Invalid set statement format: { self .statement_to_sql (statement )} ,"
185+ f"Invalid set statement format: { self ._clean_sql_string (statement )} ,"
186186 " expected SET <param> = <value>"
187187 )
188188 return None
189189
190- def statement_to_sql (self , statement : Statement ) -> str :
191- return str (statement ).strip ().rstrip (";" )
190+ def _clean_sql_string (self , token : Token ) -> str :
191+ """Strip whitespace and trailing semicolons from a SQL token or statement."""
192+ return str (token ).strip ().rstrip (";" )
192193
193194 def split_format_sql (
194195 self , query : str , parameters : Sequence [Sequence [ParameterType ]]
@@ -215,7 +216,7 @@ def split_format_sql(
215216
216217 # Try parsing each statement as a SET, otherwise return as a plain sql string
217218 return [
218- self .statement_to_set (st ) or self .statement_to_sql (st ) for st in statements
219+ self .statement_to_set (st ) or self ._clean_sql_string (st ) for st in statements
219220 ]
220221
221222 def format_bulk_insert (
0 commit comments