問題描述
在 Javascript 中打開外部 sqlite3 數據庫 (Open external sqlite3 database in Javascript)
I have an sqlite3 database called mydb.db. It is an external file. Is it possible to open up this DB in javascript?
I tried the following code but this results in mydb.db being created wherever chrome creates it's DB's, so it clearly isn't loading mine from file.
try {
if (!window.openDatabase) {
alert('Databases are not supported in this browser.');
} else {
var Name = 'mydb.db';
var version = '1.0'; //1.0
var displayName = 'TEST';
var maxSize = 100000; // bytes
database = openDatabase(Name, version, displayName, maxSize);
}
} catch(e) {
...
}
Thanks, J
‑‑‑‑‑
參考解法
方法 1:
No. (At least not by this means.)
Allowing arbitrary file/database access would be a security vulnerability. Imagine a file "C:\My Documents\My Bank Data\transactions.sqlite" ..
(Actually, I'd expect browsers to sandbox/abstract the db "name" away from the physical file as a sane, but implementation‑specific, strategy.)
(by Jarrod、user166390)