Skip to content

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

Merged
goldmedal merged 3 commits intomainfrom
bugfix/special-character
Nov 5, 2024
Merged

fix(mssql): escape special characters for odbc#889
goldmedal merged 3 commits intomainfrom
bugfix/special-character

Conversation

@grieve54706
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor Author

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

Copy link
Copy Markdown
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
@goldmedal goldmedal deleted the bugfix/special-character branch November 5, 2024 10:55
@goldmedal
Copy link
Copy Markdown
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