Javascriptで定義された文字列をMSSQLテーブルに挿入する必要があります。Node.JSにMSSQLのプリペアドステートメントを作成するにはどうすればよいですか?
これは私がこれまで持っているものです。
Javascriptを:
var message = "It's a great day today!";
$.post('www.server.com/message='+message, function(response){
console.log(response);
});
のNode.jsサーバー:
//..... a bunch of code has been used to accept the HTTP request and get the message...
// for the purpose of this example, the message is asigned to 'NodeMsg'
var mssqldb = require("../core/mssql");
var NodeMsg = theMessageReceivedFromHTTPRequest;
function saveMessage(message) {
mssqldb.executeMssql("insert into messages (message, status) VALUES('"+message+"', 'new')", function (err) {
if (err) {
httpMsgs.show500(req, resp, err);
}//end if
else {
httpMsgs.sendJson(req, resp, 'success');
}//end else
});
};
mssql.js(Node.jsのファイル):
var mssqldb = require("mssql");
var settings = require("../settings");
exports.executeMssql = function(sql, callback) {
var conn = new mssqldb.Connection(settings.mssqlConfig);
conn.connect()
.then(function(){
var req = new mssqldb.Request(conn);
req.query(sql)
.then(function (recordset) {
callback(recordset);
})
.catch(function(err){
console.log(err);
callback(null, err);
});
})
.catch(function(err){
console.log(err);
callback(null, err);
});
};//end executeMssql
何が起こっているかの概要:
- 私は文字列としてメッセージを定義しています。 :私は
問題をMSSQLする文字列を送信するためのNode.jsを使用していますNode.jsのサーバー
解決策: 私が見つけたほとんどのリソースによれば、解決策は「Prepared Statements」を使用することです。
私の問題:
がどのように地球上で私は準備された文を利用するために、私はすでにやっている変換するのですか?私はHOURSのためにウェブを検索しました.Node.JSを使ってNode.JS(MySQLではない)の準備文をどのようにしてよいかを見つけることはできません。