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
Creating a Unicode where-clause with N-prefix #4442
Comments
you could use TypeDecorator.bind_expression (https://docs.sqlalchemy.org/en/latest/core/custom_types.html?highlight=bind_expression#sqlalchemy.types.TypeDecorator.bind_expression), however the database driver, e.g. pyodbc or pymssql, does this for you when the statement is executed (edit: zzzeek is stupidly missing that this is with literal binds). What is your actual use case? |
more appropriately it would be literal_processor() |
workaround:
so I may target this at 1.3 or 1.2.x not sure yet |
Mike Bayer has proposed a fix for this issue in the master branch: Render N'' for SQL Server unicode literals https://gerrit.sqlalchemy.org/1095 |
Btw, Oracle also has the same N-prefix, but based on my limited testing seems to do automatic casting. But you may want to target Oracle with the change, too, as it seems to be the recommended way of handling NCHAR and NVARCHAR on Oracle. |
I think I need to doa unicode literal round trip test to really confirm on all backends |
well Im unable to show that the "N" makes any difference on Oracle OR SQL server. can you please illustrate the problem you're having with SQL Server itself as well as what Python driver / database version you are using ? |
OK my SQL Server here is the linux one, this is the version string: Microsoft SQL Server 2017 (RTM-CU11) (KB4462262) - 14.0.3038.14 (X64) \n\tSep 14 2018 13:53:44 \n\tCopyright (C) 2017 Microsoft Corporation\n\tDeveloper Edition (64-bit) on Linux (CentOS Linux 7 (Core)) The database looks like I created it as: "CREATE DATABASE test;" e.g. i didn't specify any collation. For these string statements you are making, are you running those in with python and the driver as well? or is this cut-and-paste into a GUI ? i wonder if that affects things ? |
well let me just try py2k as well to make sure things aren't working smoothly, in trying to get this to fail |
I can't get it to fail, here's more or less the same test, py3k/py2k and pymssql/pyodbc, passes
in any case the N certainly isn't making things worse so I'll likely just push it through. |
hey let's try your unicode character and not the ones I have which might overlap with latin1 or something |
ding |
hooray. OK that was it. needed weirder characters. lets see what oracle says. |
yeah oracle doesn't need it. |
and adding this to the tests makes me have to deal with mysql utfmb4 all over again... |
this is looking kind of 1.3 ish now. are you worked around for 1.2.x ? |
Yeah sorry I should have stressed the part about using adequately weird characters, I wasted a good bit of time using accented ascii-compliant letters, too 😃 |
I agree about this being 1.3 material. I'm thinking we can live without this until 1.3 comes out (eager ones can go with the RC). |
Thanks @zzzeek for fixing this and loved the snaked-up French in the test cases 😆 |
I'm not sure if this is a SqlAlchemy issue or something with the dialect/connector, but is there some way to force the query compiler to prefix a Unicode string with N for e.g. MSSQL? If a column has been defined as
UnicodeText
(also triedNVARCHAR
, same result), one would expect a where clause on that column to be prefixed with an N for MSSQL. However, this doesn't automatically seem to happen, and I haven't been able to find any documentation on how to achieve this. Below is an example to illustrate the problem:This yields
while one would expect the unicode type to put an N-prefix on the where clause, like so:
Is there some way to either automatically get the N-prefix, or manually inject it, e.g. by using
TypeDecorator
?The text was updated successfully, but these errors were encountered: