mysql.escape()
[링크 : https://stackoverflow.com/.../er-parse-error-on-node-mysql-when-inserting-multiple-values]
timestamp는 CURRENT_TIMESTAMP 로 설정시 자동으로 입력됨
[링크 : https://blog.naver.com/star_breeze/220534943357]
이것저것 해보는데.. new Buffer().toString()이 유효했다!
$ node > var tt = [39,91,92,39,105,110,112,117,116,35,115,101,108,95,48,95,49,92,39,44,92,39,105,110,112,117,116,35,115,101,108,95,48,95,51,92,39,44,92,39,105,110,112,117,116,35,115,101,108,95,48,95,53,92,39,93,39] undefined > var buffer = new Buffer(tt) undefined > buffer <Buffer 27 5b 5c 27 69 6e 70 75 74 23 73 65 6c 5f 30 5f 31 5c 27 2c 5c 27 69 6e 70 75 74 23 73 65 6c 5f 30 5f 33 5c 27 2c 5c 27 69 6e 70 75 74 23 73 65 6c 5f ... > > buffer.toString('base64') 'J1tcJ2lucHV0I3NlbF8wXzFcJyxcJ2lucHV0I3NlbF8wXzNcJyxcJ2lucHV0I3NlbF8wXzVcJ10n' > var buffer = new Buffer(tt, 'binary') undefined > buffer.toString('base64') 'J1tcJ2lucHV0I3NlbF8wXzFcJyxcJ2lucHV0I3NlbF8wXzNcJyxcJ2lucHV0I3NlbF8wXzVcJ10n' > tt.toString('utf-8') '39,91,92,39,105,110,112,117,116,35,115,101,108,95,48,95,49,92,39,44,92,39,105,110,112,117,116,35,115,101,108,95,48,95,51,92,39,44,92,39,105,110,112,117,116,35,115,101,108,95,48,95,53,92,39,93,39' > buffer.toString('utf-8') '\'[\\\'input#sel_0_1\\\',\\\'input#sel_0_3\\\',\\\'input#sel_0_5\\\']\'' > new Buffer(tt).toString( ... 'utf-8') '\'[\\\'input#sel_0_1\\\',\\\'input#sel_0_3\\\',\\\'input#sel_0_5\\\']\'' > new Buffer(tt).toString() '\'[\\\'input#sel_0_1\\\',\\\'input#sel_0_3\\\',\\\'input#sel_0_5\\\']\'' |
[링크 : https://stackoverflow.com/questions/9042327/node-js-reading-blob-from-mysql]
[링크 : https://gist.github.com/akirattii/86e2eda8e110976cce144c991e9cada8]
그나저나 escape의 향연 어쩔꺼야...
+
mysql에 BLOB 타입으로 JSON을 저장하면
node.js에서는 아래와 같이 Buffer에다가 값을 넣고 toString() 으로 문자열로 바꾸어준 다음
mysql.escape()를 통해 \" 식으로 된걸 원래대로 돌려주어야 한다.
server-side(node.js)
mysql.escape(new Buffer(row.element).toString("utf-8")); |
그리고 받는 쪽에서는 JSON이 아닌 일반 plain-text니까
JSON.parse를 통해서 JSON으로 변환해 주어야 한다.(eval은 빼도 되는지 확인 필요)
client-side(chrome, web browser)
JSON.parse(eval(data.json)); |
'Programming > node.js' 카테고리의 다른 글
node.js sqlite3 (0) | 2018.11.26 |
---|---|
node.js xml <-> json (0) | 2018.11.25 |
sqlite for node.js (0) | 2018.11.21 |
node.js swagger (0) | 2018.11.12 |
node.js axios delete에 body 쓰기 (0) | 2018.11.12 |