michaelwittig / node-q

Q interfacing with Node.js
MIT License
52 stars 14 forks source link

Unicode string turns into a messy code #35

Closed liutongwei closed 6 years ago

liutongwei commented 6 years ago

Examples:

var nodeq = require("node-q");

nodeq.connect({ host: "localhost", port: 5000 }, function(err, con) {
    if (err) throw err;
    console.log("connected");
    // interact with con like demonstrated below 
    con.k('aa:`$"你好"', function(err, res) {
        if (err) throw err;
        console.log("result", res); // 6 
    });
    con.close(function() {
        console.log("con closed");
    });
});

But when I look at the variable aa in q, it returns with a totally different string:

`浣犲ソ

How could I solve this problem?

michaelwittig commented 6 years ago

I can not really reproduce any issues with unicode? I adjusted your example slightly to fix a issue with the async code in your node.js example. I also return aa after the assignment in the q code.

nodeq.connect({ host: "localhost", port: 5000 }, function(err, con) {
    if (err) throw err;
    console.log("connected");
    con.k('aa:`$"你好"; aa', function(err, res) {
        if (err) throw err;
        console.log("result", res);
        con.close(function() {
            console.log("con closed");
        });
    });
});

outputs

connected
result 你好
con closed

what return do you expect from a variable assignment?

liutongwei commented 6 years ago

Hi, @michaelwittig Thanks for your reply.

I could receive the same output as your reply from node side. But when I typed aa in q terminal, it returned with 浣犲ソ.

qq 20170922105115

The problem is that I would like to read a .csv file in q which contains unicode like Chinese characters, using the code:

CstInfo:("sdsssbsssssfs"; 1# ",")0: `CustomerInfo.csv

And it returns with the CstInfo correctly like below:

qq 20170922105856

But when I use the nodeq command to fetch data from CstInfo:

nodeq.connect({ host: "localhost", port: 5000 }, function(err, con) {
    if (err) throw err;
    console.log("connected");
    con.k('1# select from CstInfo', function(err, res) {
        if (err) throw err;
        console.log("result", res);
        con.close(function() {
            console.log("con closed");
        });
    });
});

The output does not show correctly, seen the content surrounded by red lines (sorry for the mask):

qq 20170922110756

So is there any method I could take to solve this problem?

Thanks again for your reply.

michaelwittig commented 6 years ago

couldyou provide my one of those CstNames that is not working as text? I can not extract the test data from the image easily.

liutongwei commented 6 years ago

Hi, @michaelwittig. Thanks for your reply. I am sorry that I forgot to attach the csv file. Here is the CustomerInfo.csv which contains Chinese characters. Maybe you could open it with charset GBK to see the correct demonstration as shown in the image above.

CustomerInfo.zip

And you could just copy the unicode string 广发证券股份有限公司(OTC)to clipboard to use these characters.

It is so kind of you to spend your time on this problem.

liutongwei commented 6 years ago

Hi, @michaelwittig.

Now I can solve the charset problem. The reason is because I save the .csv file using charset GBK. When I save it with charset Unicode, the output shows correctly.

unnamed qq screenshot20170922202455

But the Unicode string could not be shown as what it should be in the q terminal.

unnamed qq screenshot20170922203118

This is a very tricky problem. I think it is not about node-q, but I should deal with q.

Thank you so much. I do appreciate your time.