DataAccess Utility Class
Posted by brandonthedeveloper at June 17th, 2007
I spent this weekend writing a simple ‘Data Access Layer’ utility class to be used with AIR applications and sqlite. If you are not familiar with using a ‘DAL’, data access layers act as transparent layer between your application and the database to handle the data processing. This keeps the view code clean and the sql commands as reusable methods.
You can download everything here. The zip contains the project and the AIR file.
I think I’ve commented the code pretty well. If you have any questions or comments let me know.
This work is licensed under the Creative Commons Attribution 3.0 License



Nice bro, now we need an AIRlib set up on google code, and stick this in it. As Im sure there are alot more usefull classes that are going to popup
Campbell
Pretty nice — there’s room for more functionality of course, but it’s a nice way to simplify things. The part that caught my eye the most was how it uses data binding to avoid the need for any events (and associated event handling code) — very nice.
If you don’t mind, here are a couple of comments/suggestions:
In the example it just concatenates values into the SQL rather than using parameters. The DataAccess class doesn’t really have a way to pass in parameters, but you could probably make that work by adding a parameter in the
DataAccessSelect()/DataAccessInsert()/etc. methods to pass in an associative array of SQL parameters.in the
executeSQL()method, it wraps several lines in atry..catchblock and catches SQLError. However, none of the code in thetryblock throws a SQLError, so yourcatchblock will never be used. Three of the lines of code can throw an IllegalOperationError, so maybe that would be a better choice for thecatchblock parameter. (At this point, SQLError is only used when an error occurs during an async operation — it’s only available via a SQLErrorEvent or in a status/fault handler of a Responder passed toSQLStatement.execute()A big downside is that the developer still needs to pass SQL to the DataAccess class. Obviously there’s not much way around that in a simple class; perhaps a complex version could be created where a developer just passes a table name in the constructor and the class does the work of creating the relevent SQL code. (Obviously then the INSERT and UPDATE methods would need pairs of names and values passed in, and the DELETE would need some WHERE clause value passed in or something — it wouldn’t be something trivial — I guess I’m just sort of thinking out loud here.)
- PaulActionScript Developer/WriterAdobe Systems, Inc.
Paul Robertson
Campbell – yeah I think there will be a lot of cool classes to make up a great AIR developer library.
Paul – I was excited about sqlite being embeded in AIR apps but your post on it is what really got me motivated to write the class (actually, your post and knew I was going to need the class for an AIR project at work).
Yeah the class is simple but after easily replacing a few classes in my current project with just this one DAL class, I think I’m going to take some time to refine it.
Its a nice utility for the community and maybe it will give me something to speak about at a user group meeting. ;)
brandonthedeveloper
thank
this is to good n fine for AIR users
Rajesh