sql-cli icon indicating copy to clipboard operation
sql-cli copied to clipboard

.run with a utf-8 script with unicode strings does wrong conversion

Open etiennellipse opened this issue 6 years ago • 0 comments

Version: 0.6.2 MacOS 10.14.4 Node v10.15.2

I have a SQL script encoded in UTF-8 that contains insert statements with unicode strings that are inserting in a NVARCHAR field. When I run this script, the data inserted in the table is malformed.

Example:

CREATE TABLE homeInstitution
(
    id INT IDENTITY(0,1) NOT NULL PRIMARY KEY,
    institution NVARCHAR(128) NOT NULL,
    deletedDate DATETIME NULL,
);

INSERT [dbo].[homeInstitution] ([institution], [deletedDate]) VALUES (N'Lycée ÀÉÙÇÊÏ', NULL)
  1. Save this into a UTF-8 encoded file
  2. Connect to mssql, run the script: .run myfile.sql
  3. select * from homeInstitution

Result:

mssql> select * from homeInstitution;
id  institution    deletedDate
--  -------------  -----------
0   Lycée ÀÉÙÇÊÏ  null

1 row(s) returned
  • If I convert the file to ISO-8859-1 format, the data is inserted correctly

etiennellipse avatar Apr 16 '19 13:04 etiennellipse