public function update($table, array $data, $where = null)
    {
        $context = $this->getCommandContext();
        $context->table    = $table;
        $context->data    = $data;
        $context->where    = $where;
        $context->operation    = AnDatabase::OPERATION_UPDATE;

        //Excute the update operation
        if ($this->getCommandChain()->run('before.update', $context) !==  false) {
            if (count($context->data)) {
                foreach ($context->data as $key => $val) {
                    $vals[] = '`'.$key.'` = '.$this->quoteValue($val);
                }

                //Create query statement
                $context->query = 'UPDATE '.$this->quoteName($this->getTableNeedle().$context->table)
                    .' SET '.implode(', ', $vals)
                    .' '.$context->where
                ;

                //Execute the query
                $context->result = $this->execute($context->query);

                $context->affected = $this->_affected_rows;
                $this->getCommandChain()->run('after.update', $context);
            } else {
                $context->affected = false;
            }
        }

        return $context->affected;
    }