Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to obtain the total number of records for pagination queries #101

Open
hs205118 opened this issue Jul 7, 2023 · 1 comment
Open

Comments

@hs205118
Copy link

hs205118 commented Jul 7, 2023

I have a database table with 100 pieces of data. I want to query 1-50 pieces of data first. In order to obtain the total number of pages, I need to query the total number of records (100). What should I do?
Thanks!

@QxOrm
Copy link
Owner

QxOrm commented Jul 10, 2023

Hello,

To get total number of records, you can use :
qx::dao::count<T>(const qx::QxSqlQuery & query = qx::QxSqlQuery(), QSqlDatabase * pDatabase = NULL)

Example from qxBlog sample project :
qx::dao::count<author>();

For pagination, you can use :
qx::QxSqlQuery::limit(int rowsCount, int startRow = 0, bool withTies = false)

Example from qxBlog sample project (you can remove .distinct() in your case) :

   QList<blog> listOfBlogDistinct;
   qx_query queryDistinct; queryDistinct.distinct().limit(10);
   daoError = qx::dao::fetch_by_query(queryDistinct, listOfBlogDistinct, NULL, QStringList() << "blog_text");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants