Issues

ZF-100: Zend_Log_Adapter_Db calls non-existent methods (TRAC#96)

Description

The 'write()' method seems to utilise outdated calls to the _dbAdapter object, including an obsoleted 'escapeString' method. In addition, there are a few lines of sql generation that could easily be passed directly to the _dbAdapter itself.

Requires a simple change from:-


    public function write($fields)
    {
        /**
         * If the field defaults for 'message' and 'level' have been changed
         * in the options, replace the keys in the $field array.
         */
        if ($this->_options['fieldMessage'] != 'message') {
            $fields[$this->_options['fieldMessage']] = $fields['message'];
            unset($fields['message']);
        }

        if ($this->_options['fieldLevel'] != 'level') {
            $fields[$this->_options['fieldLevel']] = $fields['level'];
            unset($fields['level']);
        }

        /**
         * Build an array of field names and values for the SQL statement.
         */
        $fieldNames = array();
        foreach ($fields as $key=>&$value) {
            /**
             * @todo needs to be updated for new database adapters
             */
            $fieldNames[] = "`" .$this->_dbAdapter->escapeString($key). "`";
            $value = "'" .$this->_dbAdapter->escapeString($value). "'";
            if ($value=="''") {
                $value = "NULL";
            }
        }

        /**
         * INSERT the log line into the database.  XXX Replace with Prepared Statement
         */
        /**
         * @todo needs to be updated for new database adapters
         */
        $sql = "INSERT INTO `" .$this->_dbAdapter->escapeString($this->_tableName). "` ("
             . implode(', ', $fieldNames) . ') VALUES ('
             . implode(', ', $fields) .')';

        // The database adapter will raise an exception if any problems occur.
        /**
         * @todo needs to be updated for new database adapters
         */
        $this->_dbAdapter->insert($sql);
        return true;
    }

... to ...


    public function write($fields)
    {
        /**
         * If the field defaults for 'message' and 'level' have been changed
         * in the options, replace the keys in the $field array.
         */
        if ($this->_options['fieldMessage'] != 'message') {
            $fields[$this->_options['fieldMessage']] = $fields['message'];
            unset($fields['message']);
        }

        if ($this->_options['fieldLevel'] != 'level') {
            $fields[$this->_options['fieldLevel']] = $fields['level'];
            unset($fields['level']);
        }
        
        /**
         * INSERT the log line into the database.
         */
        $this->_dbAdapter->insert($this->_tableName, $fields);
        return true;
    }

Comments

triaged by core to 0.1.5

This updates the escapeStrings to quote

Would also like to offer to maintaine this module

I have attached a fix for this issue and would like to offer my assistance in maintaining this module

updated escapeString -> quote to reflect changes in the zend_db api