Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NodeJS MYSQL Query result Buffer?

mysql select query result ...

//nodejs database.js
var mysql      = require('mysql');
var connection = mysql.createConnection({
    host     : 'localhost',
    user     : 'me',
    database : 'test',
    password : '1234'
});

// nodejs app.js
app.get('/api/v0.1/getPostList', function(req, res) {
        limit_count = 5;
        db.query(postModel.postList(limit_count) , function(err, rows) {
            if (err) throw err;
            console.log(rows)
            res.json(rows);
        });
    });

//result
RowDataPacket {
    POST_SEQ: 13,
    POST_TYPE: <Buffer 31 31 30 30>,
    CATEGORY: <Buffer 49 54 20 2f 20 4d 4f 42 49 4c 45>, ...

why query data buffer type?
I do not know the cause.

java query data success
[DEBUG][2016-10-28 19:20:24,160] <== Row: 13, 1100, GAME ...

like image 732
kimyeonho Avatar asked Mar 10 '23 19:03

kimyeonho


2 Answers

I had this issue with int values generated by COUNT. I was able to resolve the issue by casting these values to CHAR within my query. They then came back correctly formatted as js strings. Here's a sample query:

SELECT Date, Park, COUNT(FileID) FROM SkatePix WHERE Park != '' AND Date != 0 GROUP BY Date, Park LIMIT 5;

I changed the COUNT statement to be:

 CAST(COUNT(FileID) AS CHAR) /* formerly COUNT(FileID) */

This did the trick.

like image 132
Nick Dallett Avatar answered Mar 19 '23 23:03

Nick Dallett


I solved this issue by accessing values:

rows[0].POST_TYPE.toString('utf8');
rows[0].CATEGORY.toString('utf8');

like image 26
Ekjot Kaur Avatar answered Mar 20 '23 00:03

Ekjot Kaur