Repository navigation
Prefix string literals with N in mssql - #5039
Conversation
|
This probably fits better in data types, @janmeier? |
|
@mickhansen, the enclosing quotes for string literals are put-in in the SqlString.escape function. Since N'...' can be thought as a special variant of enclosing quotes, I thought it would be the right function to modify. Given my unfamiliarity with internals of sequelize, If you could provide a more specific suggestion as to where to look at, I am willing to put in the effort and get this fixed at the soonest. On the other hand, if this is good enough then I can also fix those test cases which fail after this fix (they fail because they do not anticipate the N prefix in the built mssql queries at the moment). On a separate note, this has been a showstopper for us. Not getting it fixed basically means sequelize is not usable (with mssql) in majority of Asia. |
dafca02 to
3cec936
Compare
|
@janmeier will chime have to chime in here, but since it's mssql specific i think it's better suited being implemented on mssql specific data types: https://github.com/sequelize/sequelize/blob/master/lib/dialects/mssql/data-types.js |
|
Thanks for the pointer, I'll look at it. Meanwhile, on the defence of the current approach, the modified if (dialect === 'postgres' || dialect === 'sqlite' || dialect === 'mssql') {
// http://www.postgresql.org/docs/8.2/static/sql-syntax-lexical.html#SQL-SYNTAX-STRINGS
// http://stackoverflow.com/q/603572/130598
val = val.replace(/'/g, "''");
} else {
val = val.replace(/[\0\n\r\b\t\\\'\"\x1a]/g, function(s) {
switch (s) {By the way, I have modified the test cases accordingly (anticipating the N prefix for mssql) and they all are passing now. |
|
@zapatek It indeed does, and we'd like to fix that going forward :) |
There was a problem hiding this comment.
The ? should not be present in the final result, as evident from the existing test.
There was a problem hiding this comment.
Ah, that question mark added in the fix is just a regular expression quantifier, meaning one or zero N characters are expected (to cover cases for mssql - one - and other dialects - zero - respectively)
There was a problem hiding this comment.
Oh right, my bad, for a second i missed that you changed it to a regex.
|
Okay looking at the tests you changed i'm not sure that a change to data types will be sufficient actually, but we'll have to wait for @janmeier to take a look |
|
Nah, I think this is the best way to fix it for now - either that or we have to move some more of the logic for proper escaping etc. into data types as well - So I think this is fine for now |
|
Could you add a changelog entry, then this should be good to go? |
|
Done. |
|
Seems like just missed the 3.15.0 release. Rebased the work branch for this fix to the tip of master to resolve the resultant conflict on changelog.md |
|
I'll cut another one once i merge a few pending PRs :) |
|
@zapatek Ah damn, looks like we need another rebase. Please do ping me when it's done and tests have run so i can get it merged in time. |
d11c88b to
f9980fc
Compare
|
Amended the conflicting changelog.md but seems it wasn't in time for 3.15.1, so I put the entry under the 'Future' header. If you could merge now, it would surely make it into next release.. :) |
|
And needs a new rebase, how the hell does this keep happening to this PR :p |
e8ffbb3 to
14105e7
Compare
|
Haha, this time the culprit was |
Prefix string literals with N in mssql
|
This explains why my latin-encoded columns no longer work. I have a view that has the following structure:
When I use a pretty standard Sequelize raw query, it generates the following with this new code: SELECT [Column_A], [Column_B]
FROM [xyzView] AS [xyzView]
WHERE [xyzView].[Column_A] LIKE N'Value' OR [xyzView].[Column_B] LIKE N'Value'Unfortunately, that code does not return any results. Dropping the Unicde prefix |
|
@brentjanderson I don't believe any override is availabe, please do provide a PR |
|
Why don't update this changes in sequelize latest version??? |
Fixes #3752