WiseLibs / better-sqlite3

The fastest and simplest library for SQLite3 in Node.js.
MIT License
5.23k stars 390 forks source link

File is not a database. #1136

Closed mqliutie closed 3 months ago

mqliutie commented 5 months ago

Environment: macOS I have a database that is encrypted named 'test.data'. I want read this data

import Database from "better-sqlite3";
const db = new Database("/test.data");
// This key is correct
db.pragma(`key = 'cc8e3387ec19bc2f73b35ebdfa9d9b3f'`);
db.exec(
  "ATTACH DATABASE '/test.db' AS encrypted KEY '';"
);

db.pragma(key = 'cc8e3387ec19bc2f73b35ebdfa9d9b3f'); This line can be executed.

db.exec(
  "ATTACH DATABASE '/test.db' AS encrypted KEY '';"
);

This line will not be executed. it throw an error: SqliteError: file is not a database I don't know how to read this database. Thanks for your help

Prinzhorn commented 5 months ago

Are you sure you have both a test.data and a test.db file in the root of your file system?

Also SQLite does not have a key pragma (see list here https://www.sqlite.org/pragma.html). You probably want to load some sort of extension like SQLCipher. I think there are better-sqlite3 forks out there with it built-in.