Skip to content

Comments

Problems with table names containing character '%', related issue #87#193

Open
atocyo wants to merge 1 commit intomichiya:azure-2.1from
atocyo:patch-1
Open

Problems with table names containing character '%', related issue #87#193
atocyo wants to merge 1 commit intomichiya:azure-2.1from
atocyo:patch-1

Conversation

@atocyo
Copy link

@atocyo atocyo commented Feb 10, 2019

pyodbc uses '?' instead of '%s' as parameter placeholder.
SQL identifiers (consequently table names, columns) can contain special characters if surrounded by brackets '[...]'
Replace only those placeholders:'%, %%, %s, %d etc.' which are not surrounded by brackets.
This is not complete solution, there may be problems with string literals in SQL etc. , if non string placeholder is found (example:%d) there should be error raised.

Test:
input:
''', test,%ss, [Company$Item].[Percentile %], [Company$Item],%s, [bfbfdb%vbddfb], %, %% [[%]], [%'''
result:
''', test,?s, [Company$Item].[Percentile %], [Company$Item],?, [bfbfdb%vbddfb], ?, ? [[%]], [%'''

pyodbc uses '?' instead of '%s' as parameter placeholder.
SQL identifiers (consequently table names, columns) can contain special characters if surrounded by brackets '[...]'
Replace only those placeholders:'%, %%, %s, %d etc.' which are not surrounded by brackets.            
This is not complete solution, there may be problems with string literals in SQL etc. , if non string placeholder is found (example:%d) there should be error raised.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant