fix bug with row number
improve sqlite perfomance