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 ...
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.
I solved this issue by accessing values:
rows[0].POST_TYPE.toString('utf8');
rows[0].CATEGORY.toString('utf8');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With