Adobe Flash player is required for this content

Main > Free Downloads > SQLite Object for Zinc News Flash! A welcome message for Games Magazine readers

SQLite for Zinc

What is it?

Multidmedia Zinc is a good game prototyping and development tool. Unfortunately, its database support leans towards the server end of the spectrum, and it has no support for a small "install free" database like SQLite. The closest approximation is MS Access, which still has some runtime and licensing (not to mention platform) issues. SQLite is very small (zips down to 100k), is license-free, and has no setup requirements beyond copying a single runtime DLL.

Unfortunately, the external function call interface to the SQLite runtime is a bit too hairy for Zinc's simple executable-code interface, so there was a need for a simpler Zinc-compatible interface that could communicate both with Flash code and the SQLite DLL.

That, coupled with an ActionScript object wrapper for Flash, makes up the SQLite for Zinc system.

SQLite Class Interface

Note that the SQLite is intended to work as a "drop in" replacement for Zinc's existing database objects, so the class interface was dictated by that model.

 

public function SQLite()

Description:
Constructs an SQLite object. No parameters.

Example:
myDB = new SQLite();

 

 

public function connect(filename:String):Boolean

Description:
Opens a database file.

Parameters:
filename - Name or path of the database file to open. If no path is specified, database will be opened in the current directory. If an existing database file is opened, it will be closed before this file opens. If the database file does not exist, it will be created.

Returns:
true if the database was opened successfully, false otherwise.

Example:
var boolVal:Boolean = myDB.connect("mydb.db");

Notes:
The Mac version expects the file path to be in Unix format, so convert it first.

 

 

public function close():Void

Description:
Closes an open database. If there is no open database, this call does nothing. It is safe to call if no database is open.

Example:
myDB.close();

 

 

public function runQuery(query:String):Boolean

Description:
Runs a query on an open database.

Parameters:
query - SQL query string. If no database is open, this call does nothing.

Returns:
true if the a query was successfully run, false otherwise.

Example:
boolVal:Boolean = myDB.runQuery("select * from myTable");

 

 

public function errorDetails():String

Description:
Returns a string containing the results of the latest database operation, specifically connect(), close(), or runQuery().

Parameters:
None.

Returns:
A textual error message from the most recent database operation. Returns "not open" or "no error" if there is not a database open or the latest operation was done without error, respectively.

Example:
if (!myDB.connect("database.db") trace(myDB.errorDetails());

 

 

public function getData():Array

Description:
Returns a 2-dimensional ActionScript array of the returned query data.

Parameters:
None.

Returns:
The contents of the returned query as a 2-dimensional ActionScript array. Returns an empty array if rowIndex/columnIndex are out of bounds, there is no query data, or the database is not open.

Example:
myArray = myDB.getData();

 

 

public function getField(rowIndex:Number, columnIndex:Number):String

Description:
Returns a field from the last runQuery() command.

Parameters:
rowIndex - The row from which to retrieve a field

columnIndex - The column from which to retrieve a field

Returns:
The contents of the returned query item as a string. Returns nothing if rowIndex/columnIndex are out of bounds, there is no query data, or the database is not open.

Example:
stringVal = myDB.getField(1, 2);

 

 

public function success():Boolean

Description:
Determines if a database is currently open.

Parameters:
None.

Returns:
true if a database is currently open, false otherwise.

Example:
trace("The database is" + myDB.success() ? "open" : "not open");

 

 

public function getRecordCount():Number

Description:
Returns the number of records from the latest runQuery() command.

Parameters:
None.

Returns:
number of records returned by most recent runQuery() command. Returns zero if no records or returned or database is not open.

Example:
val = myDB.getRecordCount();

 

Developer installation

Put the SQLite.as file into a location where it's visible to the Flash classpath, like your FLA file directory. That should be all that's necessary. Note that the Mac and Windows SQLite.as files are different, so you should probably put them in their own directories and change your classpath for each build.

Client installation

Windows: All that should be necessary for client installation is to include the sqlitezinc.dll and sqlite3.dll files into the same directory as your Zinc-compiled EXE file.

Mac: Pack the sqlite3 command-line application into your "Library" list in the MDM user interface.

Download

Download Windows version here.
Download Mac version here.

The Zip file contents. . .

sample.db A little sample database used by the sqlitetest app.
SQLite.as An ActionScript 2.0 file containing the SQLite object. Drop this file into your FLA's directory.
sqlitetest.fla Source for the test application.
SQLitetest.zinc A Zinc project file for the test application.
sqlitezinc.DLL The Zinc-SQLite "glue" DLL.
sqlite3 (Mac only) The sqlite3 engine, compiled as a universal binary
sqlitezinc-logged.DLL (Windows only) A clone of sqlitezinc.dll that logs all transactions to SQLiteZincLog.txt.
Just rename this to sqlitezinc.dll to use.

If you're in Windows, you'll also need to download SQLite3.dll. This is available on the SQLite Download Page. The one labeled "sqlitedll-3_X_X.zip" is the one you want. Both the SQLite3.dll file and the sqlitezinc.dll file will need to be present in your executable's directory. You should be able to pack both DLL's into your Zinc executable and extract them at runtime, as long as you extract them before instantiating your SQLite object

If you're using a Mac, the binary is not as easily available on the SQLite page, so I compiled it as a universal binary and included it in the distribution.

License and Support

This is free software. Free as in "free speech". Free as in "free beer" . Free as in "free from tech-support".

Copyright © 1995-2008 The Code Zone All Rights Reserved
Problem with the site? Email support here.

Site Map
Privacy Policy