public function update($table, $object, $where = array(), $resync = true, $discov = null, $derive = true)	// @todo Is that the correct default for $derive?
	{
		$sql = '';
		$set = array();

		if (is_object($object))
		{
			$object = $object->asArray();
		}

		$avail = $this->fields($table, true);		// List of available fields

		// Case folding support
		if ($this->foldsToLower())
		{
			$object = array_change_key_case($object, CASE_LOWER);
		}
		else if ($this->foldsToUpper())
		{
			$object = array_change_key_case($object, CASE_UPPER);
		}

		// Merge by keys to make sure we don't INSERT any fields that don't exist in this schema
		$object = array_intersect_key($object, $avail);

		//
		foreach ($object as $field => $value)
		{
			// Commented out because doing this to very large integers (i.e. ItemRef/FullName is a large integer SKU) causes integer overflow
			/*if (strlen((int) $value) == strlen($value))
			{
				$set[] = $field . ' = ' . (int) $value;
			}
			else
			{*/
			//	$set[] = $field . " = '" . $this->_escape($value) . "' ";
			//}

			if (is_null($value))
			{
				$set[] = $field . " = NULL ";
			}
			else
			{
				$set[] = $field . " = '" . $this->_escape($value) . "' ";
			}
		}

		$wheres = array();
		foreach ($where as $part)
		{
			foreach ($part as $field => $value)
			{
				$wheres[] = $field . " = '" . $this->_escape($value) . "' ";
			}
		}

		$sql = "UPDATE " . $this->_escape($table) . " SET " . implode(', ', $set);

		if ($resync)
		{
			$sql .= ", " . QUICKBOOKS_DRIVER_SQL_FIELD_RESYNC . " = '" . date('Y-m-d H:i:s') . "' ";
		}

		$sql .= " WHERE " . implode(' AND ', $wheres);

		//print($sql);

		$errnum = 0;
		$errmsg = '';
		$return = $this->_query($sql, $errnum, $errmsg);

		if (is_null($discov))
		{
			$discov = $resync;
		}

		if ($discov)
		{
			// Update the discover datetime *IF THE DISCOVER DATETIME IS NULL*
			//	This happens when an AddResponse is received, and we need to
			//	update a record that has just been added to QuickBooks. If we
			//	don't mark it as discovered, then updates to the record will
			//	never be picked up and sent to QuickBooks

			$errnum = 0;
			$errmsg = '';

			$wheres[] = QUICKBOOKS_DRIVER_SQL_FIELD_DISCOVER . " IS NULL ";

			$this->_query("
				UPDATE
					" . $this->_escape($table) . "
				SET
					" . QUICKBOOKS_DRIVER_SQL_FIELD_DISCOVER . " = " . QUICKBOOKS_DRIVER_SQL_FIELD_RESYNC . "
				WHERE
					" . implode(' AND ', $wheres), $errnum, $errmsg);
		}

		return $return;
	}
public function update($table, $object, $where = array(), $resync = true, $discov = null, $derive = true)	// @todo Is that the correct default for $derive?
	{
		$sql = '';
		$set = array();

		if (is_object($object))
		{
			$object = $object->asArray();
		}

		$avail = $this->fields($table, true);		// List of available fields

		// Case folding support
		if ($this->foldsToLower())
		{
			$object = array_change_key_case($object, CASE_LOWER);
		}
		else if ($this->foldsToUpper())
		{
			$object = array_change_key_case($object, CASE_UPPER);
		}

		// Merge by keys to make sure we don't INSERT any fields that don't exist in this schema
		$object = array_intersect_key($object, $avail);

		//
		foreach ($object as $field => $value)
		{
			// Commented out because doing this to very large integers (i.e. ItemRef/FullName is a large integer SKU) causes integer overflow
			/*if (strlen((int) $value) == strlen($value))
			{
				$set[] = $field . ' = ' . (int) $value;
			}
			else
			{*/
			//	$set[] = $field . " = '" . $this->_escape($value) . "' ";
			//}

			if (is_null($value))
			{
				$set[] = $field . " = NULL ";
			}
			else
			{
				$set[] = $field . " = '" . $this->_escape($value) . "' ";
			}
		}

		$wheres = array();
		foreach ($where as $part)
		{
			foreach ($part as $field => $value)
			{
				$wheres[] = $field . " = '" . $this->_escape($value) . "' ";
			}
		}

		$sql = "UPDATE " . $this->_escape($table) . " SET " . implode(', ', $set);

		if ($resync)
		{
			$sql .= ", " . QUICKBOOKS_DRIVER_SQL_FIELD_RESYNC . " = '" . date('Y-m-d H:i:s') . "' ";
		}

		$sql .= " WHERE " . implode(' AND ', $wheres);

		//print($sql);

		$errnum = 0;
		$errmsg = '';
		$return = $this->_query($sql, $errnum, $errmsg);

		if (is_null($discov))
		{
			$discov = $resync;
		}

		if ($discov)
		{
			// Update the discover datetime *IF THE DISCOVER DATETIME IS NULL*
			//	This happens when an AddResponse is received, and we need to
			//	update a record that has just been added to QuickBooks. If we
			//	don't mark it as discovered, then updates to the record will
			//	never be picked up and sent to QuickBooks

			$errnum = 0;
			$errmsg = '';

			$wheres[] = QUICKBOOKS_DRIVER_SQL_FIELD_DISCOVER . " IS NULL ";

			$this->_query("
				UPDATE
					" . $this->_escape($table) . "
				SET
					" . QUICKBOOKS_DRIVER_SQL_FIELD_DISCOVER . " = " . QUICKBOOKS_DRIVER_SQL_FIELD_RESYNC . "
				WHERE
					" . implode(' AND ', $wheres), $errnum, $errmsg);
		}

		return $return;
	}
public function update ( $ table , $ object , $ where = array ( ) , $ resync = true , $ discov = null , $ derive = true ) // @todo Is that the correct default for $derive? { $ sql = '' ; $ set = array ( ) ; if ( is_object ( $ object ) ) { $ object = $ object -> asArray ( ) ; } $ avail = $ this -> fields ( $ table , true ) ; // List of available fields // Case folding support if ( $ this -> foldsToLower ( ) ) { $ object = array_change_key_case ( $ object , CASE_LOWER ) ; } else if ( $ this -> foldsToUpper ( ) ) { $ object = array_change_key_case ( $ object , CASE_UPPER ) ; } // Merge by keys to make sure we don't INSERT any fields that don't exist in this schema $ object = array_intersect_key ( $ object , $ avail ) ; // foreach ( $ object as $ field => $ value ) { // Commented out because doing this to very large integers (i.e. ItemRef/FullName is a large integer SKU) causes integer overflow /*if (strlen((int) $value) == strlen($value))
			{
				$set[] = $field . ' = ' . (int) $value;
			}
			else
			{*/ //	$set[] = $field . " = '" . $this->_escape($value) . "' "; //} if ( is_null ( $ value ) ) { $ set [ ] = $ field . " = NULL " ; } else { $ set [ ] = $ field . " = '" . $ this -> _escape ( $ value ) . "' " ; } } $ wheres = array ( ) ; foreach ( $ where as $ part ) { foreach ( $ part as $ field => $ value ) { $ wheres [ ] = $ field . " = '" . $ this -> _escape ( $ value ) . "' " ; } } $ sql = "UPDATE " . $ this -> _escape ( $ table ) . " SET " . implode ( ', ' , $ set ) ; if ( $ resync ) { $ sql .= ", " . QUICKBOOKS_DRIVER_SQL_FIELD_RESYNC . " = '" . date ( 'Y-m-d H:i:s' ) . "' " ; } $ sql .= " WHERE " . implode ( ' AND ' , $ wheres ) ; //print($sql); $ errnum = 0 ; $ errmsg = '' ; $ return = $ this -> _query ( $ sql , $ errnum , $ errmsg ) ; if ( is_null ( $ discov ) ) { $ discov = $ resync ; } if ( $ discov ) { // Update the discover datetime *IF THE DISCOVER DATETIME IS NULL* //	This happens when an AddResponse is received, and we need to //	update a record that has just been added to QuickBooks. If we //	don't mark it as discovered, then updates to the record will //	never be picked up and sent to QuickBooks $ errnum = 0 ; $ errmsg = '' ; $ wheres [ ] = QUICKBOOKS_DRIVER_SQL_FIELD_DISCOVER . " IS NULL " ; $ this -> _query ( "
				UPDATE
					" . $ this -> _escape ( $ table ) . "
				SET
					" . QUICKBOOKS_DRIVER_SQL_FIELD_DISCOVER . " = " . QUICKBOOKS_DRIVER_SQL_FIELD_RESYNC . "
				WHERE
					" . implode ( ' AND ' , $ wheres ) , $ errnum , $ errmsg ) ; } return $ return ; }
Update a record in the SQL table

@todo We should make this support only passing a single $where component, instead of an array of array where components
@todo Support the $derive flag

@param string $table			The table to update
@param object $object		An object containing a record to update
@param array $where			An array to use to build the WHERE clause
@param boolean $resync		Update the timestamp field which indicates when we last re-synced with QuickBooks
@param boolean $discov		Update the timestamp field which indicates when this record was discoved in QuickBooks
@param boolean $derive		Update the timestamp field which indicates when we last updated derived fields from QuickBooks
@return boolean
Update a record in the SQL table