Gerardsson
Gerardsson

Reputation: 382

Node.js SQLite Call returns SQLITE_ERROR: no such table

I am setting up a database with customer data in SQLite 3.2.1 using Node.js in Javascript.

The error SQLITE_ERROR: no such table: T_KUNDENDATEN_DE keeps being returned. From the error I understand that the DB can be contacted. The SQL Query works and the variables vorname and nachname are correctly captured in the URL and passed to the db.all constructor. But it return the error. In debug-mode I cannot figure out what is going wrong here.

The table T_KUNDENDATEN_DE is not new and has data in it.

Any suggestions to resolve this issue?

URL used to call app.get('/cdata'. http://localhost:8000/cdata?vorname=ralf&nachname=ruf

[![Table & Database][1]][1]
// Create express app
var express = require("express")
var app = express()
var DateObj= new Date()
var sqlite3 = require('sqlite3');
var db = new sqlite3.Database('KundendatenJS.db');
// Server port
var HTTP_PORT = 8000 
// Start server
app.listen(HTTP_PORT, () => {
    console.log("Server running on port %PORT%".replace("%PORT%",HTTP_PORT))
});
// Root endpoint
app.get("/", (req, res, next) => {
    res.json({"message":"Ok" + " " + DateObj })
});

// API endpoints
app.get('/cdata', function(req, res){
    if(req.query.vorname  && req.query.nachname){
        db.all('SELECT * FROM T_KUNDENDATEN_DE WHERE UPPER(VORNAME) = UPPER(?) AND UPPER(NACHNAME)=UPPER(?)', [req.query.vorname,req.query.nachname], function(err, rows){
            if(err){
                res.send(err.message);

            }
            else{
                console.log("Return the customer data for: " + req.query.vorname + " " + req.query.nachname);
                res.json(rows);
            }
        });
    }
    else{
console.log("No data found")
    }
});

// Default response for any other request
app.use(function(req, res){
    res.status(404);
});```

Upvotes: 2

Views: 8240

Answers (1)

Gerardsson
Gerardsson

Reputation: 382

I auto-answered this question thanks to the comment by @messerbill.

The error occurs because the DB-path is not referenced correctly. SQLite create a new database if it cannot find an existing one. Hence SQLite will find a DB but not a table. The error message is misleading because it seems to point to an internal connection error.

Solution: Look in your solution for the path where a database is created. This will help you set the right path in your solution.

Upvotes: 11

Related Questions