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

SELECT N'' AS NVARCHAR not support #462

Open
ghost opened this issue Sep 27, 2021 · 5 comments
Open

SELECT N'' AS NVARCHAR not support #462

ghost opened this issue Sep 27, 2021 · 5 comments

Comments

@ghost
Copy link

ghost commented Sep 27, 2021

wp-db.php Line(2219) _insert_replace_helper
// $formats = implode( ', ', $formats );
$formats = implode( ', N', $formats );

@patrickebates
Copy link
Member

This is in response to the change in last patch #422 to force use of Unicode on insert? So this would be another place in the code that needs updating?

@ghost
Copy link
Author

ghost commented Oct 10, 2021

Yes, need to add (N') here one more place to fully support Unicode in MSSQL.

@srutzky
Copy link
Contributor

srutzky commented Oct 25, 2021

@achariyeak : Are you sure about this? The requested change does not look right. The header comment just above that function states:

A format is one of '%d', '%f', '%s' (integer, float, string).

Your proposed change would result in queries containing something like ... VALUES (N%d, N%s, N%s) (as an example), which would not work, especially when %d and %f are used.

Also, the $sql variable at the end of that function gets sent to the prepare() function anyway, so it will have string literals prefixed with N.

What exactly are you trying to do that does not seem to be working? What does the "SELECT N'' AS NVARCHAR" in the title refer to? I suppose if you are passing in your own query, and if that query were to use a placeholder prefixed with N (as in N'%s'), then my fix in #422 would result in the query being re-written as ... NN'%s' since the line that removes single-quotes (2 above the line that I fixed) does not account for N prefixes. The simple fix/workaround is to remove the N prefix. A more permanent solution would be to add a line above this one:

$query = str_replace( "'%s'", '%s', $query ); // Strip any existing single quotes.

being:

$query = str_replace( "N'%s'", '%s', $query ); // Strip any existing single quotes prefixed with "N".

Of course, this might not be the issue you are having, in which case we can either ignore this potential for the moment, or I can submit a separate PR for it, or maybe something else.

Again, please let us know precisely what you are trying to do, and why.

Thanks, Solomon..

@ghost
Copy link
Author

ghost commented Oct 29, 2021

It's now working fine,cause of my database table migration from existing one.

@srutzky
Copy link
Contributor

srutzky commented Oct 29, 2021

@achariyeak

It's now working fine, cause of my database table migration from existing one.

Ok, but can you please explain? Were your tables initially set up as VARCHAR and are now NVARCHAR? Was that the problem, or something else?

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

No branches or pull requests

2 participants