separated the sql code to fetch current buffer