Link to home
Create AccountLog in
Avatar of SDKCompany
SDKCompanyFlag for United States of America

asked on

SQLite DB will not update

Can any one tell me why the db will not work.  I can get data to insert, but not update.

Here is the code from the view that has the "Add Progress" button:
 
<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009" 
		xmlns:s="library://ns.adobe.com/flex/spark"
		xmlns:mx="library://ns.adobe.com/flex/mx"
		initialize="view1_initializeHandler(event)"
		color="0x000000"		
		xmlns:c="components.*"
		xmlns:components1="com.flexets.goalseeker.views.components.*">

	<fx:Declarations>
		<s:DateTimeFormatter id="dateFormatter" dateStyle="short" timeStyle="none"/>
	</fx:Declarations>
	
	<fx:Script>
		<![CDATA[
			import com.flexets.goalseeker.views.components.DatePicker;
			import com.flexets.goalseeker.views.components.DatePickerEvent;
			
			import database.Database;
			import database.DatabaseEvent;
			import database.DatabaseResponder;
			
			import model.ModelLocator;
			
			import mx.core.INavigatorContent;
			import mx.core.UIComponent;
			import mx.events.FlexEvent;
			import mx.managers.PopUpManager;
			
			import spark.components.Image;
			
			[Bindable]
			public var date1: Date = new Date();

			private var goalID:int;
			private var units:String;
			private var progress:Number;
			private var strProg:String;
			private var totProg:Number;
			private var bolProgDir:Boolean;
			private var strbolProgDir:String;
			private var strNumProg:Number;
			
			protected function view1_initializeHandler(event:FlexEvent):void
			{
				if ( !this.data ) return;				
				
				this.goalID = this.data.goalID;
				this.progress = this.data.progress;
				this.units = this.data.units;
			}			
			
			protected function startProg_clickHandler(event:MouseEvent):void
			{
				var db:Database = ModelLocator.getInstance().db;
				var responder:DatabaseResponder = new DatabaseResponder();
				responder.addEventListener(DatabaseEvent.RESULT_EVENT, onResult);
				responder.addEventListener(DatabaseEvent.ERROR_EVENT, onError);
				
				
				var prog:Object = new Object();
				prog.progDate = date1;
				prog.comments = this.comments.text;
				prog.prog = this.progtxt.text;
				prog.goalID = this.goalID;
				prog.units = this.units;

				this.strProg = this.progtxt.text;
				this.strNumProg = Number(this.strProg);
				this.totProg = this.progress + this.strNumProg;
				if (Math.abs(this.totProg) > Math.abs(this.progress))
				{
					this.bolProgDir = true;
				}
				else
				{
					this.bolProgDir = false;
				}
				
				prog.progDir = this.bolProgDir;
				
				db.insertIntoProgress([responder, prog]);
				
				function onResult(de:DatabaseEvent):void
				{
					trace("Database result event when inserting new goal. NewGoal:0004");
					responder.removeEventListener(DatabaseEvent.RESULT_EVENT, onResult);
					responder.removeEventListener(DatabaseEvent.ERROR_EVENT, onError);
					updateGoalProg();
				}
				
				function onError(de:DatabaseEvent):void
				{
					trace("Database error event when inserting new Goal. NewGoal:0005");
					responder.removeEventListener(DatabaseEvent.RESULT_EVENT, onResult);
					responder.removeEventListener(DatabaseEvent.ERROR_EVENT, onError);					
					handleError();
				}
			}
			
			private function handleError():void
			{
				trace("Unhandled error! NewProg:0006");
			}

			private function updateGoalProg():void
			{		 
				var db:Database = ModelLocator.getInstance().db;				
				var responder:DatabaseResponder = new DatabaseResponder();
				responder.addEventListener(DatabaseEvent.RESULT_EVENT, onResult);
				responder.addEventListener(DatabaseEvent.ERROR_EVENT, onError);
				db.updateGoalProgress([responder, this.totProg, this.data.goalID]);
				
				function onResult(de:DatabaseEvent):void
				{
					trace("Database result event while updating photo path. SurveyStart:0009");
					responder.removeEventListener(DatabaseEvent.RESULT_EVENT, onResult);
					responder.removeEventListener(DatabaseEvent.ERROR_EVENT, onError);
					getPreviousScreen();
				}
				
				function onError(de:DatabaseEvent):void
				{
					trace("Database error event while updating photo path. SurveyStart:000A");
					responder.removeEventListener(DatabaseEvent.RESULT_EVENT, onResult);
					responder.removeEventListener(DatabaseEvent.ERROR_EVENT, onError);					
					handleError();
				}
			}
			
			private function getPreviousScreen():void
			{
				navigator.popView();

			}
			
			protected function cancelProg_clickHandler(event:MouseEvent):void
			{
				navigator.popView();
			}
			
			protected function clearFormProg_clickHandler(event:MouseEvent):void
			{
				this.date.text = "";
				this.comments.text = "";
				this.progtxt.text = "";
				this.date.setFocus();
			}
			
			private function showDatePicker(): void
			{
				var datePicker: DatePicker = new DatePicker();
				datePicker.currentDate = date1;
				datePicker.addEventListener(DatePickerEvent.DATE_PICKER_SET, onDateSet);
				datePicker.addEventListener(DatePickerEvent.DATE_PICKER_CANCEL, onDateCancel);
				PopUpManager.addPopUp(datePicker, this, true);
				PopUpManager.centerPopUp(datePicker);
			}
			private var eventDate: Date;
			private function onDateCancel(event: DatePickerEvent): void
			{
				var datePicker: DatePicker = event.target as DatePicker;
				datePicker.removeEventListener(DatePickerEvent.DATE_PICKER_SET, onDateSet);
				datePicker.removeEventListener(DatePickerEvent.DATE_PICKER_CANCEL, onDateCancel);
			}
			private function onDateSet(event: DatePickerEvent): void
			{
				date1 = event.date;
				onDateCancel(event);
				
			}

		]]>
	</fx:Script>		
	
	<!-- Background -->	
	<s:Rect width="100%" height="100%">
		<s:fill>
			<s:SolidColor color="0x27408B"/>
		</s:fill>
	</s:Rect>

	<s:Scroller width="100%" height="100%">	
		
			<s:VGroup height="100%" width="100%" paddingTop="20" paddingRight="30" paddingLeft="15" paddingBottom="25" gap="10">
				<s:Label text="Enter Progress" color="0xFFFFFF" fontSize="40" fontFamily="Arial">
					<s:filters>
						<s:DropShadowFilter distance="2" angle="45"/>
					</s:filters>
				</s:Label>
				
				<s:Line width="100%">
					<s:stroke>
						<s:SolidColorStroke color="0x888888" weight="1"/>
					</s:stroke>
				</s:Line>
				
				<s:VGroup width="100%">
					<s:Label text="Progress Date" color="0xFFFFFF"/>
					<s:HGroup width="100%" verticalAlign="middle" gap="10">
						<s:TextInput id="date" text="{dateFormatter.format(date1)}" width="250"
							enter="this.progtxt.setFocus();" contentBackgroundColor="0xFFFFFF"/>
						<s:Button label="Change Date" click="showDatePicker()" height="60" color="0xFFFFFF"/>
					</s:HGroup>
				</s:VGroup>
				
				<s:VGroup width="100%">				
					<s:Label text="Progress" color="0xFFFFFF"/>
					<s:HGroup width="100%" verticalAlign="middle" gap="10">
						<s:TextInput id="progtxt" width="250" maxChars="25" enter="this.comments.setFocus();"
							restrict="-.0-9" contentBackgroundColor="0xFFFFFF"/>
						<s:Image source="@Embed(source='assets/Check.png')" visible="{(progtxt.text != '') ? true: false}"/>
					</s:HGroup>
				</s:VGroup>
				
				<s:VGroup width="100%">		
					<s:Label text="Comments" color="0xFFFFFF"/>
					<s:HGroup width="100%" verticalAlign="middle" gap="10">
						<s:TextInput id="comments" width="100%" maxChars="60"
									 contentBackgroundColor="0xFFFFFF"/>
						<s:Image source="@Embed(source='assets/Check.png')" visible="{(comments.text != '') ? true: false}"/>
					</s:HGroup>
				</s:VGroup>
				
				<s:Line width="100%">
					<s:stroke>
						<s:SolidColorStroke color="0x888888" weight="1"/>
					</s:stroke>
				</s:Line>
				<s:HGroup width="100%" gap="20">
					<s:Button color="0xFFFFFF" label="Add Progress" click="startProg_clickHandler(event)"/>
					<s:Button color="0xFFFFFF" label="Cancel" click="cancelProg_clickHandler(event)"/>	
					<s:Button color="0xFFFFFF" label="Clear Form" click="clearFormProg_clickHandler(event)"/>	
				</s:HGroup>		
			</s:VGroup>				
	</s:Scroller>
</s:View>

Open in new window


Here is the code that controls changes to the database.  The above code works great calling the insertIntoProgress function, but the above code should call the updateGoalProgress function and somewhere between there and the sql to update the table, it is broken.
 
package database
{
	import flash.data.SQLConnection;
	import flash.data.SQLMode;
	import flash.data.SQLResult;
	import flash.data.SQLStatement;
	import flash.events.EventDispatcher;
	import flash.events.SQLErrorEvent;
	import flash.events.SQLEvent;
	import flash.filesystem.File;
	import flash.filesystem.FileMode;
	import flash.filesystem.FileStream;
	import flash.net.Responder;
	
	import utils.DebugUtil;

	public class Database extends EventDispatcher
	{
		private var dbFile:File;
		public var aConn:SQLConnection;		
		private var sqlStatementFactory:SQLStatementFactory;
		
		public static const TABLES_CREATED:String = "TABLES_CREATED";
		
		private const CREATE_TABLE_GOALS:String = "CREATE TABLE IF NOT EXISTS gs_Goals (id INTEGER PRIMARY KEY AUTOINCREMENT, title TEXT, why TEXT, startDate DATE, endDate DATE, initProg REAL, endGoal REAL, units TEXT, imagePath TEXT, progress REAL, catType INTEGER)";
		private const CREATE_TABLE_PROGRESS:String = "CREATE TABLE IF NOT EXISTS gs_Progress (id INTEGER PRIMARY KEY AUTOINCREMENT, date DATE, prog REAL, comment TEXT, goalID INTEGER NOT NULL, progDir BOOLEAN, units TEXT)";		
		/**
		 * private const CREATE_TABLE_GOAL_PROG_REL:String = "CREATE TABLE IF NOT EXISTS gs_goal_prog_rel (goalID INTEGER NOT NULL, progID INTEGER NOT NULL);";
		**/
		
		private const GET_GOAL:String = "SELECT * FROM gs_Goals WHERE id = :id";
		private const GET_GOALS:String = "SELECT * FROM gs_Goals";
		private const GET_PROGRESS:String = "SELECT * FROM gs_Progress WHERE id = :id";	
		private const GET_PROGRESS_FOR_GOAL:String = "SELECT a.* FROM gs_Progress a, gs_Goals r WHERE a.goalID = r.id AND r.id = :id ORDER BY a.id";
		
		private const INSERT_INTO_GOALS:String = "INSERT INTO gs_Goals (title, why, startDate, endDate, initProg, endGoal, units, imagePath, progress, catType) VALUES (:stTitle, :why, :stDate, :endDate, :stVal, :endGoal, :stUnits, :imgPath, :progress, :catType)";
		private const INSERT_INTO_PROGRESS:String = "INSERT INTO gs_Progress (date, prog, comment, goalID, progDir, units) VALUES (:date, :prog, :comment, :goalID, :progDir, :units)";
		
		private const UPDATE_GOALS:String = "UPDATE gs_Goals SET title = :title, why = :why, startDate = :startDate, endDate = :endDate, initProg = :initProg, endGoal = :endGoal, units = :units, imagePath = :imagePath WHERE id = :id";
		private const UPDATE_GOAL_PROGRESS:String = "UPDATE gs_Goals SET progress=:progress WHERE id=:id";
		
		public function Database()
		{
		
		}
		
		/**
		 * Create the asynchronous connection to the database, then create the tables
		 * 
		 * @param responder:DatabaseResponder Will dispatch result or error events when the tables are created. Dispatches an event with data TABLES_CREATED 
		 *  when all tables have been successfully created. 
		 **/
		public function init(responder:DatabaseResponder):void
		{
			var internalResponder:DatabaseResponder = new DatabaseResponder();
			internalResponder.addEventListener(DatabaseEvent.RESULT_EVENT, onResult);
			internalResponder.addEventListener(DatabaseEvent.ERROR_EVENT, onError);						
			openConnection(internalResponder);	
			
			function onResult(de:DatabaseEvent):void
			{
				internalResponder.removeEventListener(DatabaseEvent.ERROR_EVENT, onError);
				internalResponder.removeEventListener(DatabaseEvent.RESULT_EVENT, onResult);				
				createTables(responder);				
			}
			
			function onError(de:DatabaseEvent):void
			{				
				internalResponder.removeEventListener(DatabaseEvent.ERROR_EVENT, onError);
				internalResponder.removeEventListener(DatabaseEvent.RESULT_EVENT, onResult);
			}
		}
		
		private function openConnection(responder:DatabaseResponder):void
		{
			this.dbFile = File.applicationStorageDirectory.resolvePath("GoalSeeker.db");
			if ( !this.dbFile.exists )
			{
				var isSuccess:Boolean = utils.DebugUtil.createSampleDatabase(this.dbFile);
				if ( !isSuccess )
				{
					trace("There was an unrecoverable error while creating the initial database. Database:0003");
					return;
				}
			}		
			
			this.aConn = new SQLConnection();
			this.aConn.addEventListener(SQLEvent.OPEN, onConnOpen);
			this.aConn.addEventListener(SQLErrorEvent.ERROR, onConnError);
			this.aConn.openAsync(dbFile, SQLMode.CREATE);
			
			function onConnOpen(se:SQLEvent):void
			{
				trace("SQL Connection successfully opened. Database:0001");
				aConn.removeEventListener(SQLEvent.OPEN, onConnOpen);
				aConn.removeEventListener(SQLErrorEvent.ERROR, onConnError);					
				sqlStatementFactory = new SQLStatementFactory(aConn);					
				var de:DatabaseEvent = new DatabaseEvent(DatabaseEvent.RESULT_EVENT);
				responder.dispatchEvent(de);				
			}
			
			function onConnError(see:SQLErrorEvent):void
			{
				trace("SQL Error while attempting to open database. Database:0002");
				aConn.removeEventListener(SQLEvent.OPEN, onConnOpen);
				aConn.removeEventListener(SQLErrorEvent.ERROR, onConnError);
				
				var de:DatabaseEvent = new DatabaseEvent(DatabaseEvent.ERROR_EVENT);
				responder.dispatchEvent(de);
			}
		}
		
		/**
		 * Will execute SQL that will either create the tables in a fresh database or return, if they're already created.
		 **/
		public function createTables(responder:DatabaseResponder):void
		{						
			createGoalsTable([responder]);				
		}

		/**
		 * Creates the goals table
		 * 
		 * @param args Expects element 0 to be a DatabaseResponder.
		 **/
		private function createGoalsTable(args:Array):void
		{	
			if ( args[0] is DatabaseResponder )
			{						
				var sqlWrapper:SQLWrapper = this.sqlStatementFactory.newInstance(args[0], CREATE_TABLE_GOALS, createProgressTable)
				sqlWrapper.statement.execute();
			}
		}
		
		/**
		 * Creates the progress table.
		 * 
		 * @param args Expects element 0 to be a DatabaseResponder.
		 **/
		private function createProgressTable(args:Array):void
		{			
			if ( args[0] is DatabaseResponder ) 
			{
				var sqlWrapper:SQLWrapper = this.sqlStatementFactory.newInstance(args[0], CREATE_TABLE_PROGRESS, finishedCreatingTables);
				sqlWrapper.statement.execute();				
			}
		}	

		/**
		 * Dispatches a complete event
		 * 
		 * @param args Expects element 0 to be a DatabaseResponder
		 **/
		private function finishedCreatingTables(args:Array):void
		{
			if ( args[0] is DatabaseResponder )
			{
				var de:DatabaseEvent = new DatabaseEvent(DatabaseEvent.RESULT_EVENT);
				de.data = Database.TABLES_CREATED;
				args[0].dispatchEvent(de);
			}
		}
		
		/**
		 * Gets the list of goals
		 * 
		 * @param args Expects element 0 to be a DatabaseResponder.
		 **/
		public function getGoals(args:Array):void
		{					
			if ( args[0] is DatabaseResponder )
			{
				var sqlWrapper:SQLWrapper = this.sqlStatementFactory.newInstance(args[0], GET_GOALS);
				sqlWrapper.statement.execute();
			}
		}	
		
		
		/**
		 * Gets a goal from the database. Selects by id
		 * 
		 * @param args Array [responder:DatabaseResponder, id:Number]
		 **/
		public function getGoal(args:Array):void
		{					
			if ( args[0] is DatabaseResponder && args[1] is Number )
			{
				var sqlWrapper:SQLWrapper = this.sqlStatementFactory.newInstance(args[0], GET_GOAL);
				sqlWrapper.statement.parameters[":id"] = args[1];
				sqlWrapper.statement.execute();
			}
		}	
		
		/**
		 * Gets progress from the database. Selects by id
		 * 
		 * @param args Array [responder:DatabaseResponder, id:Number]
		 **/
		public function getProgress(args:Array):void
		{					
			if ( args[0] is DatabaseResponder && args[1] is Number )
			{
				var sqlWrapper:SQLWrapper = this.sqlStatementFactory.newInstance(args[0], GET_PROGRESS);
				sqlWrapper.statement.parameters[":id"] = args[1];
				sqlWrapper.statement.execute();
			}
		}
		
		/**
		 * Inserts into the goals table. Arguments must be as specified
		 * 
		 * @param args Array [responder:DatabaseResponder, personObject:Object]
		 * personObject consists of key value pairs:
		 * 		stTitle:String, 
		 * 		why:String, 
		 * 		stDate:Date, 
		 * 		endDate:Date, 
		 * 		stVal:Number,
		 * 		endGoal:Number,
		 * 		stUnits:String,
		 * 		imgPath:String,
		 * 		progress:Number,
		 * 		daysRem:Int,
		 * 		catType:Int;
		 **/
		public function insertIntoGoals(args:Array):void
		{			
			if ( args[0] is DatabaseResponder && args[1] )
			{
				var sqlWrapper:SQLWrapper = this.sqlStatementFactory.newInstance(args[0], INSERT_INTO_GOALS);
				var goal:Object = args[1];
				sqlWrapper.statement.parameters[":stTitle"] = goal.stTitle; 
				sqlWrapper.statement.parameters[":why"] =  goal.why;
				sqlWrapper.statement.parameters[":stDate"] = goal.stDate;
				sqlWrapper.statement.parameters[":endDate"] = goal.endDate;
				sqlWrapper.statement.parameters[":stVal"] = goal.stVal;
				sqlWrapper.statement.parameters[":endGoal"] = goal.endGoal;
				sqlWrapper.statement.parameters[":stUnits"] = goal.stUnits;
				sqlWrapper.statement.parameters[":imgPath"] = goal.imgPath;
				sqlWrapper.statement.parameters[":progress"] = goal.progress;
				sqlWrapper.statement.parameters[":catType"] = goal.catType;
				sqlWrapper.statement.execute();
			}
		}
		
		/**
		 * Inserts into the progress table. Arguments must be as specified
		 * 
		 * @param args Array [responder:DatabaseResponder, responseObject:Object]
		 * responseObject consists of key value pairs:
		 * 		date:Date,
		 * 		prog:Real,
		 * 		comment:String,
		 * 		goalID:int,
		 * 		progDir:Boolean,
		 * 		units:String;
		 * 		
		 **/
		public function insertIntoProgress(args:Array):void
		{			
			if ( args[0] is DatabaseResponder && args[1] )
			{
				var sqlWrapper:SQLWrapper = this.sqlStatementFactory.newInstance(args[0], INSERT_INTO_PROGRESS);
				var prog:Object = args[1];
				sqlWrapper.statement.parameters[":date"] = prog.progDate; 
				sqlWrapper.statement.parameters[":prog"] =  prog.prog;
				sqlWrapper.statement.parameters[":comment"] = prog.comments;
				sqlWrapper.statement.parameters[":goalID"] = prog.goalID;
				sqlWrapper.statement.parameters[":progDir"] = prog.progDir;
				sqlWrapper.statement.parameters[":units"] = prog.units;
				sqlWrapper.statement.execute();
			}
		}
		/**
		 * Gets ids and progress from the gs_Progress table, where the goalID of the gs_Progress table equals the id in the gs_Goals table.
		 *  All progress assigned to a goal will be returned in an array. 
		 * 		
		 * @param args Array [responder:DatabaseRespodner, id:Number]
		 **/
		public function getProgressForGoal(args:Array):void
		{
			if ( args[0] is DatabaseResponder && args[1] is Number )	
			{
				var sqlWrapper:SQLWrapper = this.sqlStatementFactory.newInstance(args[0], GET_PROGRESS_FOR_GOAL);
				sqlWrapper.statement.parameters[":id"] = args[1];
				sqlWrapper.statement.execute();
			}
		}
		
		/**
		 * Updates the progress for a given goal
		 * 		
		 * @param args Array [responder:DatabaseResponder, goalID:int, progress:Number]
		 **/
		public function updateGoalProgress(args:Array):void
		{
			if ( args[0] is DatabaseResponder && args[1] is Number && args[2] is Number)	
			{
				var sqlWrapper:SQLWrapper = this.sqlStatementFactory.newInstance(args[0], UPDATE_GOAL_PROGRESS);
				sqlWrapper.statement.parameters[":progress"] = args[1];
				sqlWrapper.statement.parameters[":id"] = args[2];
				sqlWrapper.statement.execute();
			}
		}
	}
}

Open in new window

Avatar of dgofman
dgofman
Flag of United States of America image

I can see you are inserting row by using statment

INSERT INTO gs_Goals

by before to update gs_Goals record you have to get UID from the table

I don't see you are using SELECT before call UPDATE
ASKER CERTIFIED SOLUTION
Avatar of dgofman
dgofman
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of SDKCompany

ASKER

I am not sure exactly what you mean.  Here is a better flow of what is going on (or at least supposed to).  A user fills out a form and then click the Add Progress button which invokes this function:
 
protected function startProg_clickHandler(event:MouseEvent):void
			{
				var db:Database = ModelLocator.getInstance().db;
				var responder:DatabaseResponder = new DatabaseResponder();
				responder.addEventListener(DatabaseEvent.RESULT_EVENT, onResult);
				responder.addEventListener(DatabaseEvent.ERROR_EVENT, onError);
				
				
				var prog:Object = new Object();
				prog.progDate = date1;
				prog.comments = this.comments.text;
				prog.prog = this.progtxt.text;
				prog.goalID = this.goalID;
				prog.units = this.units;

				this.strProg = this.progtxt.text;
				this.strNumProg = Number(this.strProg);
				this.totProg = this.progress + this.strNumProg;
				if (Math.abs(this.totProg) > Math.abs(this.progress))
				{
					this.bolProgDir = true;
				}
				else
				{
					this.bolProgDir = false;
				}
				
				prog.progDir = this.bolProgDir;
				
				db.insertIntoProgress([responder, prog]);
				
				function onResult(de:DatabaseEvent):void
				{
					trace("Database result event when inserting new goal. NewGoal:0004");
					responder.removeEventListener(DatabaseEvent.RESULT_EVENT, onResult);
					responder.removeEventListener(DatabaseEvent.ERROR_EVENT, onError);
					updateGoalProg();
				}
				
				function onError(de:DatabaseEvent):void
				{
					trace("Database error event when inserting new Goal. NewGoal:0005");
					responder.removeEventListener(DatabaseEvent.RESULT_EVENT, onResult);
					responder.removeEventListener(DatabaseEvent.ERROR_EVENT, onError);					
					handleError();
				}
			}

Open in new window


That function calls this function:
 
public function insertIntoProgress(args:Array):void
		{			
			if ( args[0] is DatabaseResponder && args[1] )
			{
				var sqlWrapper:SQLWrapper = this.sqlStatementFactory.newInstance(args[0], INSERT_INTO_PROGRESS);
				var prog:Object = args[1];
				sqlWrapper.statement.parameters[":date"] = prog.progDate; 
				sqlWrapper.statement.parameters[":prog"] =  prog.prog;
				sqlWrapper.statement.parameters[":comment"] = prog.comments;
				sqlWrapper.statement.parameters[":goalID"] = prog.goalID;
				sqlWrapper.statement.parameters[":progDir"] = prog.progDir;
				sqlWrapper.statement.parameters[":units"] = prog.units;
				sqlWrapper.statement.execute();
			}
		}

Open in new window


That function then sends the sql statement to the DB:
private const INSERT_INTO_PROGRESS:String = "INSERT INTO gs_Progress (date, prog, comment, goalID, progDir, units) VALUES (:date, :prog, :comment, :goalID, :progDir, :units)";

The original function called by the button press should then call this function to update a different table:
 
private function updateGoalProg():void
			{		 
				var db:Database = ModelLocator.getInstance().db;				
				var responder:DatabaseResponder = new DatabaseResponder();
				responder.addEventListener(DatabaseEvent.RESULT_EVENT, onResult);
				responder.addEventListener(DatabaseEvent.ERROR_EVENT, onError);
				db.updateGoalProgress([responder, this.totProg, this.data.goalID]);
				
				function onResult(de:DatabaseEvent):void
				{
					trace("Database result event while updating photo path. SurveyStart:0009");
					responder.removeEventListener(DatabaseEvent.RESULT_EVENT, onResult);
					responder.removeEventListener(DatabaseEvent.ERROR_EVENT, onError);
					getPreviousScreen();
				}
				
				function onError(de:DatabaseEvent):void
				{
					trace("Database error event while updating photo path. SurveyStart:000A");
					responder.removeEventListener(DatabaseEvent.RESULT_EVENT, onResult);
					responder.removeEventListener(DatabaseEvent.ERROR_EVENT, onError);					
					handleError();
				}
			}

Open in new window


That function calls the DB update function:
 
public function updateGoalProgress(args:Array):void
		{
			if ( args[0] is DatabaseResponder && args[1] is Number && args[2] is Number)	
			{
				var sqlWrapper:SQLWrapper = this.sqlStatementFactory.newInstance(args[0], UPDATE_GOAL_PROGRESS);
				sqlWrapper.statement.parameters[":progress"] = args[1];
				sqlWrapper.statement.parameters[":id"] = args[2];
				sqlWrapper.statement.execute();
			}
		}

Open in new window


Which finally should send this sql to the DB:
private const UPDATE_GOAL_PROGRESS:String = "UPDATE gs_Goals SET progress=:progress WHERE id=:id";

For some reason, the insert function works great, but the update function does not work no matter what I seem to try.
There are two tables that we are dealing with.  The first is the gs_Goals table and the second is the gs_Progress table.  The code that is calling the insert and update functions are contained in a flex view that is for entering a new progress record.  That view is passed the goalID (using navigator.pushview(NewProg, obj)) from the previous view which showed the Goal Details.  What I am trying to do is insert the new progress record and then generate the total from the progress that was entered (which that part works fine as I have verified that the varible is getting updated) and then update the gs_Goals table with the new total based on the ID goalID.  I can debug and see that I have the correct ID number and the correct total progress, but for some reason the code to update the gs_Goals table using those two numbers does not work.
Here are the other classes in case it helps:

DatabaseEvent
 
package database
{
	import flash.events.Event;

	public class DatabaseEvent extends Event
	{
		public static const ERROR_EVENT:String   = "errorEvent";
		public static const RESULT_EVENT:String  = "resultEvent";
		
		public var data:*;
		
		public function DatabaseEvent(type:String)
		{
			super(type);
		}
	}
}

Open in new window


DatabaseResponder
 
package database
{
	import flash.events.EventDispatcher;

	public class DatabaseResponder extends EventDispatcher
	{
		[Event(name="errorEvent",  type="database.DatabaseEvent")]
		[Event(name="resultEvent", type="database.DatabaseEvent")]
		
		public function DatabaseResponder()
		{
		}
	}
}

Open in new window


SQLStatementFactory
 
package database
{
	import flash.data.SQLConnection;
	import flash.data.SQLResult;
	import flash.data.SQLStatement;
	import flash.errors.SQLError;
	import flash.events.SQLErrorEvent;
	import flash.events.SQLEvent;
	
	import mx.core.IFactory;
	
	public class SQLStatementFactory
	{
		private var aConn:SQLConnection;
		
		public function SQLStatementFactory(aConn:SQLConnection)
		{
			this.aConn = aConn;
		}
		
		/**
		 * This factory avoids duplication of event handlers.
		 * It creates and returns an SQLWrapper Object, which contains a number of properties the calling funnction will find useful.
		 * The two, optional callback functions are useful for controlling asycnhronous program flow.
		 * The callback functions must accept one non-null Array argument, with args[0] being the responder 
		 * 
		 * @param responder Will dispatch DatabaseEvents on success or failure 
		 * @param sqlQuery A query in plaintext. Assumes it's sanitized!		 
		 * @param onResultCallback Optional callback function, in addition to dispatching a DatabaseEvent.RESULT_EVENT through the responder. 
		 * @param onErrorCallback Optional callback function, in addition to dispatching a DatabaseEvent.ERROR_EVENT through the responder.		 
		 * 
		 * @returns SQLWrapper
		 **/
		public function newInstance(responder:DatabaseResponder, sqlQuery:String, onResultCallback:Function = null, onErrorCallback:Function = null):SQLWrapper
		{
			if ( !this.aConn || !this.aConn.connected ) return null;

			var wrapper:SQLWrapper = new SQLWrapper();
			wrapper.responder = responder;	
			
			wrapper.statement = new SQLStatement();
			wrapper.statement.sqlConnection = this.aConn;
			wrapper.statement.text = sqlQuery;		
			
			wrapper.onResult = function onResult(se:SQLEvent):void
				{
					// trace("SQLStatement result event. SQLStatementFactory:0001");
												
					var de:DatabaseEvent = new DatabaseEvent(DatabaseEvent.RESULT_EVENT);
					de.data = wrapper.statement.getResult().data;
					wrapper.responder.dispatchEvent(de);
					// Is there a callback function specified?
					if ( onResultCallback != null )
					{
						var args:Array = [responder];
						onResultCallback(args);
					}							
					wrapper.cleanUp();
				}
						
			wrapper.onError = function onError(see:SQLErrorEvent):void
				{
					// trace("SQLStatement error event. SQLStatementFactory:0002");
						
					var de:DatabaseEvent = new DatabaseEvent(DatabaseEvent.ERROR_EVENT);
					de.data = see.error;
					wrapper.responder.dispatchEvent(de);
					// Callback function?
					if ( onErrorCallback != null ) 
					{								
						var args:Array = [responder];
						onErrorCallback(args);
					}
					wrapper.cleanUp();
				}	
				
			wrapper.statement.addEventListener(SQLEvent.RESULT,wrapper.onResult);
			wrapper.statement.addEventListener(SQLErrorEvent.ERROR,wrapper.onError);
				
			wrapper.cleanUp = function cleanUp():void
			{
				wrapper.statement.removeEventListener(SQLEvent.RESULT, wrapper.onResult);
				wrapper.statement.removeEventListener(SQLErrorEvent.ERROR, wrapper.onError);
			}
						
			return wrapper;
		}
	}
}

Open in new window


SQLWrapper
 
package database
{
	import flash.data.SQLResult;
	import flash.data.SQLStatement;

	public class SQLWrapper
	{
		public var responder:DatabaseResponder;
		public var statement:SQLStatement;
		public var result:SQLResult;
		
		// Called when a query is executed successfully or unsuccessfully. Usually called to dispatch events
		public var onResult:Function;
		public var onError:Function;
		
		// Removes event listeners for the garbage collector  
		public var cleanUp:Function; 
		
		public function SQLWrapper()
		{
		}
	}
}

Open in new window

Hi SDKCompany,
Did you submit full code of SQLWrapper.as ?

Remeber you are calling updateGoalProgress and passing "this.data.goalID"

.updateGoalProgress([responder, this.totProg, this.data.goalID]);

can you trace this varaible?

trace(this.data.goalID);

I don't see from your code your are upatating that value
Please bear with me as I am very new to all of this.  The variables all come back ok.  However, when I put a breakpoint at line 89 updateGoalProg() in the original code above under startProg_clickHandler, it never breaks which tells me that it is not getting to that function call.  Do you agree with that logic?
please send me you project I will help you to solve your probelm
david_gofman@yahoo.com
I am re-writing the code for accessing the DB.