Java Code Examples for android.database.sqlite.SQLiteStatement.bindDouble()

The following are Jave code examples for showing how to use bindDouble() of the android.database.sqlite.SQLiteStatement class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: Shopping_List   File: UsedProductDao.java   Source Code and License Vote up 6 votes
@Override
protected final void bindValues(SQLiteStatement stmt, UsedProduct entity) {
    stmt.clearBindings();
 
    Long id = entity.getId();
    if (id != null) {
        stmt.bindLong(1, id);
    }
    stmt.bindDouble(2, entity.getQuantity());
    stmt.bindLong(3, entity.getUnit() ? 1L: 0L);
    stmt.bindLong(4, entity.getIsPurchased() ? 1L: 0L);
    stmt.bindLong(5, entity.getDate());
 
    Long productId = entity.getProductId();
    if (productId != null) {
        stmt.bindLong(6, productId);
    }
    stmt.bindLong(7, entity.getShoppingListId());
}
 
Example 2
Project: FamilyBond   File: SMSDao.java   Source Code and License Vote up 6 votes
@Override
protected final void bindValues(SQLiteStatement stmt, SMS entity) {
    stmt.clearBindings();
 
    Long id = entity.getId();
    if (id != null) {
        stmt.bindLong(1, id);
    }
 
    String time = entity.getTime();
    if (time != null) {
        stmt.bindString(2, time);
    }
 
    String address = entity.getAddress();
    if (address != null) {
        stmt.bindString(3, address);
    }
 
    String content = entity.getContent();
    if (content != null) {
        stmt.bindString(4, content);
    }
    stmt.bindDouble(5, entity.getProbability());
}
 
Example 3
Project: GitHub   File: SqlInfo.java   Source Code and License Vote up 5 votes
public SQLiteStatement buildStatement(SQLiteDatabase database) {
    SQLiteStatement result = database.compileStatement(sql);
    if (bindArgs != null) {
        for (int i = 1; i < bindArgs.size() + 1; i++) {
            KeyValue kv = bindArgs.get(i - 1);
            Object value = ColumnUtils.convert2DbValueIfNeeded(kv.value);
            if (value == null) {
                result.bindNull(i);
            } else {
                ColumnConverter converter = ColumnConverterFactory.getColumnConverter(value.getClass());
                ColumnDbType type = converter.getColumnDbType();
                switch (type) {
                    case INTEGER:
                        result.bindLong(i, ((Number) value).longValue());
                        break;
                    case REAL:
                        result.bindDouble(i, ((Number) value).doubleValue());
                        break;
                    case TEXT:
                        result.bindString(i, value.toString());
                        break;
                    case BLOB:
                        result.bindBlob(i, (byte[]) value);
                        break;
                    default:
                        result.bindNull(i);
                        break;
                } // end switch
            }
        }
    }
    return result;
}
 
Example 4
Project: GitHub   File: SimpleEntityNotNullDao.java   Source Code and License Vote up 5 votes
@Override
protected final void bindValues(SQLiteStatement stmt, SimpleEntityNotNull entity) {
    stmt.clearBindings();
    stmt.bindLong(1, entity.getId());
    stmt.bindLong(2, entity.getSimpleBoolean() ? 1L: 0L);
    stmt.bindLong(3, entity.getSimpleByte());
    stmt.bindLong(4, entity.getSimpleShort());
    stmt.bindLong(5, entity.getSimpleInt());
    stmt.bindLong(6, entity.getSimpleLong());
    stmt.bindDouble(7, entity.getSimpleFloat());
    stmt.bindDouble(8, entity.getSimpleDouble());
    stmt.bindString(9, entity.getSimpleString());
    stmt.bindBlob(10, entity.getSimpleByteArray());
}
 
Example 5
Project: MapaDeIgarassuAdmin   File: DataBaseUtil.java   Source Code and License Vote up 5 votes
public void updateLocation(LocationModel locationModel) {
    SQLiteDatabase db = this.getWritableDatabase();
    SQLiteStatement stmt = db.compileStatement(Constants.UPDATE_TABLE_LOCATION);
    stmt.bindString(1, locationModel.getName());
    stmt.bindDouble(2, locationModel.getLongitude());
    stmt.bindDouble(3, locationModel.getLatitude());
    stmt.bindString(4, locationModel.getAddress());
    stmt.bindString(5, locationModel.getDescription());
    stmt.bindLong(6, locationModel.getId());
    stmt.execute();
}
 
Example 6
Project: pvdisplay   File: PvDataOperations.java   Source Code and License Vote up 5 votes
public void saveDaily(List<DailyPvDatum> dailyPvData) {
    SQLiteDatabase db = pvDataHelper.getWritableDatabase();

    db.beginTransaction();
    String sql = "REPLACE INTO " + PvDataContract.DailyPvData.TABLE_NAME +
            "(" + PvDataContract.DailyPvData.COLUMN_NAME_YEAR +
            "," + PvDataContract.DailyPvData.COLUMN_NAME_MONTH +
            "," + PvDataContract.DailyPvData.COLUMN_NAME_DAY +
            "," + PvDataContract.DailyPvData.COLUMN_NAME_ENERGY_GENERATED +
            "," + PvDataContract.DailyPvData.COLUMN_NAME_PEAK_POWER +
            "," + PvDataContract.DailyPvData.COLUMN_NAME_CONDITION +
            ") VALUES (?,?,?,?,?,?);";
    SQLiteStatement statement = db.compileStatement(sql);
    double maxEnergyGenerated = Double.MIN_VALUE;
    for (DailyPvDatum dailyPvDatum : dailyPvData) {
        statement.clearBindings();
        statement.bindLong(1, dailyPvDatum.getYear());
        statement.bindLong(2, dailyPvDatum.getMonth());
        statement.bindLong(3, dailyPvDatum.getDay());
        statement.bindDouble(4, dailyPvDatum.getEnergyGenerated());
        statement.bindDouble(5, dailyPvDatum.getPeakPower());
        statement.bindString(6, dailyPvDatum.getCondition());
        statement.execute();
        maxEnergyGenerated = Math.max(maxEnergyGenerated, dailyPvDatum.getEnergyGenerated());
    }
    db.setTransactionSuccessful();
    db.endTransaction();

    db.close();
    Log.d(TAG, "Saved " + dailyPvData.size() + " rows of daily PV data to database");

    RecordPvDatum recordPvDatum = loadRecord();
    if (maxEnergyGenerated > recordPvDatum.getDailyEnergyGenerated()) {
        recordPvDatum.setDailyEnergyGenerated(maxEnergyGenerated);
        saveRecord(recordPvDatum);
    }
}
 
Example 7
Project: pvdisplay   File: PvDataOperations.java   Source Code and License Vote up 5 votes
public void saveLive(List<LivePvDatum> livePvData) {
    SQLiteDatabase db = pvDataHelper.getWritableDatabase();

    db.beginTransaction();
    String sql = "REPLACE INTO " + PvDataContract.LivePvData.TABLE_NAME +
            "(" + PvDataContract.LivePvData.COLUMN_NAME_YEAR +
            "," + PvDataContract.LivePvData.COLUMN_NAME_MONTH +
            "," + PvDataContract.LivePvData.COLUMN_NAME_DAY +
            "," + PvDataContract.LivePvData.COLUMN_NAME_HOUR +
            "," + PvDataContract.LivePvData.COLUMN_NAME_MINUTE +
            "," + PvDataContract.LivePvData.COLUMN_NAME_ENERGY_GENERATION +
            "," + PvDataContract.LivePvData.COLUMN_NAME_POWER_GENERATION +
            ") VALUES (?,?,?,?,?,?,?);";
    SQLiteStatement statement = db.compileStatement(sql);
    double maxPowerGeneration = Double.MIN_VALUE;
    for (LivePvDatum livePvDatum : livePvData) {
        statement.clearBindings();
        statement.bindLong(1, livePvDatum.getYear());
        statement.bindLong(2, livePvDatum.getMonth());
        statement.bindLong(3, livePvDatum.getDay());
        statement.bindLong(4, livePvDatum.getHour());
        statement.bindLong(5, livePvDatum.getMinute());
        statement.bindDouble(6, livePvDatum.getEnergyGeneration());
        statement.bindDouble(7, livePvDatum.getPowerGeneration());
        statement.execute();
        maxPowerGeneration = Math.max(maxPowerGeneration, livePvDatum.getPowerGeneration());
    }
    db.setTransactionSuccessful();
    db.endTransaction();

    db.close();
    Log.d(TAG, "Saved " + livePvData.size() + " rows of live PV data to database");

    RecordPvDatum recordPvDatum = loadRecord();
    if (maxPowerGeneration > recordPvDatum.getLivePowerGeneration()) {
        recordPvDatum.setLivePowerGeneration(maxPowerGeneration);
        saveRecord(recordPvDatum);
    }
}
 
Example 8
Project: pvdisplay   File: PvDataOperations.java   Source Code and License Vote up 5 votes
public void saveMonthly(List<MonthlyPvDatum> monthlyPvData) {
    SQLiteDatabase db = pvDataHelper.getWritableDatabase();

    db.beginTransaction();
    String sql = "REPLACE INTO " + PvDataContract.MonthlyPvData.TABLE_NAME +
            "(" + PvDataContract.MonthlyPvData.COLUMN_NAME_YEAR +
            "," + PvDataContract.MonthlyPvData.COLUMN_NAME_MONTH +
            "," + PvDataContract.MonthlyPvData.COLUMN_NAME_ENERGY_GENERATED +
            ") VALUES (?,?,?);";
    SQLiteStatement statement = db.compileStatement(sql);
    double maxEnergyGenerated = Double.MIN_VALUE;
    for (MonthlyPvDatum monthlyPvDatum : monthlyPvData) {
        statement.clearBindings();
        statement.bindLong(1, monthlyPvDatum.getYear());
        statement.bindLong(2, monthlyPvDatum.getMonth());
        statement.bindDouble(3, monthlyPvDatum.getEnergyGenerated());
        statement.execute();
        maxEnergyGenerated = Math.max(maxEnergyGenerated, monthlyPvDatum.getEnergyGenerated());
    }
    db.setTransactionSuccessful();
    db.endTransaction();

    db.close();
    Log.d(TAG, "Saved " + monthlyPvData.size() + " rows of monthly PV data to database");

    RecordPvDatum recordPvDatum = loadRecord();
    if (maxEnergyGenerated > recordPvDatum.getMonthlyEnergyGenerated()) {
        recordPvDatum.setMonthlyEnergyGenerated(maxEnergyGenerated);
        saveRecord(recordPvDatum);
    }
}
 
Example 9
Project: pvdisplay   File: PvDataOperations.java   Source Code and License Vote up 5 votes
public void saveYearly(List<YearlyPvDatum> yearlyPvData) {
    SQLiteDatabase db = pvDataHelper.getWritableDatabase();

    db.beginTransaction();
    String sql = "REPLACE INTO " + PvDataContract.YearlyPvData.TABLE_NAME +
            "(" + PvDataContract.YearlyPvData.COLUMN_NAME_YEAR +
            "," + PvDataContract.YearlyPvData.COLUMN_NAME_ENERGY_GENERATED +
            ") VALUES (?,?);";
    SQLiteStatement statement = db.compileStatement(sql);
    double maxEnergyGenerated = Double.MIN_VALUE;
    for (YearlyPvDatum yearlyPvDatum : yearlyPvData) {
        statement.clearBindings();
        statement.bindLong(1, yearlyPvDatum.getYear());
        statement.bindDouble(2, yearlyPvDatum.getEnergyGenerated());
        statement.execute();
        maxEnergyGenerated = Math.max(maxEnergyGenerated, yearlyPvDatum.getEnergyGenerated());
    }
    db.setTransactionSuccessful();
    db.endTransaction();

    db.close();
    Log.d(TAG, "Saved " + yearlyPvData.size() + " rows of yearly PV data to database");

    RecordPvDatum recordPvDatum = loadRecord();
    if (maxEnergyGenerated > recordPvDatum.getYearlyEnergyGenerated()) {
        recordPvDatum.setYearlyEnergyGenerated(maxEnergyGenerated);
        saveRecord(recordPvDatum);
    }
}
 
Example 10
Project: MapaDeIgarassu   File: DataBaseUtil.java   Source Code and License Vote up 5 votes
public void updateLocation(LocationModel locationModel) {
    SQLiteDatabase db = this.getWritableDatabase();
    SQLiteStatement stmt = db.compileStatement(Constants.UPDATE_TABLE_LOCATION);
    stmt.bindString(1, locationModel.getName());
    stmt.bindDouble(2, locationModel.getLongitude());
    stmt.bindDouble(3, locationModel.getLatitude());
    stmt.bindString(4, locationModel.getAddress());
    stmt.bindString(5, locationModel.getDescription());
    stmt.bindLong(6, locationModel.getId());
    stmt.execute();
}
 
Example 11
Project: Shopping_List   File: StatisticDao.java   Source Code and License Vote up 5 votes
@Override
protected final void bindValues(SQLiteStatement stmt, Statistic entity) {
    stmt.clearBindings();
 
    Long id = entity.getId();
    if (id != null) {
        stmt.bindLong(1, id);
    }
    stmt.bindString(2, entity.getName());
    stmt.bindDouble(3, entity.getQuantity());
    stmt.bindDouble(4, entity.getTotalCost());
    stmt.bindLong(5, entity.getUnit() ? 1L: 0L);
    stmt.bindLong(6, entity.getDate());
}
 
Example 12
Project: Shopping_List   File: ProductDao.java   Source Code and License Vote up 5 votes
@Override
protected final void bindValues(SQLiteStatement stmt, Product entity) {
    stmt.clearBindings();
 
    Long id = entity.getId();
    if (id != null) {
        stmt.bindLong(1, id);
    }
    stmt.bindString(2, entity.getName());
    stmt.bindDouble(3, entity.getCost());
}
 
Example 13
Project: GitHub   File: SimpleEntityDao.java   Source Code and License Vote up 4 votes
@Override
protected final void bindValues(SQLiteStatement stmt, SimpleEntity entity) {
    stmt.clearBindings();
 
    Long id = entity.getId();
    if (id != null) {
        stmt.bindLong(1, id);
    }
 
    Boolean simpleBoolean = entity.getSimpleBoolean();
    if (simpleBoolean != null) {
        stmt.bindLong(2, simpleBoolean ? 1L: 0L);
    }
 
    Byte simpleByte = entity.getSimpleByte();
    if (simpleByte != null) {
        stmt.bindLong(3, simpleByte);
    }
 
    Short simpleShort = entity.getSimpleShort();
    if (simpleShort != null) {
        stmt.bindLong(4, simpleShort);
    }
 
    Integer simpleInt = entity.getSimpleInt();
    if (simpleInt != null) {
        stmt.bindLong(5, simpleInt);
    }
 
    Long simpleLong = entity.getSimpleLong();
    if (simpleLong != null) {
        stmt.bindLong(6, simpleLong);
    }
 
    Float simpleFloat = entity.getSimpleFloat();
    if (simpleFloat != null) {
        stmt.bindDouble(7, simpleFloat);
    }
 
    Double simpleDouble = entity.getSimpleDouble();
    if (simpleDouble != null) {
        stmt.bindDouble(8, simpleDouble);
    }
 
    String simpleString = entity.getSimpleString();
    if (simpleString != null) {
        stmt.bindString(9, simpleString);
    }
 
    byte[] simpleByteArray = entity.getSimpleByteArray();
    if (simpleByteArray != null) {
        stmt.bindBlob(10, simpleByteArray);
    }
}
 
Example 14
Project: SQLite-Performance   File: SQLiteStatementTestCase.java   Source Code and License Vote up 4 votes
@Override
public Metrics runCase() {
    mDbHelper = new DbHelper(App.getInstance(), getClass().getName());
    Metrics result = new Metrics(getClass().getSimpleName()+" ("+mInsertions+" insertions)", mTestSizeIndex);
    SQLiteDatabase db = mDbHelper.getWritableDatabase();

    Charset ascii = Charset.forName("US-ASCII");

    byte[] titleByteArry = new byte[50];
    byte[] urlByteArray = new byte[100];
    byte[] lyricsByteArray = new byte[2000];
    byte[] aboutByteArray = new byte[2000];

    result.started();
    db.beginTransaction();
    SQLiteStatement stmt = db.compileStatement("INSERT INTO tracks (id, title, band_id, duration, url, lyrics, about, release_date, mod_date) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)");
    for (int i = 0; i < mInsertions; i++) {
        mRandom.nextBytes(titleByteArry);
        mRandom.nextBytes(urlByteArray);
        mRandom.nextBytes(lyricsByteArray);
        mRandom.nextBytes(aboutByteArray);

        stmt.bindLong(1, i);
        stmt.bindString(2, new String(titleByteArry, ascii));
        stmt.bindLong(3, mRandom.nextInt());
        stmt.bindDouble(4, mRandom.nextDouble());
        stmt.bindString(5, new String(urlByteArray, ascii));
        stmt.bindString(6, new String(lyricsByteArray, ascii));
        stmt.bindString(7, new String(aboutByteArray, ascii));
        stmt.bindLong(8, mRandom.nextLong());
        stmt.bindLong(9, mRandom.nextLong());

        stmt.executeInsert();
        stmt.clearBindings();
    }
    db.setTransactionSuccessful();
    db.endTransaction();
    result.finished();

    return result;
}
 
Example 15
Project: SQLite-Performance   File: BatchedSQLiteStatementTestCase.java   Source Code and License Vote up 4 votes
private void doInsertions(SQLiteDatabase db, int total, Map<Integer, SQLiteStatement> statementCache, byte[] titleByteArray, byte[] urlByteArray, byte[] lyricsByteArray, byte[] aboutByteArray) {
    // divide 999 by 9 since that's the # of fields in our table
    if (total > 999/9) {
        doInsertions(db, total-999/9, statementCache, titleByteArray, urlByteArray, lyricsByteArray, aboutByteArray);
        total = 999/9;
    }
    SQLiteStatement stmt;
    if (statementCache.containsKey(total)) {
        stmt = statementCache.get(total);
    } else {
        StringBuilder valueBuilder = new StringBuilder();
        for (int i = 0; i < total; i++) {
            if (i > 0) {
                valueBuilder.append(", ");
            }
            valueBuilder.append("(?, ?, ?, ?, ?, ?, ?, ?, ?)");
        }
        stmt = db.compileStatement("INSERT INTO tracks (id, title, band_id, duration, url, lyrics, about, release_date, mod_date) VALUES "+valueBuilder.toString());
        statementCache.put(total, stmt);
    }

    Charset ascii = Charset.forName("US-ASCII");
    for (int i = 0; i < total; i++) {
        mRandom.nextBytes(titleByteArray);
        mRandom.nextBytes(urlByteArray);
        mRandom.nextBytes(lyricsByteArray);
        mRandom.nextBytes(aboutByteArray);

        stmt.bindLong(9*i+1, mInsertId++);
        stmt.bindString(9*i+2, new String(titleByteArray, ascii));
        stmt.bindLong(9*i+3, mRandom.nextInt());
        stmt.bindDouble(9*i+4, mRandom.nextDouble());
        stmt.bindString(9*i+5, new String(urlByteArray, ascii));
        stmt.bindString(9*i+6, new String(lyricsByteArray, ascii));
        stmt.bindString(9*i+7, new String(aboutByteArray, ascii));
        stmt.bindLong(9*i+8, mRandom.nextLong());
        stmt.bindLong(9*i+9, mRandom.nextLong());
    }

    stmt.executeInsert();
    stmt.clearBindings();
}