Skip to content
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

'?' always replaced as parameter (even in string literals and comments) #13

Closed
hochhaus opened this issue Apr 21, 2014 · 4 comments · Fixed by #14
Closed

'?' always replaced as parameter (even in string literals and comments) #13

hochhaus opened this issue Apr 21, 2014 · 4 comments · Fixed by #14

Comments

@hochhaus
Copy link
Contributor

Thanks for all of the work @denisenkom and @dimdin. It is exciting how quickly go-mssqldb is maturing. I am a bit concerned with change 0a8a8cf that uses '?' for parameters. I'm interested in both your thoughts about the best way to proceed.

It looks like if go-mssqldb uses '?' the library will need to parse the query and replace '?' with @px (where X is the integer field number). However, parsing the query in the client side library seems error prone to get all of the cases correct (eg: string literals, comments, etc). We could definitely improve the implementation of parseParams() to handle these cases, however it seems like it might be better to avoid parsing the query all together client side (if possible).

The plus side is that '?' does seem like the standard character to use for MS SQL so I like the change from this perspective.

Does anyone know how other mssql client libraries are doing this? I know nothing about TDS so I'm not sure of the limitations we are facing at the protocol level.

Thoughts?

@dimdin
Copy link
Collaborator

dimdin commented Apr 21, 2014

I shall extend the parseParams to scan the SQL statement and replace the ? only in the appropriate state i.e. not in comments, strings and identifiers.

@denisenkom
Copy link
Owner

Underlying protocol only supports "at" prefixed parameter names, support for question marks is supported by client library, freetds does exactly this.
BTW it doesn't have to be question marks, it might be something more appropriate to given platform, for example pytds supports format and pyformat http://legacy.python.org/dev/peps/pep-0249/#paramstyle

@hochhaus
Copy link
Contributor Author

Thanks for the comments and patch! This makes sense.

@dimdin
Copy link
Collaborator

dimdin commented Apr 22, 2014

It makes sense to have positional positional parameters, :1, :2 like Oracle or $1, $2 like PostgreSQL.
The patch can be extended to support them.

denisenkom added a commit that referenced this issue Apr 22, 2014
replace ? only in the correct context, resolves issue #13
odeke-em pushed a commit to orijtech/go-mssqldb that referenced this issue Jul 26, 2020
prochac pushed a commit to prochac/go-mssqldb that referenced this issue Sep 30, 2022
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 a pull request may close this issue.

3 participants