Skip to content

[5.0] Special chars and sqlsrv #7253

@henriquebremenkanp

Description

@henriquebremenkanp

Problem

Special chars in sqlsrv driver come to the model as "non-utf8" chars which makes Queues, Views and Json output to not work as serialization/json_encode don't support it.

Case

I tried to fetch some data from a legacy SQL Server that contains special chars like áíúéóãõç and when I try to call toJson() I get:

UnexpectedValueException in Response.php line 403:
The Response content must be a string or object implementing __toString(), "boolean" given.

Commands that will be serialized for queues doesn't work:
DoSomething(SpecialCharsModel $foo, User $user)
$foo will be serialized as null.

My connection:

'linx' => [
    'driver'   => 'sqlsrv',
    'host'     => env('DB_LINX_HOST', '192.168.0.2'),
    'database' => env('DB_LINX_DATABASE', 'a'),
    'username' => env('DB_LINX_USERNAME', 'a'),
    'password' => env('DB_LINX_PASSWORD', 'a'),
    'prefix'   => '',
],

Collation is SQL_Latin1_General_CI_AS

Workaround

Overwriting setRawAttributes() made it work.

public function setRawAttributes(array $attributes, $sync = false)
    {
        foreach ($attributes as $index => $attribute)
        {
            $attributes[$index] = utf8_encode($attribute);
        }
        return parent::setRawAttributes($attributes, $sync);
    }

I don't know the complexity of this issue at framework level, but if all other drivers don't break, I think would be interesting to have sqlsrv working out of the box too.

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