Single Tick issues with AIR

This post describes a way to get around the issue of inserting and updated a sqlLite db with single ticks…

There probably is more than likely a better way to do this, I’m told that when you use “Prepared” sql statements in air, it may fix the issue, but I’m on my first Air project, i’ve been doing flex for like 2 and a half years with CF on the backend, and so i know all the tricks in cf to fix the issues, but in AIR we just wrote a function to do it…


I have an object called “TeamVO” it looks like this

  • TeamVO
    • TeamName:String
    • TeamID:Number

teamVO:TeamVO = new TeamVO; teamVO.teamName = "Jakes's Team";

When I insert that into the db, I always get errors back… so we (by we I mean Jake Churchill ) came up with a function to handle that for use… this will only work if your using objects like we are, but more than likely you are… if not, you can still use the replace statment in it.

/** * this escapes single ticks so they can be stored in the DB correctly **/ public function escapeStrings( value:Object ):Object { // get object details var objectDescription:XML = flash.utils.describeType(value); // get object properties as XMLList var objectProperties:XMLList = new XMLList(objectDescription.accessor); // create a new object to store modified data in var newVal:Object = new Object();

// loop over all properties

for( var x:uint = 0; x < objectProperties.length(); x++ )


// if the property is a string, escape single ticks

if( objectDescription.accessor[x].@type == “String” )


newVal[objectDescription.accessor[x].@name] = String(value[objectDescription.accessor[x].@name]).replace(‘\”,’\’\”);


// otherwise just grab the value of the property as it is



newVal[objectDescription.accessor[x].@name] = value[objectDescription.accessor[x].@name];



// return new value

return newVal;


this function loops of the properties of an object, finds out if it’s a string, and replaces the single ticks with something acceptable in the db…

1 comment on this post.
  1. Nate:

    Love your blog!

    How do you get your code to have that nice background and change font in wordpress. Do you do that by hand or is there some kind of plugin?


Leave a comment