2015-06-29 80 views
-1

在每的NodeJS我嘗試同時使用懷疑MySQL的和的NodeJS

var geometry = 'GeomFromText(&rsquoPOLYGON('+Area1x+' '+Area1y+','+Area2x+' '+Area2y+','+Area3x+' '+Area3y+','+Area4x+' '+Area4y+','+Area1x+' '+Area1y+')&rsquo,0)'; 
// console.log(geometry); 
var data = { 
    "error":1, 
    "Area":"" 
}; 
if(!!Areanome && !!Area1x){ 
var query =  connection.query("INSERT INTO likeyouarea VALUES(null,?,?)",[Areanome,geometry],function(err, rows, fields){ 

在sql突擊隊由CONSOLE.LOG(query.sql的)公開此;

INSERT INTO area VALUES(null,'area2','GeomFromText(&rsquoPOLYGON(-30.02724579591031 -51.22842527925968,-30.027021410835776 -51.22754216194153,-30.027769165561978 -51.22727394104004,-30.02800603078958 -51.228153705596924,-30.02724579591031 -51.22842527925968)&rsquo,0)') 

但正確的查詢和它的工作,但在phpMyAdmin的控制檯

INSERT INTO area VALUES(null,'area2',GeomFromText('POLYGON((-30.02724579591031 -51.22842527925968,-30.027021410835776 -51.22754216194153,-30.027769165561978 -51.22727394104004,-30.02800603078958 -51.228153705596924,-30.02724579591031 -51.22842527925968))',0)) 

如何使用正確的方法usingo geoFromText它是一個命令不是字符串

我已經看這個INSERT INTO fails with node-mysql 但它都是根據mysql

回答

0

嘗試使用:

var geometry = 'POLYGON('+Area1x+' '+Area1y+','+Area2x+' '+Area2y+','+Area3x+' '+Area3y+','+Area4x+' '+Area4y+','+Area1x+' '+Area1y+')'; 

... 

var query = connection.query("INSERT INTO likeyouarea VALUES(null,?,GeomFromText(?,0))",[Areanome,geometry],function(err, rows, fields){ ... }; 
+0

感謝這個給我一盞燈,理解問題^ _ ^ –

0

我缺少一個第二(在多邊形

var geometry = 'POLYGON(('+Area1x+' '+Area1y+','+Area2x+' '+Area2y+','+Area3x+' '+Area3y+','+Area4x+' '+Area4y+','+Area1x+' '+Area1y+'))'; 
// console.log(geometry); 
var data = { 
    "error":1, 
    "Area":"" 
}; 
if(!!Areanome && !!Area1x){ 
var query = connection.query("INSERT INTO area VALUES(null,?,GeomFromText(?,0))",[Areanome,geometry],function(err, rows, fields){