3

Using Node.JS with the SQLlite3 module I created a table: 'users' in my database with 2 columns: 'name' and 'surname'.

// Importing database
var fs = require('fs');
var file = 'test.db';
var exists = fs.existsSync(file);
var sqlite3 = require("sqlite3").verbose();
let db = new sqlite3.Database(file)

//inserting first user
db.run('INSERT INTO users VALUES(?, ?)', ['"John", "Doe"'])
db.close();

Instead of adding the value 'John' to 'name' and 'Doe' to surname, it adds the value ' "John", "Doe" ' to name and null to surname.

1 Answer 1

4

Parameter of db.run should have been passed as an array when using multiple placeholders instead of a string. Solution:

db.run('INSERT INTO users VALUES(?, ?)', ['John', 'Doe'])
db.close();
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for stating the most simple and direct answer which is not answered in proper tutorials also!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.