Skip to content

ConnectionHelper.php updateQuery prepending bindValues with N #5

@DavidWnek

Description

@DavidWnek

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",

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions