@Override
	public String paginate(int page) {
		// is there a need to paginate?
		if(this.rows <= 0 || this.rows <= this.per_page)
			return this.query;
		
		// check if the page is valid
		if(page <= 0) page = 1;
		if(page > this.pages) page = this.pages;
		
		// calculate rows
		this.currPage = page;
		
		int row_from = (this.currPage-1) * this.per_page;
		int row_to = Math.min((row_from + this.per_page), this.rows);
		
		return this.db.add_offset(this.query, row_from, row_to);
	}