Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

SQLSRV: N prefix should be added before any value to be inserted in NVARCHAR field #1602

Loupax opened this Issue Jul 10, 2012 · 5 comments


None yet
5 participants

Loupax commented Jul 10, 2012

Not sure if I should post this here, but here it goes...

Here is the deal: When I try to insert unicode values to a NVARCHAR column, the query should be something like this:

INSERT INTO test_table (title) VALUES (N'Iñtërnâtiônàlizætiøn')

Activerecord generates this query

INSERT INTO test_table (title) VALUES ('Iñtërnâtiônàlizætiøn')
and this makes all special character information to be stripped from the string, making the inserted data being this: Internationaliz?tion

If this functionality is implemented, it guarantees painless UTF-8 data inserting and fetching from SQL servers


narfbg commented Jul 10, 2012

That's impossible to do without prepared statements.

Loupax commented Jul 10, 2012

Too bad... Thanks to MS now I was forced to do this ugly hack that luckily doesn't break my queries so far...

function _insert($table, $keys, $values)
foreach ($values as &$value){
if (substr($value, 0,1)==="'"){
$value = 'N'.$value;
return "INSERT INTO ".$this->_escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")";

It's funny... Even dated get inserted properly like that!

your solution solves 'insert' and 'update' cases but not the problem with 'WHERE' clause and i really need help with this one

Loupax commented May 22, 2013

Could not find a better solution than changing the collation of the query itself :/

Why this is a 4.0 feature? Maybe we need a temporary workaround for this to support unicode now on MSSQL. I think an 'ugly' or performance-intense' fix is probably better that nothing.

@narfbg narfbg modified the milestone: 3.1.0, 4.0.0 Jul 17, 2015

@narfbg narfbg self-assigned this Jul 17, 2015

@narfbg narfbg referenced this issue Aug 7, 2015


Firebird blod #4035

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment