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

ConnectionHelper.php updateQuery prepending bindValues with N #5

Open
DavidWnek opened this issue Aug 27, 2018 · 3 comments
Open

ConnectionHelper.php updateQuery prepending bindValues with N #5

DavidWnek opened this issue Aug 27, 2018 · 3 comments

Comments

@DavidWnek
Copy link

In the following code, what was the reason for pre-pending the values with N?

https://github.com/mediamonks/symfony-mssql-bundle/blob/master/Helper/ConnectionHelper.php

  /**
     * @param $query
     * @param array $values
     * @return void|mixed
     */
    public static function updateQuery($query, array $values = [])
    {
        if (PlatformHelper::isWindows()) {
            return $query;
        }

        for ($i = 0, $offset = 0; $pos = strpos($query, '?', $offset); $i++) {
            $offset = $pos + 1;
            if (isset($values[$i]) && is_string($values[$i])) {
                $query = substr_replace($query, 'N?', $pos, 1);
                $offset++;
            }
        }

        return $query;
    }

We're using this bundle on Ubuntu servers, and it's failing due to the pre-pended 'N' on the values, when we remove the isWindows() check is seems to work fine.

Should this logic be here? Was it for an older version of doctrine?

We're using:

        "doctrine/orm": "^2.5.11",
        "doctrine/doctrine-bundle": "^1.6.10",
@slootjes
Copy link
Contributor

This is required when working with Unicode as can be read here; https://softwareengineering.stackexchange.com/questions/155859/why-do-we-need-to-put-n-before-strings-in-microsoft-sql-server

Can you share what exactly fails when using it?

@DavidWnek
Copy link
Author

screenshot from 2018-08-27 13-28-53

@slootjes
Copy link
Contributor

Never ran into this before... what version of SQL Server are you using?

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