public function setParameter( $parameter, $value, $restorePoint = self::PREVIOUS, $type = self::SESSION )
    {

        if (!is_scalar($value)) {
            throw new BadTypeException($value, 'scalar');
        }

        self::isParameterAllowed( $parameter );
        if( !in_array( $type, array( self::SESSION, self::LOCAL ) ) ) {
            throw new \InvalidArgumentException("WTF!");
        }

        if( $restorePoint and !is_scalar($restorePoint) ) {
            throw new \InvalidArgumentException( "RestorePoint has to be a scalar.");
        }

        // manage previous and original stores
        $currentValue = $this->getParameter( $parameter );

        if( !isset( $this->parameterStore[$parameter][self::ORIGINAL] ) ) {
            $this->parameterStore[$parameter][self::ORIGINAL] = $currentValue;
        }

        $this->parameterStore[$parameter][self::PREVIOUS] = $currentValue;

        // we can't quote a parameter value so regex
        /*
        if( preg_match_all('/[^a-zA-Z0-9_]/', $value, $matches ) ) {
            $badChars = implode('', $matches[0]);
            throw new \Exception( "We can't quote parameter values. Bad characters `{$badChars}`" );
        }
         */

        // bool
        if( $value === true ) {
            $value = 'true';
        } elseif( $value === false ) {
            $value = 'false';
        }

        // parameters
        if( $restorePoint !== self::PREVIOUS ) {
            $this->parameterStore[$parameter][$restorePoint] = $value;
        }

        $value = $this->query( new Raw("SET {$parameter} TO {$value}") );

        return $this;

    }