Skip to content
This repository was archived by the owner on Mar 25, 2020. It is now read-only.
Ricky Tobing edited this page Aug 24, 2013 · 11 revisions

ITable represents a table inside the database. To access the table simply call

...
IDatabase db = ...
ITable table = db.get("<table-name>");
...

ITable object, once created, is automatically cached inside the IDatabase. So there's no need to reference it outside. Most of the time db.get("tableName").<someMethod>() is more preferable to use. ITable does not store any table structure or any data whatsoever. It only stores its name, alias (if any) and column names. So it's easy on the memory usage.

ITable provides common methods to perform many CRUD and other common tasks such as (functions, count, etc...). This is the object that you will reference to access and manipulate the data with.

#Operations

#ITable.count()

  • ITable.count() returns the total records inside the table. Equivalent to calling SELECT COUNT(*) IN Table in SQL
  • ITable.count(String condition) returns the total records inside the table that matches the specified condition. Equivalent to calling SELECT COUNT(*) IN Table WHERE...
  • ITable.count(String whereClause, Object... args) returns the total records inside the table that matches the whereClause. This is more preferred way then calling count(condition).

#ITable.has() This is a convenient method to check for a record existence in a table.

  • ITable.has(int id) returns true if table has a record with the same id; false if otherwise
  • ITable.has(String condition) returns true if table has a record or more that satisfy the condition; false if otherwise
  • ITable.has(String whereClause, Object... args) returns true if table has a record or more that satisfy the specified whereClause; false if otherwise

ITable.raw()

This is a convenient method to query your manual SQL script:

String sql = ...
Cursor cursor = db.get("Table")
                    .raw(sql)
                    .query();
// or
Cursor cursor = db.get("Table")
                    .raw(sql, [args]...)
                    .query();

#Functions

  • AVG Returns the average value in a specific column inside the table. Equivalent to calling SELECT AVG(column) FROM table. Use the following
int avg = db.get("table").avg("columnName").asInt(); // rounded as integer
float avg = db.get("table").avg("columnName").asFloat(); // as float
  • SUM Returns the sum (total) value in a specific column inside the table. Equivalent of calling SELECT SUM(column) FROM table. Use the following
int sum = db.get("table").sum("columnName").asInt(); // rounded as integer
float sum = db.get("table").sum("columnName").asFloat(); // as float
  • MAX Returns the maximum value in a specific column inside the table. Equivalent to calling SELECT MAX(column) FROM table. Use the following
int max = db.get("table").max("columnName").asInt(); // rounded as integer
float max = db.get("table").max("columnName").asFloat(); // as float
  • MIN Returns the minimum value in a specific column inside the table. Equivalent to calling SELECT MIN(column) FROM table. Use the following
int min = db.get("table").min("columnName").asInt(); // rounded as integer
float min = db.get("table").min("columnName").asFloat(); // as float
Clone this wiki locally