protected function build_sql() {

		$builder = new Builder();

		$select = $this->parse_select();
		$from   = new From( $this->table->get_table_name( $GLOBALS['wpdb'] ), 'q' );

		$where = new Where( 1, true, 1 );

		if ( ( $message = $this->parse_message() ) !== null ) {
			$where->qAnd( $message );
		}

		if ( ( $level = $this->parse_level() ) !== null ) {
			$where->qAnd( $level );
		}

		if ( ( $user = $this->parse_user() ) !== null ) {
			$where->qAnd( $user );
		}

		if ( ( $group = $this->parse_group() ) !== null ) {
			$where->qAnd( $group );
		}

		if ( ( $time = $this->parse_time() ) !== null ) {
			$where->qAnd( $time );
		}

		$order = $this->parse_order();
		$limit = $this->parse_pagination();

		$builder->append( $select )->append( $from );

		$builder->append( $where );
		$builder->append( $order );

		if ( $limit !== null ) {
			$builder->append( $limit );
		}

		return $builder->build();
	}