Please let me know if there is a part that you can't figure out.
Brett
Can you post this to m.d.platform also?
Thanks,
Dan
You can get this information from the built-in sqlite_master table:
http://www.sqlite.org/faq.html#q9
You might have to parse the results, though.
Brett
It would be seriously cool if you were able to pull the column names by
calling a method or function attached to the mozstorage API =D
That brings me to another query, can you access a remote (ie. from
another website/server) sqlite db file using mozstorage?
I understand it would be useful. My excuse is that you should know your
own database schema. My real reason is that I don't want to write it
because it's a pain to implement :)
> That brings me to another query, can you access a remote (ie. from
> another website/server) sqlite db file using mozstorage?
No. I guess we could get this to work in read-only mode, but basically
it would involve downloading the DB to the local drive and opening it.
If you want that, you can do it yourself.
Brett
The docs are welcome and reallly well done. I have been using
mozStorage for a month now and I learn a few usefull things from your doc.
The only thing missing from the doc is a part on
mozIStorageStatementWrapper which in my opinion make code more readable
since you can access colums by their name and not their index.
Keep up the good work!
Eric
Hey, cool. I never noticed that! I'll figure out how to use it sometime
and document it.
Brett
var nAr = new Array();
while(wrapper.step())
{
nAr.push(wrapper.row["columnname"]);
}
alert(nAr.join("\n");
Is there a particular method to create a db that the mozstorage
extension will accept (as I dont want to have to make copies of the
calender one to have to make it work...)
Any ideas?
I think you're probably using different versions of sqlite.
Brett
There is something unclear to me. Does the openDatabase method create
the database file if it does not exist or do I have to create it
manually beforehand? In that case, is it enough to just create an empty
file using the nsIFile.create method and then open a database connection
on that file to execute some CREATE TABLE statements, or do I have to
create the database file using the sqllite command line client? Thanks
in advance.
openDatabase creates the file if it doesn't exist yet, so you don't have
to create it first.
Here's an example that creates an new database in the profile directory
or opens an existing one:
var file = Cc['@mozilla.org/file/directory_service;1']
.getService(Ci.nsIProperties)
.get('ProfD', Ci.nsIFile);
file.append('database.sqlite');
var storageService = Cc['@mozilla.org/storage/service;1']
.getService(Ci.mozIStorageService);
var dBConnection = storageService.openDatabase(file);
- Adam
Thanks, I managed to find that out by myself (actually I was too lazy to
test it, but I did it anyway :p).
Still I have another question (and for this one I don't see how to test
it): is it possible to execute statements from a .sql script file? This
could be useful to create the tables and to insert initial data. Well I
believe it is possible, my problem is more about accessing to the
content of such a file. Suppose my .sql scripts are stored under the
"sqlfiles" folder which is placed at the root of the directory structure
of my extension. Can I access my files via a chrome:// url, or is there
another way to achieve this?
Why do you want a separate file for these statements instead of
hardcoding them in JS?
> believe it is possible, my problem is more about accessing to the
> content of such a file. Suppose my .sql scripts are stored under the
> "sqlfiles" folder which is placed at the root of the directory structure
> of my extension. Can I access my files via a chrome:// url, or is there
> another way to achieve this?
Yes. You should put them in \chrome\content, though.
We're going off-topic, so I guess it'd be better to continue this on
m.d.extensions.
- Adam