Access SQLite from WebView?

When I create an SQLite database in Corona, the file is stored in system.DocumentsDirectory. Once the database has been created, can I access it using javascript from a native WebView or WebPopup in iOS? I want to create an SQLite database in Corona and then use the database to populate a table in a native WebView.

According to the documentation: “Corona includes support for SQLite databases on all platforms. This is based on the built-in sqlite support on the iPhone.” I’m not sure about the relationship between Corona’s SQLite databases and the SQLite databases used by WebKit to provide HTML5 client-side storage.

Thanks!
Dave [import]uid: 164828 topic_id: 31062 reply_id: 331062[/import]

I have the same question

+1

The native.newWebView() is a self contained block on the page.  It’s really black boxed off from the rest of your app.  There is no visibility into our out of your Corona SDK app other than events that get triggered when links are tapped.  Being able to access things like HTML5 storage, bridging the JavaScript side with Corona would be a nice thing to have, we are not there yet with it.

What you can do, and this may be what you need, but it’s one way, is you can have Corona SDK write out an HTML file (with CSS and JS if you wish) to local files and then have the native.newWebView load that local content.   You could use Corona to read the database, write out the HTML and then show the HTML.  But other than programming links with get strings that can be parsed inside of the eventListener, there isn’t any other communications back that I know of.

Rob

We’ve used webview’s listeners to get around this.

I don’t have the code in front of me but the idea is that with js you change the url, usually by adding a querystring.

something like

document.location.href = document.location.href + '?foo=1'

and then on corona, the web listener should receive the url event

local function webListener(event) if event.url then if event.url:match('foo=1') then -- your sqlite code here end end end local webView = native.newWebView(...) webView:addEventListener('urlRequest', webListener)

Again, I’m not sure this code works, but this is the general idea that worked for us.

I have the same question

+1

The native.newWebView() is a self contained block on the page.  It’s really black boxed off from the rest of your app.  There is no visibility into our out of your Corona SDK app other than events that get triggered when links are tapped.  Being able to access things like HTML5 storage, bridging the JavaScript side with Corona would be a nice thing to have, we are not there yet with it.

What you can do, and this may be what you need, but it’s one way, is you can have Corona SDK write out an HTML file (with CSS and JS if you wish) to local files and then have the native.newWebView load that local content.   You could use Corona to read the database, write out the HTML and then show the HTML.  But other than programming links with get strings that can be parsed inside of the eventListener, there isn’t any other communications back that I know of.

Rob

We’ve used webview’s listeners to get around this.

I don’t have the code in front of me but the idea is that with js you change the url, usually by adding a querystring.

something like

document.location.href = document.location.href + '?foo=1'

and then on corona, the web listener should receive the url event

local function webListener(event) if event.url then if event.url:match('foo=1') then -- your sqlite code here end end end local webView = native.newWebView(...) webView:addEventListener('urlRequest', webListener)

Again, I’m not sure this code works, but this is the general idea that worked for us.