Tuesday, July 1, 2008

Tip: Use SQLite3 in your gadget

While saving into the options is very easy you sometimes work with more data. This often requires a real database which supports features like sorting, grouping, randomized access or limiting the request to a number of datasets. Here is a tip on how to use sqlite3 in your gadget.

The first thing you need is the the sqlite3 ActiveX object from http://www.assembla.com/wiki/show/litex. Just download the zip archive in the files section of the webpage. The DLL is located in the \litex\bin\ folder of the zip archive. Copy the sqlite3.dll into your gadgets root folder.

Then open your gadget.gmanifest in your favorite editor. After the <about> tag add the following install tag for the sqlite3 object:
<install>
<object name="sqlite3"
clsid="3E22694D-7B92-42A1-89A7-668E2F7AA107"
src="sqlite3.dll"/>
</install>
Now you can create a new instance of the sqlite3 object in your code and work with sqlite3 - either with a database on the disk or in memory:
var sqlite = new sqlite3();
debug.trace("SQLite3 version: "+
sqlite.version( true ) );
sqlite.open( ":memory:" );
sqlite.execute("CREATE TABLE Test(a);");
sqlite.execute("INSERT INTO test VALUES (4);");
sqlite.close();
Check the PDF on the litex webpage for all supported functions. You can now use your sqlite3 database from your gadget. Unfortunately this is currently only supported on Windows.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home