bool For SQL Query - Android Database

Android examples for Database:SQL Query

Description

bool For SQL Query

Demo Code


//package com.java2s;

import android.database.DatabaseUtils;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDoneException;

public class Main {
    public static boolean boolForQuery(SQLiteDatabase db, String query,
            String[] selectionArgs) {
        long value = longForQuery(db, query, selectionArgs);
        return sqlToBool((int) value);
    }/*w  ww. j av a 2 s  . c o m*/

    public static long longForQuery(SQLiteDatabase db, String query,
            String[] selectionArgs) {
        try {
            return DatabaseUtils.longForQuery(db, query, selectionArgs);
        } catch (SQLiteDoneException e) {
            return 0;
        }
    }

    public static boolean sqlToBool(int value) {
        return (value != 0);
    }
}

Related Tutorials