public function set($data)
    {
        if ($this->queryType !== self::QUERY_INSERT && $this->queryType !== self::QUERY_UPDATE) {
            $this->exception = new QueryException("When using set/data you must do a insert into or update first! Query is not in UPDATE or INSERT mode!", 0, $this->exception); // @codeCoverageIgnore
            return $this; // @codeCoverageIgnore
        }
        if (! is_array($data)) {
            $this->exception = new QueryException("set()/data() must have an array data parameter!", 0, $this->exception); // @codeCoverageIgnore
            return $this; // @codeCoverageIgnore
        }

        // Prepare the data
        $this->data = "";
        $this->changeData = array();

        // Verify and generate insert parts
        foreach ($this->columnOrder as $currentColumn) {
            // Verify if all the columns that are non-null exists when inserting
            if ($this->queryType === self::QUERY_INSERT) {
                // We MUST fill in the non null columns, with exception on the auto increment column
                if (! $currentColumn->null && ! $currentColumn->autoIncrement) {
                    if (! isset($data[$currentColumn->name])) {
                        $this->exception = new QueryException("Inserting data failed, data must contain all non-null columns defined in the entity!", 0, $this->exception); // @codeCoverageIgnore
                        return $this; // @codeCoverageIgnore
                    }
                }
            }

            // Skip primary key when updating.
            if ($this->queryType === self::QUERY_UPDATE && $currentColumn->primary) {
                // Skip
                continue;
            }

            // If data exists for current column
            if (isset($data[$currentColumn->name])) {
                $value = $data[$currentColumn->name];

                // Current column exists, save data
                $this->changeData[$currentColumn->name] = $value;
            } else {
                // We will insert NULL in this column, it's not given in the $data array
                $this->changeData[$currentColumn->name] = null;
            }
        }

        return $this;
    }