Sunday, February 24, 2008

Google Gears API: LocalServer Module

Following my last post about Google Gears Database Module , here comes the LocalServer module.

LocalServer module allows you to store the HTTP resources locally. The resources could be images, html pages, css, JS files etc. For more details refer my post on Gears Modules.

There are two options in LocalServer to store the files:

1. ManagedResourceStore: The resources are cached based on a manifest file. Set of URLs of the resources has to mentioned in a manifest file with a version number of the manifest file. When ever the resource is modified, you need to change the version number specified in the manifest file. Gears will take care of updating the local store (resources stored locally) with the new version. This option is more handy when the resources are almost static or occasionally modified, and thus avoiding downloading the resources every time you go offline/online.

Note: You might have an array of resources of which only few might have been modified. Gears will download only the modified resource.

2. ResourceStore: Alternately you can store the resources through API (method calls) at will, using methods like capture(), copy(), remove() etc.

Well, selecting the option is purely based on the requirement and the type of resource. If the resource is almost static, then you could use the ManagedResourceStore option, however there are resources associated with UI themes which changes based on user's current settings, that could be captured using ResourceStore.

Fore more details refer: http://code.google.com/apis/gears/api_localserver.html

In my next post I'll explain ResourceStore module with sample code.

Friday, February 22, 2008

Google Gears New version 0.2 is now available

Gears team have released 0.2 version of Google Gears. For more details refer:
http://gearsblog.blogspot.com/2008/02/gears-02-released.html
http://gears.google.com/

Saturday, February 2, 2008

Google Gears API: Database Module

My last post was on initializing the Google Gears API which is indeed the first step to use the Gears API. Next comes the use of different modules. In this post I'll illustrate the usage of Database Module.

All the Gears Module has to be instantiated by using Gears Factory's create method. For more details refer below url:

http://code.google.com/apis/gears/api_factory.html

Also have a look at getBuildInfo() method, to get the Gears build info.You will get some thing like this - 0. 2.14.0;official;opt;linux;firefox

As explained in my Modules of Google Gears post, the Database module uses SQLLite database.

Here are few methods that could be useful. Ensure that you have followed the initialization steps.


function dbtest()
{
var db = google.gears.factory.create('beta.database', '1.0');
if(db)
{
db.open('dbtest');
db.execute('create table if not exists testtab (id int,name text)');
db.execute('insert into testtab values (?,?)' ,[1,'srikanth']);
var rs = db.execute('select id,name from testtab where id=(?)',[1]);
while(rs.isValidRow())
{
alert(rs.field(0) + ':' + rs.field(1));
rs.next();
}
rs.close();
db.execute('update testtab set name = (?) where id=(?)',['srikanthramu',1]);
rs=db.execute('select name from testtab where id=(?)',[1]);
while(rs.isValidRow())
{
alert(rs.fieldName(0)+':'+rs.field(0));
rs.next();
}
rs.close();//It is important to close the resultset before database object
db.close();
}
}


Refer below url for database module methods:
http://code.google.com/apis/gears/api_database.html