Re: [sqlite] Javascript API for SQLite?

2012-09-14 Thread Etienne
> I work on an application that uses an SQLite database as it's binary document 
> format (with a custom extension). Now we want to develop a Web App variation 
> of that application, that should be able to read and write those 
> documents/databases. Since the Web App is written in Javascript, I am now 
> looking for a Javascript implementation of the SQLite library.

> I have used the C SQLite library in the past, so I know about using SQLite 
> from C. However, I am just starting with Javascript and Web Apps and I am 
> quite a newbie on that side (Other people on the team are experienced, but I 
> have been asked to work on the SQLite integration).

> What would be my options?


JSDB (SQLite library embedded )  is worth a look:

"JSDB is JavaScript for databases, a scripting language for data-driven, 
network-centric programming on Windows, Mac, Linux, and SunOS. JSDB works with 
databases, XML, the web, and email. It is free and open-source. Use it as a 
JavaScript shell, to run CGI programs, or as a web server". (home page)


Regards,
Etienne
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Javascript API for SQLite?

2012-09-14 Thread Eleytherios Stamatogiannakis

There is a version of SQLite compiled in Javascript:

http://www.syntensity.com/static/sqlite_wip.html

But as others said, it is not possible to do block access on files from 
inside a Web browser's contained Javascript VM.


Nevertheless, theoretically you could load the full DB file in memory 
[*], do your operations on it in memory and then write it as a whole 
back to the disk, all on the client side.


lefteris.

[*] https://github.com/eligrey/FileSaver.js

On 14/09/12 16:05, Simon Slavin wrote:


On 13 Sep 2012, at 3:13pm, Jean-Denis Muys  wrote:


I work on an application that uses an SQLite database as it's binary document 
format (with a custom extension). Now we want to develop a Web App variation of 
that application, that should be able to read and write those 
documents/databases. Since the Web App is written in Javascript, I am now 
looking for a Javascript implementation of the SQLite library.


This can't be done entirely in JavaScript, since JavaScript running in a web 
browser has no way of getting at files on your hard disk.  This is to prevent 
the programmers of a web site spying on your computer's files.


I have used the C SQLite library in the past, so I know about using SQLite from 
C. However, I am just starting with Javascript and Web Apps and I am quite a 
newbie on that side (Other people on the team are experienced, but I have been 
asked to work on the SQLite integration).


There are ways you can allow JavaScript to access data inside a file on a web 
server.  The standard way is to write a shim in PHP or some similar language.  
The PHP code runs on the web server and uses PHP's SQLite3 library to access 
databases.  You ask it to execute a SQLite command, and it returns the results 
in JSON (or some other) format.  So for instance

https://myserver.com/databases/doSQLCommand.php?file=money.sqlite&command=SELECT
 * FROM transactions WHERE id=123

might return a page of application/json type containing

{id: 123, trandate: "20030205", amount: 274.53}

Of course in real life you're more likely to pass the parameters using POST 
than GET.

Your JavaScript code asks the shim for the data using an XMLHttpRequest and 
uses JSON.parse() to turn the results into an array or an object.

There are, of course, many security concerns with such a setup, so most shim 
programs check to see that they're being called only from their own server, by 
a program they recognise, running on a computer they recognise.  I sometimes 
use a setup like this, though my shim returns the requested results as only a 
small part of the stuff it returns, the rest being things like error messages 
and last-insert-id and stuff like that.

Simon.
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users



___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Javascript API for SQLite?

2012-09-14 Thread Clemens Ladisch
Jean-Denis Muys wrote:
> I am now looking for a Javascript implementation of the SQLite library.

 says:
| sql.js is a port of SQLite to JavaScript, by compiling the SQLite
| C code with Emscripten.

It's completely in-memory, but:

| Database objects ... have the following methods:
| * .exportData() serializes the data to a typed array of 8-bit values,
|   which you can save using any method you like (localStorage,
|   indexedDB, send to a remote server, etc.), and later re-use by
|   calling SQL.open with that data.

It's one of the engines used on sqlfiddle.com, and seems to work just
fine.


Regards,
Clemens
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Javascript API for SQLite?

2012-09-14 Thread Simon Slavin

On 13 Sep 2012, at 3:13pm, Jean-Denis Muys  wrote:

> I work on an application that uses an SQLite database as it's binary document 
> format (with a custom extension). Now we want to develop a Web App variation 
> of that application, that should be able to read and write those 
> documents/databases. Since the Web App is written in Javascript, I am now 
> looking for a Javascript implementation of the SQLite library.

This can't be done entirely in JavaScript, since JavaScript running in a web 
browser has no way of getting at files on your hard disk.  This is to prevent 
the programmers of a web site spying on your computer's files.

> I have used the C SQLite library in the past, so I know about using SQLite 
> from C. However, I am just starting with Javascript and Web Apps and I am 
> quite a newbie on that side (Other people on the team are experienced, but I 
> have been asked to work on the SQLite integration).

There are ways you can allow JavaScript to access data inside a file on a web 
server.  The standard way is to write a shim in PHP or some similar language.  
The PHP code runs on the web server and uses PHP's SQLite3 library to access 
databases.  You ask it to execute a SQLite command, and it returns the results 
in JSON (or some other) format.  So for instance

https://myserver.com/databases/doSQLCommand.php?file=money.sqlite&command=SELECT
 * FROM transactions WHERE id=123

might return a page of application/json type containing

{id: 123, trandate: "20030205", amount: 274.53}

Of course in real life you're more likely to pass the parameters using POST 
than GET.

Your JavaScript code asks the shim for the data using an XMLHttpRequest and 
uses JSON.parse() to turn the results into an array or an object.

There are, of course, many security concerns with such a setup, so most shim 
programs check to see that they're being called only from their own server, by 
a program they recognise, running on a computer they recognise.  I sometimes 
use a setup like this, though my shim returns the requested results as only a 
small part of the stuff it returns, the rest being things like error messages 
and last-insert-id and stuff like that.

Simon.
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


[sqlite] Javascript API for SQLite?

2012-09-14 Thread Jean-Denis Muys
Hello,

I work on an application that uses an SQLite database as it's binary document 
format (with a custom extension). Now we want to develop a Web App variation of 
that application, that should be able to read and write those 
documents/databases. Since the Web App is written in Javascript, I am now 
looking for a Javascript implementation of the SQLite library.

I have used the C SQLite library in the past, so I know about using SQLite from 
C. However, I am just starting with Javascript and Web Apps and I am quite a 
newbie on that side (Other people on the team are experienced, but I have been 
asked to work on the SQLite integration).

What would be my options?

Thanks for any help.

Jean-Denis

___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users