Skip to content

Problem with Persian/Arabic characters when using input() #1625

@ShahriarKh

Description

@ShahriarKh

I noticed that there's a problem with Persian/Arabic characters when using .input().

Note

Both ی (Persian) and ي (Arabic) represent the ~same character but with different unicodes.
In my database, since there isn't strict formatting rules, both forms exist; for example, both 'شادی' and 'شادي' are possible and acceptable values.

When I directly write the value in my query, it works as desired and both values return data.

// ✅ Works
data = await pool.request().query(`select Name as first_name from People where Name = 'شادی'`);
// ✅ Works
data = await pool.request().query(`select Name as first_name from People where Name = 'شادي'`);

Using JS variables works too:

// ✅ Works
const PERSIAN = 'شادی';
data = await pool.request().query( `select Name as first_name from People where Name = '${PERSIAN}'`);
// ✅ Works
const ARABIC = 'شادي';
data = await pool.request().query( `select Name as first_name from People where Name = '${ARABIC}'`);

But when I use input() to utilize sql variables, only the Arabic text works:

// ✅ Works
data = await pool.request()
  .input('nameVar', NVarChar(20), 'شادي')
  .query(`select Name as first_name from People where Name = @nameVar`);
// 🔴 Doesn't Work
data = await pool.request()
  .input('nameVar', NVarChar(20), 'شادی')
  .query(`select Name as first_name from People where Name = @nameVar`);

Seem like there's an issue with input() and how it passes data to query, because using variables with both values work in sql (direct query)

-- ✅ Works
declare @nameVar nvarchar(20) = 'شادی'
select
  name
from
  people
where
  name = @nameVar
-- ✅ Works
declare @nameVar nvarchar(20) = 'شادي'
select
  name
from
  people
where
  name = @nameVar

Expected behaviour:

input() should behave like direct queries and don't change characters or anything.

Software versions

  • NodeJS: v18.18.2
  • node-mssql: v10.0.1
  • SQL Server: 15.0.2000.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    upstreamRoot cause is in an upstream dependency

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions