sqliteError:文件不是数据库
按照此处找到的指示: sqlite错误:文件不是数据库我仔细检查了该路径不包含.db
扩展名:
export const getInfopiecesDbpath = () {
const isEnvDevelopment = process.env.NODE_ENV === 'development'
const infopiecesDbpath = isEnvDevelopment
? path.join(app.getAppPath(), "src", "data", "infopieces")
: path.join(app.getAppPath(), ".webpack", "data", "infopieces")
return infopiecesDbpath
}
const createInfopiecesTable: any = `
CREATE TABLE IF NOT EXISTS infopieces (
id INTEGER PRIMARY KEY AUTOINCREMENT,
infotext TEXT NOT NULL
);`
const createInfopiecesIndex = `PRAGMA INDEX_LIST(infopieces);`
export function initializeInfopiecesDB(db: Database) {
db.prepare(createInfopiecesTable).run()
db.prepare(createInfopiecesIndex).get()
}
const insertIP = `
INSERT INTO infopiecesDb (id, infotext)
VALUES (ip.id, ip.infotext)
`
export const insertInfopiece = (ip: IInfopiece) => {
infopiecesDb.prepare(insertIP).run(ip)
}
let infopiecesDbpath = getInfopiecesDbpath()
let infopiecesDb = require('better-sqlite3-multiple-ciphers')(infopiecesDbpath, { verbose: console.log })
infopiecesDb.pragma("key='secret-key'")
initializeInfopiecesDB(infopiecesDb)
在main
中:
let infopiecesDbpath = getInfopiecesDbpath()
let infopiecesDb = require('better-sqlite3-multiple-ciphers')(infopiecesDbpath, { verbose: console.log })
infopiecesDb.pragma("key='secret-key'")
initializeInfopiecesDB(infopiecesDb)
ipcMain.handle ("insert-infopiece-intodb", (IpcMainEvent, message) => {
console.log("ipcMain.hanlde-insert-infopiece-intodb-message: ", message.ip_01)
insertInfopiece(message.ip_01)
})
我收到此错误:
Error occurred in handler for 'insert-infopiece-intodb': SqliteError: file is not a database
at Database.prepare (/home/raphy/Playground/.webpack/main/index.js:652:21)
at insertInfopiece (/home/raphy/Playground/.webpack/main/index.js:1773:18)
at /home/raphy/Playground/.webpack/main/index.js:1943:32
at node:electron/js2c/browser_init:193:579
at EventEmitter.<anonymous> (node:electron/js2c/browser_init:161:10433)
at EventEmitter.emit (node:events:390:28) {
code: 'SQLITE_NOTADB'
}
其他信息:
"@types/better-sqlite3": "^7.5.0",
"better-sqlite3": "^7.5.3",
"better-sqlite3-multiple-ciphers": "^7.5.2",
"electron": "17"
node: v16.15.0
我缺少和/或做错了什么?
更新1)
如果我放入main
:
const infopiecesdb = require('bester-sqlite3-multiple-ciphers')(“ ../ data/data/infopieces.sqlite”,{timeout:5000}) infopiecesdb.exec(`如果不存在创建表格(如果不存在)( ID整数主钥匙自动启动, infotext文本而不是null, Doctype Varchar(255), datestamp dateTime而不是null, 货架生物dateTime而不是null, 源varchar(255)不为空, 血统文字, 可靠性整数, 人Varchar(255), 公司Varchar(255), 隐私整数不是零, 授权文本, 标签varchar(255) );')
infopiecesDb.pragma("key='secret-key'")
我得到sqliteError:无法打开数据库文件
错误
Following the indications found here: Sqlite Error: file is not a database I double-checked that the path does not contain .db
extension:
export const getInfopiecesDbpath = () {
const isEnvDevelopment = process.env.NODE_ENV === 'development'
const infopiecesDbpath = isEnvDevelopment
? path.join(app.getAppPath(), "src", "data", "infopieces")
: path.join(app.getAppPath(), ".webpack", "data", "infopieces")
return infopiecesDbpath
}
const createInfopiecesTable: any = `
CREATE TABLE IF NOT EXISTS infopieces (
id INTEGER PRIMARY KEY AUTOINCREMENT,
infotext TEXT NOT NULL
);`
const createInfopiecesIndex = `PRAGMA INDEX_LIST(infopieces);`
export function initializeInfopiecesDB(db: Database) {
db.prepare(createInfopiecesTable).run()
db.prepare(createInfopiecesIndex).get()
}
const insertIP = `
INSERT INTO infopiecesDb (id, infotext)
VALUES (ip.id, ip.infotext)
`
export const insertInfopiece = (ip: IInfopiece) => {
infopiecesDb.prepare(insertIP).run(ip)
}
let infopiecesDbpath = getInfopiecesDbpath()
let infopiecesDb = require('better-sqlite3-multiple-ciphers')(infopiecesDbpath, { verbose: console.log })
infopiecesDb.pragma("key='secret-key'")
initializeInfopiecesDB(infopiecesDb)
in main
:
let infopiecesDbpath = getInfopiecesDbpath()
let infopiecesDb = require('better-sqlite3-multiple-ciphers')(infopiecesDbpath, { verbose: console.log })
infopiecesDb.pragma("key='secret-key'")
initializeInfopiecesDB(infopiecesDb)
ipcMain.handle ("insert-infopiece-intodb", (IpcMainEvent, message) => {
console.log("ipcMain.hanlde-insert-infopiece-intodb-message: ", message.ip_01)
insertInfopiece(message.ip_01)
})
I get this error:
Error occurred in handler for 'insert-infopiece-intodb': SqliteError: file is not a database
at Database.prepare (/home/raphy/Playground/.webpack/main/index.js:652:21)
at insertInfopiece (/home/raphy/Playground/.webpack/main/index.js:1773:18)
at /home/raphy/Playground/.webpack/main/index.js:1943:32
at node:electron/js2c/browser_init:193:579
at EventEmitter.<anonymous> (node:electron/js2c/browser_init:161:10433)
at EventEmitter.emit (node:events:390:28) {
code: 'SQLITE_NOTADB'
}
Other info:
"@types/better-sqlite3": "^7.5.0",
"better-sqlite3": "^7.5.3",
"better-sqlite3-multiple-ciphers": "^7.5.2",
"electron": "17"
node: v16.15.0
What am I missing and / or doing wrongly?
Update 1)
If I put in main
:
const infopiecesDb = require('better-sqlite3-multiple-ciphers')("../data/infopieces.sqlite", {timeout: 5000})
infopiecesDb.exec(`CREATE TABLE IF NOT EXISTS infopieces (
id INTEGER PRIMARY KEY AUTOINCREMENT,
infotext TEXT NOT NULL,
doctype VARCHAR(255),
dateStamp DATETIME NOT NULL,
shelfLife DATETIME NOT NULL,
source VARCHAR(255) NOT NULL,
lineage TEXT,
reliability INTEGER,
person VARCHAR(255),
company VARCHAR(255),
privacy INTEGER NOT NULL,
authorization TEXT,
tag VARCHAR(255)
);')
infopiecesDb.pragma("key='secret-key'")
I get SqliteError: unable to open database file
error
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试以下操作:
Try this: