SQLITE_ERROR: no such column:
(1) By hahobson on 2022-01-06 06:14:34 [link] [source]
Having difficulty with inserting records into my database. The scheme is as follows:
CREATE TABLE animalStream( id INTEGER PRIMARY KEY AUTOINCREMENT, cascade_name TEXT NOT NULL, enclosure_name TEXT NOT NULL, scene TEXT NOT NULL, sensorCamAddress TEXT NOT NULL, streamerCamAddress TEXT NOT NULL, duration INTEGER NOT NULL );
Here is the Nodejs code:
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 enclosure_name = req.body.enclosure_name; var sensorCamAddress = req.body.sensorCamAddress var streamerCamAddress = req.body.streamerCamAddress var duration = req.body.duration;
db.run(INSERT INTO animalStream('duration') VALUES(duration)
, ['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..'); });
And here is the HTML form:
<!DOCTYPE html>
<body style="background-color:black;"></body><form action="/submit-student-data" method="post">Cascade file name:
<input type = "text" name = "cascade_name" />Enclosure name:
<input type = "text" name = "enclosure_name" />Scene number:
<input type = "text" name = "scene" />Sensor Camera IP address:
>
<input type = "text" name = "sensorCamAddress" />Streamer Camera IP address:
<input type = "text" name = "streamerCamAddress" />Scene duration:
<input type = "text" name = "duration" />
<INPUT type="submit" value="Send"> <INPUT type="reset"> </form>
(2) By Larry Brasfield (larrybr) on 2022-01-06 06:47:23 in reply to 1 [source]
There are several problems with your INSERT attempt and post.
This is a SQL string or text literal: 'duration'
It cannot be a column name. You can double-quote identifiers in SQL, but single-quoted text is not an identifier; it is a text value.You have 6 NOT NULL constraints in your schema for animalStream. Your successful inserts into that table will need to provide 6 values per row inserted for those columns having a NOT NULL constraint.
This forum is not about NodeJS and your post contains much extraneous verbiage related to your application which has nothing to do with SQLite.
(3) By hahobson on 2022-01-06 08:43:36 in reply to 2 [link] [source]
Thanks, I followed your instructions, but no joy. SQlite still says column does not exist. I changed from "duration" to "cascade_name" and I made it and ID the only columns in the table. Thanks anyways.