Fix limit and offset for DB

Use Owncloud's $limit and $offset variables in database access. This
makes sure that the SQL is formatted correctly for different SQL
variants (such as PostgreSQL).

Fixes owncloud/apps#1198
Fixes owncloud/apps#1262