Welcome to the Official BlackBerry® Support Community Forums. This is your resource to discuss support topics with your peers, and learn from each other. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Web and WebWorks Development

Reply
Developer
jmace
Posts: 482
Registered: 10-24-2008
My Carrier: AT&T

Gears create table stopping widget

[ Edited ]

I've looked at the developer blog post and the gears code examples, but for some reason my widget can't get past my create table statements below. I've even tried simplifying it, but still no luck. My code never makes it past the first create table below. Any ideas what I am missing? (I have the gears_init.js in my project)

 

 

// Open the database using Google Gears API and create tables if needed 
function openDatabase()
{
alert("inside of openDatabase");
var db = google.gears.factory.create('beta.database');
alert("after create db");
db.open('Emit-database');
alert("after open db");
db.execute('create table if not exists Station (Name, StationID)');
//db.execute('create table if not exists Station (Name, StationID, SiteID, CanPoll, IsSatellite, Lat, Lon, PropID, API)');
alert("after create table Station");
db.execute('CREATE TABLE IF NOT EXISTS StationData (ID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, StationID , DataString)').close();
_db = db;
}

 

_________________________________________
www.jasonmace.com/blackberry
Please use plain text.
BlackBerry Development Advisor
astanley
Posts: 712
Registered: 07-02-2009
My Carrier: Bell

Re: Gears create table stopping widget

Hello,

 

This may be expected behaviour, depending on which BlackBerry Smartphone model you are using.

 

There is currently a design limitation with the underlying SQLite API used to implement the Gears DB.  The file system type of the internal memory on a BlackBerry Smartphone is not compatible with SQLite.  As a result, this API requires that the device has either eMMC or an SDCard.  This design limitation affects Java applications as well.

 

More details about this behaviour can be found here:

 

http://www.blackberry.com/developers/docs/widgetapi/google.gears.database.Database.html

 

Sincerely,

Adam

 

Follow me on Twitter: @n_adam_stanley
-------------------------------------------------------------------------------------------------------------------------
BlackBerry WebWorks Developers: Join us for the BlackBerry 10 Jam World Tour May-Aug 2012.

Don't forget to check the BlackBerry Development Knowledge Base for helpful learning resources.
Please use plain text.
Developer
jmace
Posts: 482
Registered: 10-24-2008
My Carrier: AT&T

Re: Gears create table stopping widget

[ Edited ]

Hello Adam,

 

I am trying to simulate this code on the 9550 simulator packaged with the Widget Beta 3.

 

 

_________________________________________
www.jasonmace.com/blackberry
Please use plain text.
BlackBerry Development Advisor
tneil
Posts: 3,555
Registered: 10-16-2008
My Carrier: Rogers

Re: Gears create table stopping widget

Hi jmace,

 

You will have to turn on SD card emulation in the Simulator. 

 

This can be done via the "Simulate -> Change SD Card..." menu item in the simulator.  You can choose a directory on your file system you would like the simulator to use as the root of your SD card.

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
Please use plain text.
Developer
mikeo007
Posts: 22
Registered: 11-17-2009

Re: Gears create table stopping widget

So does this mean that a DB used/created by gears must be stored on the SD card?

Please use plain text.
Developer
jmace
Posts: 482
Registered: 10-24-2008
My Carrier: AT&T

Re: Gears create table stopping widget

I've added a piece of code to check if gears is even registering. I am hitting the alert for "Gears not initialized".

 

In my index.html, I have a reference to gears_init.js. Am I missing something else? I've also added an SD card file to the simulator as suggested.

 

 

// Open the database using Google Gears API and create tables if needed function openDatabase(){
alert("inside of openDatabase"); 
var db = google.gears.factory.create('beta.database'); 

if (!window.google || google.gears)
{
   alert("Gears not initialized");
}

alert("after create db"); 
db.open('Emit-database'); 
alert("after open db"); 
db.execute('create table if not exists Station (Name, StationID)'); 
//db.execute('create table if not exists Station (Name, StationID, SiteID, CanPoll, IsSatellite, Lat, Lon, PropID, API)'); 
alert("after create table Station"); 
db.execute('CREATE TABLE IF NOT EXISTS StationData (ID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, StationID , DataString)').close(); 
_db = db; 
}

 

_________________________________________
www.jasonmace.com/blackberry
Please use plain text.
BlackBerry Development Advisor
tneil
Posts: 3,555
Registered: 10-16-2008
My Carrier: Rogers

Re: Gears create table stopping widget

 


mikeo007 wrote:

So does this mean that a DB used/created by gears must be stored on the SD card?


 

A BlackBerry smartphone must either have an SD card present or have a built in eMMC card for the Gears Database

 

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
Please use plain text.
Developer
Posts: 107
Registered: 09-25-2008

Re: Gears create table stopping widget

> I've added a piece of code to check if gears is even registering. I am hitting the alert for "Gears not initialized".

 

That's because !a || b evaluates as (!a) || b. When b is "google.gears", that expression will return true if gears is installed.

Please use plain text.
Developer
jmace
Posts: 482
Registered: 10-24-2008
My Carrier: AT&T

Re: Gears create table stopping widget

yes Stak,

I noticed that and had already changed that if statement. proceeding with 

 

if (!window.google)
    alert("Gears uninitialized");

 

Regardless, the code still fails on the db.execute create table statement and throws an 'undefined' error when this is all placed in a try catch.

_________________________________________
www.jasonmace.com/blackberry
Please use plain text.
BlackBerry Development Advisor
tneil
Posts: 3,555
Registered: 10-16-2008
My Carrier: Rogers

Re: Gears create table stopping widget

You had mentioned that you had the gears_init.js in your project, but is it also loaded into the page via a <script> tag where you are writing your gears code?

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
Please use plain text.