public class SelectionBuilder extends QueryBuilder<SelectionBuilder,android.database.Cursor>
SELECT
query.
Cursor crsResult = QueryBuilder.selectFrom( sTableName ) .allColumns() .where( "entity_id=?", sID ) .executeOn( db ) ;
Cursor crsResult = QueryBuilder.selectFrom( sTableName ) .columns( "entity_id", "name", "start_ts", "stop_ts" ) .where( "active=? AND start_ts>=?", QueryBuilder.WHERE_TRUE, SQLitePortal.now() ) .groupBy( "name" ) .orderBy( "name", SelectionBuilder.ORDER_ASC ) .limit( 10 ) .executeOn( db ) ;
SQLiteDatabase.query(boolean, java.lang.String, java.lang.String[], java.lang.String, java.lang.String[], java.lang.String, java.lang.String, java.lang.String, java.lang.String)
QueryBuilder.UnboundException
Modifier and Type | Field and Description |
---|---|
protected boolean |
m_bDistinct
Flag specifying whether to select distinct results.
|
protected java.util.LinkedHashMap<java.lang.String,java.lang.String> |
m_mapOrderBy
The mapping of SQLite
ORDER BY clauses and directions, if any. |
protected int |
m_nLimit
A limit on the number of results to be returned, if any.
|
protected java.lang.String |
m_sGroupBy
The SQLite
GROUP BY clause to be used, if any. |
protected java.lang.String |
m_sHaving
The SQLite
HAVING clause to be used, if any. |
protected java.util.Vector<java.lang.String> |
m_vColumns
The columns to be selected.
|
static int |
NO_LIMIT
Specifies that no result count limit should be enforced.
|
m_asExplicitWhereParams, m_dbTarget, m_sExplicitWhereFormat, m_sTableName, m_valsToWrite
Constructor and Description |
---|
SelectionBuilder(java.lang.String sTableName) |
Modifier and Type | Method and Description |
---|---|
SelectionBuilder |
allColumns()
Specifies that all columns should be selected (default).
|
SelectionBuilder |
columns(java.util.Collection<java.lang.String> asColumns)
Sets the columns that should be returned in the selection set.
|
SelectionBuilder |
columns(java.lang.String... asColumns)
Sets the columns that should be returned in the selection set.
|
SelectionBuilder |
distinct()
Specifies that selection results should be distinct.
|
SelectionBuilder |
distinct(boolean b)
Specifies whether to select distinct results.
|
android.database.Cursor |
executeOn(android.database.sqlite.SQLiteDatabase db)
Executes the selection query.
|
protected java.lang.String[] |
getColumnList()
Generates the column list to be passed to
SQLiteDatabase.query(boolean, java.lang.String, java.lang.String[], java.lang.String, java.lang.String[], java.lang.String, java.lang.String, java.lang.String, java.lang.String) . |
protected java.lang.String |
getOrderByClause()
Generates the selection's
ORDER BY clause, if any. |
SelectionBuilder |
groupBy(java.lang.String sGroupByClause)
Specifies the SQLite
GROUP BY clause for the selection. |
SelectionBuilder |
having(java.lang.String sHavingClause)
Specifies the SQLite
HAVING clause for the selection. |
protected SelectionBuilder |
initColumns()
Initializes the vector of columns to be shown, if limited.
|
SelectionBuilder |
limit(int nLimit)
Adds an SQLite
LIMIT clause to the selection. |
SelectionBuilder |
orderBy(java.lang.String sColumnName)
Adds an SQLite
ORDER BY clause to the selection. |
SelectionBuilder |
orderBy(java.lang.String sColumnName,
java.lang.String sDirection)
Adds an SQLite
ORDER BY clause to the selection. |
java.lang.String |
toString()
Constructs a raw SQL
SELECT query based on the attributes of the
builder instance. |
deleteFrom, deleteFrom, execute, getWhereClause, getWhereFormat, getWhereParams, insertInto, insertInto, onDatabase, selectFrom, selectFrom, setTableName, setValues, toSQLInputParams, update, update, where, where, where
public static final int NO_LIMIT
limit(int)
,
Constant Field Valuesprotected boolean m_bDistinct
protected java.util.Vector<java.lang.String> m_vColumns
protected java.lang.String m_sGroupBy
GROUP BY
clause to be used, if any.protected java.lang.String m_sHaving
HAVING
clause to be used, if any.protected java.util.LinkedHashMap<java.lang.String,java.lang.String> m_mapOrderBy
ORDER BY
clauses and directions, if any.
This is a LinkedHashMap
because we want to preserve the order in
which sort keys were added to the order spec. (#52)protected int m_nLimit
protected SelectionBuilder initColumns()
public SelectionBuilder distinct(boolean b)
b
- true
if only distinct results are desiredpublic SelectionBuilder distinct()
public SelectionBuilder allColumns()
public SelectionBuilder columns(java.lang.String... asColumns)
null
to this method;
use allColumns()
instead, or use
SQLiteSyntax.SELECT_ALL
.asColumns
- the names of columns to be returnedpublic SelectionBuilder columns(java.util.Collection<java.lang.String> asColumns)
null
to this method;
use allColumns()
instead, or use
SQLiteSyntax.SELECT_ALL
.asColumns
- the names of columns to be returnedprotected java.lang.String[] getColumnList()
SQLiteDatabase.query(boolean, java.lang.String, java.lang.String[], java.lang.String, java.lang.String[], java.lang.String, java.lang.String, java.lang.String, java.lang.String)
.null
if not limited.public SelectionBuilder groupBy(java.lang.String sGroupByClause)
GROUP BY
clause for the selection.
Pass null
to specify no grouping.sGroupByClause
- the SQLite GROUP BY
clausepublic SelectionBuilder having(java.lang.String sHavingClause)
HAVING
clause for the selection.
Pass null
to specify no clause.sHavingClause
- the SQLite HAVING
clausepublic SelectionBuilder orderBy(java.lang.String sColumnName, java.lang.String sDirection)
ORDER BY
clause to the selection.
This method can be invoked multiple times to construct a multi-layered
clause.sColumnName
- the name of the column to be sortedsDirection
- the direction of sortingSQLiteSyntax.SQL_ORDER_ASC
,
SQLiteSyntax.SQL_ORDER_DESC
public SelectionBuilder orderBy(java.lang.String sColumnName)
ORDER BY
clause to the selection.
This method can be invoked multiple times to construct a multi-layered
clause.
The sorting direction set by this method is always "ascending".sColumnName
- the name of the column to be sortedprotected java.lang.String getOrderByClause()
ORDER BY
clause, if any.ORDER BY
clause for the selectionpublic SelectionBuilder limit(int nLimit)
LIMIT
clause to the selection.
To explicitly enforce no limit, pass NO_LIMIT
.nLimit
- the limit to be enforced, or NO_LIMIT
(default)public android.database.Cursor executeOn(android.database.sqlite.SQLiteDatabase db)
executeOn
in class QueryBuilder<SelectionBuilder,android.database.Cursor>
db
- the database instance on which the query should be executed.SQLiteDatabase.query(boolean, java.lang.String, java.lang.String[], java.lang.String, java.lang.String[], java.lang.String, java.lang.String, java.lang.String, java.lang.String)
public java.lang.String toString()
SELECT
query based on the attributes of the
builder instance.toString
in class java.lang.Object
SELECT
query