Skip to content
Siminov Framework edited this page Jan 16, 2016 · 10 revisions

Total

Exposes API's to return total of all non-NULL values in the group. The non-standard total() function is provided as a convenient way to work around this design problem in the SQL language. The result of total() is always a floating point value.

Android API: Total

    public ITotal total() throws DatabaseException;
  • Android: ITotal Interface
    public interface ITotal {

        public ITotalClause where(String column);
	
        public ITotal whereClause(String whereClause);
	
        public ITotalClause and(String column);
	
        public ITotalClause or(String column);

        public ITotal groupBy(String...columns);
	
        public ITotalClause having(String column);

        public ITotal havingClause(String havingClause);
	
        public ITotal column(String column);
	
        public Object execute() throws DatabaseException;
	
    }
  • Android: ITotalClause Interface
    public interface ITotalClause {

        public ITotal equalTo(String value);

        public ITotal notEqualTo(String value);
	
        public ITotal greaterThan(String value);
	
        public ITotal greaterThanEqual(String value);
	
        public ITotal lessThan(String value);
	
        public ITotal lessThanEqual(String value);
	
        public ITotal between(String start, String end);
	
        public ITotal like(String like);
	
        public ITotal in(String...values);
	
    }
Android Sample: Get Total
    int total = 0;
	
    try {
        total = new Book().total().column(Book.COLUMN_NAME_WHICH_CONTAIN_NUMBRIC_VALUE).where(Book.TITLE).equalTo("C").execute();
    } catch(DatabaseException de) {
		//Log it.
    }

iOS API: Total

    - (id<SICITotal>)total;
  • iOS: SICITotal Interface
    @protocol SICITotal <NSObject>

    - (id<SICITotalClause>)where:(NSString *)column;

    - (id<SICITotal>)whereClause:(NSString *)whereClause;

    - (id<SICITotalClause>)and:(NSString *)column;
  
    - (id<SICITotalClause>)or:(NSString *)column;

    - (id<SICITotal>)groupBy:(NSArray *)columns;

    - (id<SICITotalClause>)having:(NSString *)column;

    - (id<SICITotal>)havingClause:(NSString *)havingClause;

    - (id<SICITotal>)column:(NSString *)column;

    - (id)execute;

    @end
  • _iOS: SICITotalClause Interface
    @protocol SICITotalClause <NSObject>

    - (id<SICITotal>)equalTo:(id)value;

    - (id<SICITotal>)notEqualTo:(id)value;

    - (id<SICITotal>)greaterThan:(id)value;
 
    - (id<SICITotal>)greaterThanEqual:(id)value;

    - (id<SICITotal>)lessThan:(id)value;

    - (id<SICITotal>)lessThanEqual:(id)value;

    - (id<SICITotal>)between:(id)start end:(id)end;

    - (id<SICITotal>)like:(id)like;

    - (id<SICITotal>)in:(id)values;

    @end
iOS Sample: Get Total
    double total = 0;
	
    @try {
        total = [[[[[[[Book alloc] init] total] column:[Book COLUMN_NAME_WHICH_CONTAIN_NUMBRIC_VALUE]] where:[Book TITLE]] equalTo:@"C"] execute];
    } @catch(SICDatabaseException *databaseException) {
		//Log it.
    }

Windows API: Total

    public ITotal Total();
  • Windows: ITotal Interface
    public interface ITotal 
    {

        ITotalClause Where(String column);
	
        ITotal WhereClause(String whereClause);
	
        ITotalClause And(String column);
	
        ITotalClause Or(String column);

        ITotal GroupBy(String[] columns);
	
        ITotalClause Having(String column);

        ITotal HavingClause(String havingClause);
	
        ITotal Column(String column);
	
        double Execute();
	
    }
  • Windows: ITotalClause Interface
    public interface ITotalClause 
    {

        ITotal EqualTo(String value);

        ITotal NotEqualTo(String value);
	
        ITotal GreaterThan(String value);
	
        ITotal GreaterThanEqual(String value);
	
        ITotal LessThan(String value);
	
        ITotal LessThanEqual(String value);
	
        ITotal Between(String start, String end);
	
        ITotal Like(String like);
	
        ITotal In(String[] values);
	
    }
Windows Sample: Get Total
    double total = 0;
	
    try 
    {
        total = new Book().Total().Column(Book.COLUMN_NAME_WHICH_CONTAIN_NUMBRIC_VALUE).Where(Book.TITLE).EqualTo("C").Execute();
    } 
    catch(DatabaseException de) 
    {
		//Log it.
    }

JavaScript API: Total

    this.total = function();
  • JavaScript: ITotal Interface
    function ITotal() {

        this.where = function(column);
	
        this.whereClause = function(whereClause);
	
        this.and = function(column);
	
        this.or = function(column);

        this.groupBy = function(columns);
	
        this.having = function(column);

        this.havingClause = function(havingClause);
	
        this.column = function(column);
	
        this.execute = function();

        this.executeAsync = function(callback, transaction);
	
    }
  • JavaScript: ITotalClause Interface
    function ITotalClause() {

        this.equalTo = function(value);

        this.notEqualTo = function(value);
	
        this.greaterThan = function(value);
	
        this.greaterThanEqual = function(value);
	
        this.lessThan = function(value);
	
        this.lessThanEqual = function(value);
	
        this.between = function(start, end);
	
        this.like = function(like);
	
        this.in = function(values);
	
    }
JavaScript Sample: Get Total
            /** Total Sample **/

    double total = 0;
	
    try {
        total = new Book().total().column(Book.COLUMN_NAME_WHICH_CONTAIN_NUMBRIC_VALUE).where(Book.TITLE).equalTo("C").execute();
    } catch(de) {
		//Log it.
    }
            /** Total Async Sample **/

    var callback = new Callback();
    callback.onSuccess = function(total) {

    }

    new Book().total().executeAsync(callback);
            /** Total Async Transaction Sample **/

    var callback = new Callback();
    callback.onExecute = function(transaction) {

        var totalCallback = new Callback();
        totalCallback.onSuccess = function() {

        }

        new Book().total().executeAsync(totalCallback, transaction);
    }

    callback.onSuccess = function() {

    }

    var databaseDescriptor = new Lession().getDatabaseDescriptor();
    Database.beginTransactionAsync(databaseDescriptor, callback);