The DBBean Framework
Advanced DBBean Select Operations

There are a number of methods available to facilitate selecting the data you want from the database. Sql where and like clauses are covered in the Basic Operations section.

All selecting operations can be used in conjunction. For example, you can select beans where some values are an exact match, others are a "like" match, order the results by the columns of your choice, and limit the number of results that will be returned.

Advanced Select Operations:

  • Order By - Adds an ORDER BY clause
  • Group By - Adds a GROUP BY clause
  • Limit - Adds a LIMIT clause, must be used in conjunction with ORDER BY
  • Count - Utility to count the number of Beans that match the current select criteria
 
DB mDB = [get the db instance];

// order the results of selecting all people by first names
PersonBean mBean = new Person();
mBean.addOrderBy(PersonBean.FIRST_NAME);
DBBean[] mArray = mDB.selectBean(mBean);
 
DB mDB = [get the db instance];

// group all people by first name, just for example
DBBean mBean = new PersonBean();
mBean.addGroupBy(PersonBean.FIRST_NAME);
DBBean[] mArray = mDB.selectBean(mBean);
 
DB mDB = [get the db instance];

// Select all of the person beans ordered by first name
DBBean mBean = new PersonBean();
mBean.addOrderBy(PersonBean.FIRST_NAME);

// only select a maximum of 50 records, starting with the first
mBean.setLimit(0,50);

DBBean[] mArray = mDB.selectBean(mBean);
   
DB mDB = [get the db instance];

// how many people are in the entire DB?
DBBean mBean = new PersonBean();
int mCount = mDB.getTotalCount(mBean);

// how many people are in the DB with first name starting with j?
mBean.addSelectLike(PersonBean.FIRST_NAME,"j");
mCount = mDB.getTotalCount(mBean);