Tag Archives: sqlite

SQLITE_CANTOPEN

21 Aug 2019

While working with a SQLite3 database in Node using KNEX and Objection I encountered this error:

UnhandledPromiseRejectionWarning:
Error: SQLITE_CANTOPEN: unable to open database file

Seems that using relative paths isn’t a good idea. Setting the absolute path to the SQLite file instead resolves this using Node’s __dirname variable. From there simply construct the rest of your path to the database.

Your knexfile.js file can stay as-is, where you specify the path to where the database should be created. Instead look at the file you use to setup Knex/Objection and specify the absolute path there. For example:

const { Model } = require('objection');
const Knex = require('knex');

const knex = Knex({
  client: 'sqlite3',
  useNullAsDefault: true,
  connection: {
    filename: `${__dirname}/path/to/db.sqlite3`,
  },
});

Another error related to not finding the database is one which claims to not being able to find the specified table when in fact it does exist.

UnhandledPromiseRejectionWarning:
Error: SQLITE_ERROR: no such table: [table name]

As above, set the absolute path to the SQLite file.

Installing The SQLite PhoneGap Plugin via the CLI

30 Apr 2014

For some reason I had issues trying to install the PhoneGap SQLite plugin for Android on my Windows 8.1 laptop using the CLI. Attempting to run the install resulted in a Command failed: fatal: could not create work tree dir error. After some fruitless searching for a solution I took another look at the error message and thought that maybe the problem would be something simple to resolve.

This type of CLI command usually works:

$ phonegap plugin add https://github.com/brodysoft/Cordova-SQLitePlugin.git

As mentioned this resulted in the following error:

sqlite_npm_install

 

The key to solving this is in the error message – apparently the temp path can’t be created…. so… create it!

Using Explorer navigate to this path:

  • C:\Users\[YOUR USER NAME]\AppData\Local\Temp

 
Note that “AppData” is likely a hidden folder – just enter the path (use your own user name where appropriate). For example:

 

sqlite_npm_install_path

 

Once in the Temp folder create the necessary directories to recreate the following path:

  • C:\Users\[YOUR USER NAME]\AppData\Local\Temp\plugman\git

 
And once again run the CLI command for installing the plugin. This time everything runs without error:

 

sqlite_npm_install_success