为什么我的 Nodejs 应用程序看不到我的 sqlite3 数据库列?
Why can't my Nodejs application cannot see my sqlite3 database column?
没有与数据库或 table 关联的错误,但它没有看到列。这是错误:
节点服务器是 运行..
SQLITE_ERROR:没有这样的栏目:场景
这是table:
CREATE TABLE animalStream (
id INTEGER PRIMARY KEY AUTOINCREMENT,
cascade_name TEXT NOT NULL,
enclosre_name TEXT NOT NULL,
scene TEXT NOT NULL,
sensorCamAddress TEXT NOT NULL,
streamerCamAddress TEXT NOT NULL,
duration INTEGER NOT NULL
);
下面的 Nodejs 代码允许我从 HTML 表单接收数据
const path=require('path');
const sqlite3 = require("sqlite3").verbose();
const db_name = path.join(__dirname, "wildlife.db");
const db = new sqlite3.Database(db_name);
var express = require('express');
var app = express();
var bodyParser = require("body-parser");
app.use(bodyParser.urlencoded({ extended: false }));
app.get('/', function (req, res) {
res.sendFile('/home/harry/interface/in9.html');
});
app.post('/submit-student-data', function (req, res) {
var scene = req.body.scene
var cascade_name = req.body.cascade_name;
var enclosre_name = req.body.enclosre_name;
var sensorCamAddress = req.body.sensorCamAddress
var streamerCamAddress = req.body.streamerCamAddress
var duration = req.body.duration;
db.run(`INSERT INTO animalStream(scene) VALUES(scene)`, ['C'], function(err) {
if (err) {
return console.log(err.message);
}
// get the last insert id
console.log(`A row has been inserted with rowid ${this.lastID}`);
});
});/////////////////
var server = app.listen(3000, function () {
console.log('Node server is running..');
});
<!DOCTYPE html>
<html><body style="background-color:black;"><blockquote><blockquote>
<form action="/submit-student-data" method="post">
<p style="color:white;">Cascade file name:<br>
<input type = "text" name = "cascade_name" /></p>
<p style="color:white;">Enclosure name:<br>
<input type = "text" name = "enclosre_name" /></p>
<p style="color:white;">Scene number:<br>
<input type = "text" name = "scene" /></p>
<p style="color:white;">Sensor Camera IP address:
<br> <input type = "text" name = "sensorCamAddress" /></p>
>
<p style="color:white;">Streamer Camera IP address:
<br> <input type = "text" name = "streamerCamAddress" /></p>
<p style="color:white;">Scene duration:
<br><input type = "text" name = "duration" /></p>
<br>
<center> <INPUT type="submit" value="Send"> <INPUT type="reset"></center>
</form>
</blockquote></blockquote>
</body></html>
正如我提到的,它似乎可以获取数据库并且 table 很好。由于某种原因,它只是看不到这些列。我将不胜感激。
我想你必须这样写你的查询:
`INSERT INTO animalStream (scene) VALUES("${scene}")`
而且您没有为设置 NOT NULL
的其他列设置任何值
没有与数据库或 table 关联的错误,但它没有看到列。这是错误: 节点服务器是 运行.. SQLITE_ERROR:没有这样的栏目:场景
这是table:
CREATE TABLE animalStream (
id INTEGER PRIMARY KEY AUTOINCREMENT,
cascade_name TEXT NOT NULL,
enclosre_name TEXT NOT NULL,
scene TEXT NOT NULL,
sensorCamAddress TEXT NOT NULL,
streamerCamAddress TEXT NOT NULL,
duration INTEGER NOT NULL
);
下面的 Nodejs 代码允许我从 HTML 表单接收数据
const path=require('path');
const sqlite3 = require("sqlite3").verbose();
const db_name = path.join(__dirname, "wildlife.db");
const db = new sqlite3.Database(db_name);
var express = require('express');
var app = express();
var bodyParser = require("body-parser");
app.use(bodyParser.urlencoded({ extended: false }));
app.get('/', function (req, res) {
res.sendFile('/home/harry/interface/in9.html');
});
app.post('/submit-student-data', function (req, res) {
var scene = req.body.scene
var cascade_name = req.body.cascade_name;
var enclosre_name = req.body.enclosre_name;
var sensorCamAddress = req.body.sensorCamAddress
var streamerCamAddress = req.body.streamerCamAddress
var duration = req.body.duration;
db.run(`INSERT INTO animalStream(scene) VALUES(scene)`, ['C'], function(err) {
if (err) {
return console.log(err.message);
}
// get the last insert id
console.log(`A row has been inserted with rowid ${this.lastID}`);
});
});/////////////////
var server = app.listen(3000, function () {
console.log('Node server is running..');
});
<!DOCTYPE html>
<html><body style="background-color:black;"><blockquote><blockquote>
<form action="/submit-student-data" method="post">
<p style="color:white;">Cascade file name:<br>
<input type = "text" name = "cascade_name" /></p>
<p style="color:white;">Enclosure name:<br>
<input type = "text" name = "enclosre_name" /></p>
<p style="color:white;">Scene number:<br>
<input type = "text" name = "scene" /></p>
<p style="color:white;">Sensor Camera IP address:
<br> <input type = "text" name = "sensorCamAddress" /></p>
>
<p style="color:white;">Streamer Camera IP address:
<br> <input type = "text" name = "streamerCamAddress" /></p>
<p style="color:white;">Scene duration:
<br><input type = "text" name = "duration" /></p>
<br>
<center> <INPUT type="submit" value="Send"> <INPUT type="reset"></center>
</form>
</blockquote></blockquote>
</body></html>
正如我提到的,它似乎可以获取数据库并且 table 很好。由于某种原因,它只是看不到这些列。我将不胜感激。
我想你必须这样写你的查询:
`INSERT INTO animalStream (scene) VALUES("${scene}")`
而且您没有为设置 NOT NULL