2016-02-25 145 views
2

我需要執行插入和在這樣執行多個查詢

INSERT INTO COMPANY (ID,NAME) VALUES (1, 'Paul');DELETE FROM COMPANY WHERE ID='12'; 

一條語句刪除查詢這是我的node.js代碼執行查詢

pg.connect(pgConString, function (err, client, done) { 
     if (err) { 
      callBack("DB connection failed. " + err, null); 
      return; 
     } 
     var query = client.query({ 
      text: "INSERT INTO COMPANY (ID,NAME) VALUES (1, 'Paul');DELETE FROM COMPANY WHERE ID='12';" 
      values: [1, "Poul1"], 
      name: "insertQuery" 
     }); 
     query.on("error", function (err) { 
      callBack("DB insertion failed. Error Message: " + err, null); 
      return; 
     }); 

     query.on('end', function (result) { 

      done(); 
      return; 
     }); 
    }); 

我得到了這樣的

error: cannot insert multiple commands into a prepared statement

錯誤消息是有可能在執行多個查詢postgresql數據庫使用node.js?

+0

你試過嗎?你有什麼錯誤嗎? –

+0

我得到了一個錯誤。 –

+0

沒有準備好的陳述沒有準備 –

回答

1

嘗試這樣

pg.connect(pgConString, function (err, client, done) { 
    if (err) { 
     callBack("DB connection failed. " + err, null); 
     return; 
    } 
    client.query({ 
     text: "INSERT INTO COMPANY (ID,NAME) VALUES (1, 'Paul');", 
     values: [1, "Poul1"], 
     name: "insertQuery" 
    }); 

    client.query({ 
     text: "DELETE FROM COMPANY WHERE ID='12';", 
     name: "deleteQuery" 
    }); 

    client.on("error", function (err) { 
     callBack("DB insertion failed. Error Message: " + err, null); 
     return; 
    }); 


}); 
+0

謝謝你的回答。問題已經解決了。 –