Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

mozStorage documentation up

105 views
Skip to first unread message

Brett Wilson

unread,
May 4, 2006, 11:28:49 AM5/4/06
to
http://developer.mozilla.org/en/docs/Storage

Please let me know if there is a part that you can't figure out.

Brett

Dan Mosedale

unread,
May 4, 2006, 6:30:24 PM5/4/06
to Brett Wilson
Brett Wilson wrote:
> http://developer.mozilla.org/en/docs/Storage
>
> Please let me know if there is a part that you can't figure out.

Can you post this to m.d.platform also?

Thanks,
Dan

Casperion

unread,
May 8, 2006, 12:34:58 AM5/8/06
to
Is there a method attached to mozstorage to retreive jsut the column
names of a sqlite db?

Brett Wilson

unread,
May 8, 2006, 12:00:51 PM5/8/06
to
Casperion wrote:
> Is there a method attached to mozstorage to retreive jsut the column
> names of a sqlite db?

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

Casperion

unread,
May 8, 2006, 8:34:17 PM5/8/06
to
Yeah I know about the master table, but to put it bluntly, its a pain
to impliment :(

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?

Brett Wilson

unread,
May 8, 2006, 9:44:58 PM5/8/06
to
Casperion wrote:
> Yeah I know about the master table, but to put it bluntly, its a pain
> to impliment :(

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

Eric Desbiens

unread,
May 9, 2006, 11:59:29 AM5/9/06
to
Hi 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

Brett Wilson

unread,
May 9, 2006, 1:05:20 PM5/9/06
to
Eric Desbiens wrote:
> 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.

Hey, cool. I never noticed that! I'll figure out how to use it sometime
and document it.

Brett

Casperion

unread,
May 9, 2006, 8:59:04 PM5/9/06
to
you can do it by:

var nAr = new Array();
while(wrapper.step())
{
nAr.push(wrapper.row["columnname"]);
}

alert(nAr.join("\n");

Casperion

unread,
May 9, 2006, 9:01:06 PM5/9/06
to
ANother thing I wanted to ask, the mozstorage extension, it gives me
invalid file format with some sqlite db's I use?

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?

Brett Wilson

unread,
May 10, 2006, 11:46:07 AM5/10/06
to

I think you're probably using different versions of sqlite.

Brett

Casperion

unread,
May 10, 2006, 9:22:36 PM5/10/06
to
yep I just figured it out :(
Thanks for your help.

Sébastien Philippon

unread,
Nov 29, 2006, 7:38:19 AM11/29/06
to
Brett Wilson a écrit :

> http://developer.mozilla.org/en/docs/Storage
>
> Please let me know if there is a part that you can't figure out.
>
> 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.

Adam Kowalczyk

unread,
Nov 29, 2006, 9:09:58 AM11/29/06
to
Sébastien Philippon wrote:
> 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

Sébastien Philippon

unread,
Nov 29, 2006, 11:01:06 AM11/29/06
to
Adam Kowalczyk a écrit :

> openDatabase creates the file if it doesn't exist yet, so you don't have
> to create it first.

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?

Adam Kowalczyk

unread,
Nov 29, 2006, 12:15:55 PM11/29/06
to
Sébastien Philippon wrote:
> 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

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

0 new messages