Where does sqlite store the database file on win7 offline? - javascript

I'm following this, using js in html to call 'openDatabase("AddressBook",....'. It works, it stores values and calls them them back correctly when I reopen the page but I can't find where the AddressBook DB file is. I've searched my pc, C:\ and appdata etc but I can't find it. I've tried downloading the sqlite3 tool and setting a DB separately and transporting it to the folder but it doesn't seem to recognize it. If I change the name of the DB called it starts a new one and if I then put the previous DB name it shows the stored DB from before. I'd like to know I can locate it and transport it before I learn anymore.
Can anyone advise where it might be?
Is there a way to force it into the same folder as the js files?

That guide seems seems to misunderstand the APIs that it is using. It keeps saying that its using SQLite. It's not. It looks like it is using the deprecated WebSQL spec. The file isn't in your filesystem, it's part of the browser's internal storage and there is no guarantee of how the browser is actually storing it so you can't directly access it from outside the browser.
I'm making the assumption that it is using WebSQL because it mentions using openDatabase and executeSql. WebSQL has been deprecated and is no longer maintained in most browsers. You can get a detailed reasoning from this answer Why is Web SQL database deprecated?. That guide you're following is also 9 years old and doesn't even discuss WebSQL's deprecation.

Related

Accessing user disk storage in chrome extension

I am building a chrome extension, I want to read and write in the user's disk storage. I want to make folders in users' documents, store screenshots, and delete and read. Is it possible?
I have searched, but could not find a way to do this, I want to know if it is possible, if it is possible, could you tell me, how to do that, or refer to some docs?
Extensions cannot access the file system directly.
(except in very limited ways)
Native Messaging allows extensions to access the file system, by passing messages to and receiving messages from a native application, such as a Python script.
The native application (which you have to program yourself) then accesses the file system directly.
Because your question isn't specific, I can only refer you to the official documentation:
https://developer.chrome.com/docs/apps/nativeMessaging/

PhoneGap - Read pre-packaged sqlite database

I've been struggling to get this working for too long. I just started to get into PhoneGap/Cordova. I got the demo app running, installed all official plugins, and added this SQLite plugin to begin work with: https://github.com/brodysoft/Cordova-SQLitePlugin
However, I want the plugin to read a pre-packaged database. Simply put, create an app that works offline and does not need to download an SQLite database when it is run for the first time.
I have been developing for Android for quite some time, and the solution was to deploy a read-only database file in the assets folder, and on first run copy the database file into a different folder, where I can read/write as I please.
So I did a little research and realized that it SHOULD be the same with PhoneGap. Place a binary SQLite database somewhere, so that when built, it will be packaged with the app. And then simply load it with the SQLite plugin I linked here.
Finally, the question! What are the exact steps I have to take to be able to read a file that was packaged with the app?
Where should I put my binary file to ensure that it gets packaged into the app?
How exactly should I initialize the File API? Should I ask for persistent storage using window.requestFileSystem? Or should I get some (not sure which) directory (cordova.file.applicationDirectory) as a DirectoryEntry using window.resolveLocalFileSystemURL? If so, what are the EXACT parameters I should use? I am mostly referring to this: https://github.com/apache/cordova-plugin-file/blob/master/doc/index.md
How do I read the packaged file? Using window.resolveLocalFileSystemURL with the right folder? What should then the parameters be?
File copying should work OK if I get to this point. Just copy from the read-only cordova.file.applicationDirectory into cordova.file.dataDirectory, which is read/write. Right?
I know the questions might be pretty basic, but my countless attempts were unsuccessful and I did not find a tutorial that explains this in-depth (believe me, I googled). Also, the documentation seems insufficient.
Just working with a WebSQL database and load data the DB using a s***load of INSERTs is not a viable option, the database has thousands of records.
Thanks for the help in advance, you will save me a headache or two.
Currently Cordova's standard SQLite Plugin supports Pre-populated Databases, which will copy your database file from www and put it into the right directory. It also supports Android as well as iOS, so you don't need to have different logic for different platforms.
When you open the database, you can specify that it is pre-populated using createFromLocation: 1 like this:
var db = window.sqlitePlugin.openDatabase({
name: "my.db",
createFromLocation: 1
});
For iOS, it will first check www and if the file exists, it will copy it to Documents. Keep in mind that it will be backed up by iCloud. If you want to exclude it from iCloud, then add location: 2 on openDatabase as well, which will put your databases in Library/LocalDatabase.
UPDATE (2016)
The original Cordova-sqlite-storage project does not support pre-populated db anymore.
However, this feature just moved to another project from the same creator. Now, use Cordova-sqlite-ext for this purpose.

Writing and downloading files clientside crossbrowser

I have a program where the user does some actions (i.e. clicking on several buttons). I want to record their clicks and the buttons that they click to allow the user to then download a text file with a record of their clicks when they click a separate "download" button. I looked at the File-system APIs for HTML 5, but they seemed to not have cross-browser support. I would ideally like to have this entire file generation and download scheme be entirely client-side, but I am open to server-side ideas as well.
TL;DR: Essentially I'm looking for an equivalent to Java's FileWriter, FileReader, ObjectOutputStream, and ObjectInputStream within Vanilla JS or jQuery (would like to stay away from php, but I'll use it as a last option).
Also, why don't all browsers support the filesystem api? (I'm guessing that it would make MSWord and Pages go out of business with all the open source clientside text editors that could come out.)
Unfortunately the HTML5-File-system is no longer a part of the spec, long story short FF refused to implement because they claimed everything you could do in the File-System API was doable in the HTML5 Indexeddb (which was mostly true). Please see this blog post for more on why FF didn't implement. I do not know IE's story. (I may have exagerated why FireFox didn't implement, I'm still bummed because you cannot actually do everything in indexeddb that you can do in the noew "Chrome File-system API")
Typically if two of those three browsers implement a spec, it stays in the spec. Otherwise that spec gets orphaned. However, I'm fairly certain a large reason the file-system api didn't take off is because of the IndexedDB API (caniuse IndexedDB) really took off when both specs were introduced. If you want cross browser support, check this api out.
That all said if you are still set on the file-system api some developers wrote a nice wrapper around the IndexedDB, the File-system api wouldn't actually supply you with a stream anyway. You would have to keep appending events to a given file given a fileWriter object. you'd then have to read the entire file and send to the server via an ajax request and then downloaded from the server once successfully uploaded.
The better route would be to use the IndexedDB apiwhich as stated on developer.mozilla
Open a database.
Create an object store in upgrading database.
Start a transaction and make a request to do some database operation, like adding or retrieving data.
Wait for the operation to complete by listening to the right kind of DOM event.
Do something
with the results (which can be found on the request object).
Here are a couple tutorials on the IndexedDB.
https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API/Using_IndexedDB
http://www.html5rocks.com/en/tutorials/indexeddb/todo/
As for giving the user that file, as mentioned briefly before you would have to upload the file to the server and download upon the "download" request. Unfortunately you have to trick the user into giving them the data already on their machine. Anyway, hope this all helps.

Saving data to a local file using only JavaScript

The set-up in question:
I have a stand alone, offline, kiosk mode instance of Chrome running on a Windows machine. I have full access to the system and any admin rights. I can start Chrome with any flags set or unset.
The task:
I have been asked to create a log file which tracks user activity within the offline app I am coding. It's a simple form of analytics which will append each event to the end of the file separated with a comma. The file will then be sent to a server once a day via a scheduled task. (None of this is my idea so please don't troll me)
Ruled out:
Any server side code - I have lobbied for Node, PHP etc but as this will be distributed to many different installations so we cannot guarantee this will be installed.
Flash/ActiveX/Java - ideally would like to avoid this (even though these will be installed by default)
Possible solutions:
File API - I have looked at this but AFAIK if opens dialogue boxes to save the data to each file and this needs to happen in the background.
Security - I have read in other SO Questions that this can be achieved if the security settings are reduced but no-one goes on to explain which ones. Is there a simple flag which allows it?
How to enable local file system read write access from Google chrome? - similar question!
Ideal result: (something akin to PHP)
$file = 'log.txt';
$current = file_get_contents($file);
$current .= ",clicked:link";
file_put_contents($file, $current);
Possible ideal side result: proving this isn't possible and forcing PHP/Node/Java to be used ;)
In reply to those suggesting local storage : I'm not storing unique key/value pairs and that is very much like setting a cookie. Similarily there are file size limits.
To those suggesting web SQL such as SQLite in chrome - there are file size limits if it's not a chrome extension. The only way I see that working is if I were to find the location of the file in the windows directory (C:\Users\%USERNAME%\AppData\Local\Google\Chrome\User Data\Default\databases) and upload that from the schedules task. Perfectly feasible but it is not a desirable answer.
You could use HTML5?
http://diveintohtml5.info/storage.html
var foo = localStorage.getItem("bar");
// ...
localStorage.setItem("bar", foo);
You can use the Chrome Apps File API, you will need to grant access to the file via a user action once, but after that you can get access the file again by using restoreEntry
You can use localStorage to save offline data. It's impossible to access other files using Javascript since it's a violation of the sandbox.
From http://en.wikipedia.org/wiki/JavaScript#Security:
JavaScript and the DOM provide the potential for malicious authors to deliver scripts to run on a client computer via the web. Browser authors contain this risk using two restrictions. First, scripts run in a sandbox in which they can only perform web-related actions, not general-purpose programming tasks like creating files.
You may want to look into Local Storage which is part of the HTML5 spec.
This will only be supported in modern browsers though.
If you need to use older browsers then may still be able to achieve what you're after using dojox.storage
Use HTML5 features like Web Storage or Web SQL database to store your logs.
Whenever needed read logs from the client side storage and send it back to the server & delete the client storage.
Refer http://www.html5rocks.com/en/features/storage.

html or javascript, how to find out where is the program files folder?

i have some HTML files that i want to run in user local machine ( offline).
is there any method to find out in which hard drive the program files folder is located?
Note: do you know any methods that don't raise security problems.
I think this question is very confused. Not every computer has a "Program Files" directory or even the concept of drives because not every computer is Windows.
On top of that, HTML5 Offline Mode just requires a manifest file to be hosted by your web server. The browser will put the cached data in the right place for it.
If you're talking about some internal deployment of a non-hosted page and want to spawn IE directly, I think it's a bad idea, but use the %ProgramFiles% environment variable.
There is a file system api in HTML5 - have a look at the draft documentation
If you're calling requestFileSystem() for the first time, new storage is created for your app. It's important to remember that this file system is sandboxed, meaning one web app cannot access another app's files. This also means you cannot read/write files to an arbitrary folder on the user's hard drive (for example My Pictures, My Documents, etc.).
So if you're thinking about a web page being able to poke around a users program folder, then the answer is no, you'll need some kind of an app engine - e.g. Adobe Air or the Windows8 Metro apps.
Basically there is no crossbrowser way of doing this. If it is ok for you to have an Internet Explorer only solution try to look at the ActiveX component called FileSystemObject and its GetSpecialFolder method - http://msdn.microsoft.com/en-us/library/aa265315%28v=vs.60%29.aspx
I'm not on Windows but it seems you can try something like this:
var WshShell = new ActiveXObject('WScript.Shell');
Response.write("ProgramFiles envioronment variable is set to:\n\n" +
WshShell.ExpandEnvironmentStrings('%ProgramFiles%'));
Program Files are found on Environment Variables, so that's what you're looking for.
Regards,
PS: this will lead you to some security warnings. Actually, this is not safe.

Categories

Resources