Skip to content

fix(mssql): escape special characters for odbc #889

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 5, 2024

Conversation

grieve54706
Copy link
Contributor

We found the error

'IM002', '[IM002] [unixODBC][Driver Manager]Data source name not found and no default driver specified (0) (SQLDriverConnect)'

Because the password of mssql includes special characters like {R;3G1/8Al2AniRye that start with { or include ;.
It should be covered by { and } and replace } with}}.

Reference:
https://github.com/mkleehammer/pyodbc/wiki/Connecting-to-databases
https://stackoverflow.com/questions/78531086/pyodbc-connection-string-correctly-escaping-password-with-special-characters/78532507#78532507

@grieve54706 grieve54706 requested a review from goldmedal November 5, 2024 09:57
@github-actions github-actions bot added ibis python Pull requests that update Python code labels Nov 5, 2024
Comment on lines 168 to 172
def _escape_special_characters_for_odbc(value: str) -> str:
if ";" in value or value.startswith("{"):
return "{" + value.replace("}", "}}") + "}"
else:
return value
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we always add brackets? Maybe we don't need to check if it contains any illegal character? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to be okay.

@grieve54706
Copy link
Contributor Author

The connection string test should wait until ibis handles special characters by ibis-project/ibis#10437.

Copy link
Contributor

@goldmedal goldmedal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @grieve54706 LGTM

@goldmedal goldmedal merged commit d624ea6 into main Nov 5, 2024
7 checks passed
@goldmedal goldmedal deleted the bugfix/special-character branch November 5, 2024 10:55
@goldmedal
Copy link
Contributor

The connection string test should wait until ibis handles special characters by ibis-project/ibis#10437.

filed #890 for it

gagan-bhullar-tech pushed a commit to gagan-bhullar-tech/wren-engine that referenced this pull request Nov 6, 2024
@grieve54706 grieve54706 added this to the 0.11.3 milestone Nov 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ibis python Pull requests that update Python code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants