Java 类android.database.sqlite.SQLiteStatement 实例源码

项目:sctalk    文件:UserDao.java   
/** @inheritdoc */
@Override
protected void bindValues(SQLiteStatement stmt, UserEntity entity) {
    stmt.clearBindings();

    Long id = entity.getId();
    if (id != null) {
        stmt.bindLong(1, id);
    }
    stmt.bindLong(2, entity.getPeerId());
    stmt.bindLong(3, entity.getGender());
    stmt.bindString(4, entity.getMainName());
    stmt.bindString(5, entity.getPinyinName());
    stmt.bindString(6, entity.getRealName());
    stmt.bindString(7, entity.getAvatar());
    stmt.bindString(8, entity.getPhone());
    stmt.bindString(9, entity.getEmail());
    stmt.bindLong(10, entity.getDepartmentId());
    stmt.bindLong(11, entity.getStatus());
    stmt.bindLong(12, entity.getCreated());
    stmt.bindLong(13, entity.getUpdated());
}
项目:sqlbrite-sqlcipher    文件:BriteDatabaseTest.java   
@Test public void executeInsertWithArgsThrowsAndDoesNotTrigger() {
  SQLiteStatement statement = real.compileStatement("INSERT INTO " + TABLE_EMPLOYEE + " ("
      + NAME + ", " + USERNAME + ") VALUES (?, ?)");
  statement.bindString(1, "Alice Aliison");
  statement.bindString(2, "alice");

  db.createQuery(TABLE_EMPLOYEE, SELECT_EMPLOYEES)
      .skip(1) // Skip initial
      .subscribe(o);

  try {
    db.executeInsert(TABLE_EMPLOYEE, statement);
    fail();
  } catch (SQLException ignored) {
  }
  o.assertNoMoreEvents();
}
项目:healthvault-java-sdk    文件:ViewProvider.java   
public Uri insert(Uri uri, ContentValues values) {
    SQLiteDatabase sqlDb = dbHelper.getWritableDatabase();

    List<String> segments = uri.getPathSegments();
    String recordId = segments.get(1);
    String name = segments.get(3);

       String insertView = "Insert or replace into views (record_id, name, query, date_synced) values(?,?,?,?)";

       SQLiteStatement insertViewStmt = sqlDb.compileStatement(insertView);

       insertViewStmt.bindString(1, recordId);
       insertViewStmt.bindString(2, name);
       insertViewStmt.bindString(3, values.getAsString("query"));
       insertViewStmt.bindString(4, values.getAsString("date_synced"));
       insertViewStmt.execute();

       getContext()
               .getContentResolver()
               .notifyChange(uri, null);

       return uri;
}
项目:GitHub    文件:DbManagerImpl.java   
@Override
public int executeUpdateDelete(SqlInfo sqlInfo) throws DbException {
    SQLiteStatement statement = null;
    try {
        statement = sqlInfo.buildStatement(database);
        return statement.executeUpdateDelete();
    } catch (Throwable e) {
        throw new DbException(e);
    } finally {
        if (statement != null) {
            try {
                statement.releaseReference();
            } catch (Throwable ex) {
                LogUtil.e(ex.getMessage(), ex);
            }
        }
    }
}
项目:FamilyBond    文件:BpmDao.java   
@Override
protected final void bindValues(SQLiteStatement stmt, Bpm entity) {
    stmt.clearBindings();

    Long id = entity.getId();
    if (id != null) {
        stmt.bindLong(1, id);
    }

    String mBpm = entity.getMBpm();
    if (mBpm != null) {
        stmt.bindString(2, mBpm);
    }

    String mTime = entity.getMTime();
    if (mTime != null) {
        stmt.bindString(3, mTime);
    }

    String mDescription = entity.getMDescription();
    if (mDescription != null) {
        stmt.bindString(4, mDescription);
    }
}
项目:GitHub    文件:ToManyTargetEntityDao.java   
@Override
protected final void bindValues(SQLiteStatement stmt, ToManyTargetEntity entity) {
    stmt.clearBindings();

    Long toManyId = entity.getToManyId();
    if (toManyId != null) {
        stmt.bindLong(1, toManyId);
    }

    Long toManyIdDesc = entity.getToManyIdDesc();
    if (toManyIdDesc != null) {
        stmt.bindLong(2, toManyIdDesc);
    }

    Long id = entity.getId();
    if (id != null) {
        stmt.bindLong(3, id);
    }

    String targetJoinProperty = entity.getTargetJoinProperty();
    if (targetJoinProperty != null) {
        stmt.bindString(4, targetJoinProperty);
    }
}
项目:sqlbrite-sqlcipher    文件:BriteDatabaseTest.java   
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.HONEYCOMB)
@Test public void executeUpdateDeleteThrowsAndDoesNotTrigger() {
  SQLiteStatement statement = real.compileStatement(
      "UPDATE " + TABLE_EMPLOYEE + " SET " + USERNAME + " = 'alice'");

  db.createQuery(TABLE_EMPLOYEE, SELECT_EMPLOYEES)
      .skip(1) // Skip initial
      .subscribe(o);

  try {
    db.executeUpdateDelete(TABLE_EMPLOYEE, statement);
    fail();
  } catch (SQLException ignored) {
  }
  o.assertNoMoreEvents();
}
项目:sqlbrite-sqlcipher    文件:BriteDatabaseTest.java   
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.HONEYCOMB)
@Test public void executeUpdateDeleteAndTriggerWithNoTables() {
  SQLiteStatement statement = real.compileStatement(
      "UPDATE " + TABLE_EMPLOYEE + " SET " + NAME + " = 'Zach'");

  db.createQuery(TABLE_EMPLOYEE, SELECT_EMPLOYEES).subscribe(o);
  o.assertCursor()
      .hasRow("alice", "Alice Allison")
      .hasRow("bob", "Bob Bobberson")
      .hasRow("eve", "Eve Evenson")
      .isExhausted();

  db.executeUpdateDelete(Collections.<String>emptySet(), statement);

  o.assertNoMoreEvents();
}
项目:MeiLa_GNN    文件:UserDao.java   
@Override
protected final void bindValues(SQLiteStatement stmt, User entity) {
    stmt.clearBindings();

    Long id = entity.getId();
    if (id != null) {
        stmt.bindLong(1, id);
    }

    String phone = entity.getPhone();
    if (phone != null) {
        stmt.bindString(2, phone);
    }

    String psw = entity.getPsw();
    if (psw != null) {
        stmt.bindString(3, psw);
    }
}
项目:sctalk    文件:SessionDao.java   
/** @inheritdoc */
@Override
protected void bindValues(SQLiteStatement stmt, SessionEntity entity) {
    stmt.clearBindings();

    Long id = entity.getId();
    if (id != null) {
        stmt.bindLong(1, id);
    }
    stmt.bindString(2, entity.getSessionKey());
    stmt.bindLong(3, entity.getPeerId());
    stmt.bindLong(4, entity.getPeerType());
    stmt.bindLong(5, entity.getLatestMsgType());
    stmt.bindLong(6, entity.getLatestMsgId());
    stmt.bindString(7, entity.getLatestMsgData());
    stmt.bindLong(8, entity.getTalkId());
    stmt.bindLong(9, entity.getCreated());
    stmt.bindLong(10, entity.getUpdated());
}
项目:Cable-Android    文件:SmsDatabase.java   
SQLiteStatement createInsertStatement(SQLiteDatabase database) {
  return database.compileStatement("INSERT INTO " + TABLE_NAME + " (" + ADDRESS + ", " +
                                                                    PERSON + ", " +
                                                                    DATE_SENT + ", " +
                                                                    DATE_RECEIVED  + ", " +
                                                                    PROTOCOL + ", " +
                                                                    READ + ", " +
                                                                    STATUS + ", " +
                                                                    TYPE + ", " +
                                                                    REPLY_PATH_PRESENT + ", " +
                                                                    SUBJECT + ", " +
                                                                    BODY + ", " +
                                                                    SERVICE_CENTER +
                                                                    ", " + THREAD_ID + ") " +
                                   " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
}
项目:LookWeather    文件:CountyDao.java   
@Override
protected final void bindValues(SQLiteStatement stmt, County entity) {
    stmt.clearBindings();

    Long id = entity.getId();
    if (id != null) {
        stmt.bindLong(1, id);
    }

    String countyName = entity.getCountyName();
    if (countyName != null) {
        stmt.bindString(2, countyName);
    }

    String weatherId = entity.getWeatherId();
    if (weatherId != null) {
        stmt.bindString(3, weatherId);
    }
    stmt.bindLong(4, entity.getCityId());
}
项目:sqlbrite-sqlcipher    文件:BriteDatabaseTest.java   
@Test public void executeInsertThrowsAndDoesNotTrigger() {
  SQLiteStatement statement = real.compileStatement("INSERT INTO " + TABLE_EMPLOYEE + " ("
      + NAME + ", " + USERNAME + ") "
      + "VALUES ('Alice Allison', 'alice')");

  db.createQuery(TABLE_EMPLOYEE, SELECT_EMPLOYEES)
      .skip(1) // Skip initial
      .subscribe(o);

  try {
    db.executeInsert(TABLE_EMPLOYEE, statement);
    fail();
  } catch (SQLException ignored) {
  }
  o.assertNoMoreEvents();
}
项目:buildAPKsApps    文件:DataManager.java   
public int createItem(int list_id, String label)
{
    Log.v(L.TAG, "DataManager.createItem(): Insert item " + label);

    SQLiteDatabase db = helper.getWritableDatabase();
    SQLiteStatement stmt = db.compileStatement("insert into items (list_id,label,active) values (?,?,?)");        
    stmt.bindLong(1, list_id);
    stmt.bindString(2, label);
    stmt.bindLong(3, 1);
    long id = stmt.executeInsert();
    stmt.close();
    db.close();

    Log.d(L.TAG, "DataManager.createItem(): Inserted item and got id " + id);
    if(id == -1)
    {
        Log.e(L.TAG, "DataManager.createItem(): Attempt to insert item failed. Got " + id + " from executeInsert()");
    }
    return (int)id;
}
项目:OftenPorter    文件:SqliteHandle.java   
private void bind(int index, Object value, SQLiteStatement sQLiteStatement)
{
    if (value == null)
    {
        sQLiteStatement.bindNull(index);
    } else
    {
        int i = Arrays.binarySearch(TYPES_ADD, TypeUtil.Type.forSearch(value.getClass()));
        if (i >= 0)
        {
            TypeUtil.Type<TypeUtil.StatementObj> type = TYPES_MULTI_ADD[i];
            type.put(null, value, new TypeUtil.StatementObj(index, sQLiteStatement));
        } else
        {
            throw new DBException("unknown type of " + value.getClass() + " for sqlite");
        }

    }
}
项目:OftenPorter    文件:SqliteHandle.java   
@Override
public int del(Condition query) throws DBException
{
    SQLiteStatement statement = null;
    try
    {
        SqlUtil.WhereSQL whereSQL = SqlUtil.toDelete(tableName, checkCondition(query), true);

        statement = db.compileStatement(whereSQL.sql);
        Object[] args = whereSQL.args;
        for (int i = 0; i < args.length; i++)
        {
            bind(i + 1, args[i], statement);
        }

        return statement.executeUpdateDelete();
    } catch (Exception e)
    {
        throw new DBException(e);
    } finally
    {
        close(statement);
    }

}
项目:wallpaperboard    文件:Database.java   
public void deleteCategories(@NonNull List<Category> categories) {
    if (!openDatabase()) {
        LogUtil.e("Database error: deleteCategories() failed to open database");
        return;
    }

    String query = "DELETE FROM " +TABLE_CATEGORIES+ " WHERE " +KEY_NAME+ " = ?";
    SQLiteStatement statement = mDatabase.get().mSQLiteDatabase.compileStatement(query);
    mDatabase.get().mSQLiteDatabase.beginTransaction();

    for (Category category : categories) {
        statement.clearBindings();
        statement.bindString(1, category.getName());
        statement.execute();
    }

    mDatabase.get().mSQLiteDatabase.setTransactionSuccessful();
    mDatabase.get().mSQLiteDatabase.endTransaction();
}
项目:AndroidBackendlessChat    文件:ContactLinkDao.java   
/** @inheritdoc */
@Override
protected void bindValues(SQLiteStatement stmt, ContactLink entity) {
    stmt.clearBindings();

    Long id = entity.getId();
    if (id != null) {
        stmt.bindLong(1, id);
    }

    Long BUserDaoId = entity.getBUserDaoId();
    if (BUserDaoId != null) {
        stmt.bindLong(2, BUserDaoId);
    }

    Long linkOwnerBUserDaoId = entity.getLinkOwnerBUserDaoId();
    if (linkOwnerBUserDaoId != null) {
        stmt.bindLong(3, linkOwnerBUserDaoId);
    }
}
项目:AndroidBackendlessChat    文件:UserThreadLinkDao.java   
/** @inheritdoc */
@Override
protected void bindValues(SQLiteStatement stmt, UserThreadLink entity) {
    stmt.clearBindings();

    Long id = entity.getId();
    if (id != null) {
        stmt.bindLong(1, id);
    }

    Long BUserDaoId = entity.getBUserDaoId();
    if (BUserDaoId != null) {
        stmt.bindLong(2, BUserDaoId);
    }

    Long BThreadDaoId = entity.getBThreadDaoId();
    if (BThreadDaoId != null) {
        stmt.bindLong(3, BThreadDaoId);
    }
}
项目:AndroidBackendlessChat    文件:FollowerLinkDao.java   
/** @inheritdoc */
@Override
protected void bindValues(SQLiteStatement stmt, FollowerLink entity) {
    stmt.clearBindings();

    Long id = entity.getId();
    if (id != null) {
        stmt.bindLong(1, id);
    }

    Integer type = entity.getType();
    if (type != null) {
        stmt.bindLong(2, type);
    }

    Long BUserDaoId = entity.getBUserDaoId();
    if (BUserDaoId != null) {
        stmt.bindLong(3, BUserDaoId);
    }

    Long linkOwnerBUserDaoId = entity.getLinkOwnerBUserDaoId();
    if (linkOwnerBUserDaoId != null) {
        stmt.bindLong(4, linkOwnerBUserDaoId);
    }
}
项目:openlocate-android    文件:LocationTable.java   
static void addAll(SQLiteDatabase database, List<OpenLocateLocation> locations) {
    if (database == null || locations == null || locations.isEmpty()) {
        return;
    }

    SQLiteStatement statement = database.compileStatement(BULK_INSERT_LOCATION);

    database.beginTransaction();
    for (OpenLocateLocation location : locations) {
        statement.clearBindings();
        statement.bindString(COLUMN_LOCATION_INDEX, location.getJson().toString());
        statement.bindLong(2, location.getCreated().getTime());
        statement.execute();
    }

    database.setTransactionSuccessful();
    database.endTransaction();
}
项目:weex-3d-map    文件:DefaultWXStorage.java   
private long performGetLength() {
    SQLiteDatabase database = mDatabaseSupplier.getDatabase();
    if (database == null) {
        return 0;
    }

    String sql = "SELECT count(" + WXSQLiteOpenHelper.COLUMN_KEY + ") FROM " + WXSQLiteOpenHelper.TABLE_STORAGE;
    SQLiteStatement statement = null;
    try {
        statement = database.compileStatement(sql);
        return statement.simpleQueryForLong();
    } catch (Exception e) {
        WXLogUtils.e(WXSQLiteOpenHelper.TAG_STORAGE, "DefaultWXStorage occurred an exception when execute getLength:" + e.getMessage());
        return 0;
    } finally {
        if(statement != null) {
            statement.close();
        }
    }
}
项目:Expert-Android-Programming    文件:PhotoItemDao.java   
/** @inheritdoc */
@Override
protected void bindValues(SQLiteStatement stmt, PhotoItem entity) {
     stmt.clearBindings();

     int c = 0;         
     Long id = entity.getId();
     ++c;
     if (id != null) {
         stmt.bindLong(c, id);
     }
    ++c; stmt.bindString(c, handleNull(entity.get_id()));
    ++c; stmt.bindString(c, handleNull(entity.getName()));
    ++c; stmt.bindString(c, handleNull(entity.getPath()));
    ++c; stmt.bindString(c, handleNull(entity.getTag()));
    ++c; stmt.bindLong(c, entity.isStatus()?1:0);
}
项目:sqlbrite-sqlcipher    文件:BriteDatabaseTest.java   
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.HONEYCOMB)
@Test public void executeUpdateDeleteAndDontTrigger() {
  SQLiteStatement statement = real.compileStatement(""
      + "UPDATE " + TABLE_EMPLOYEE
      + " SET " + NAME + " = 'Zach'"
      + " WHERE " + NAME + " = 'Rob'");

  db.createQuery(TABLE_EMPLOYEE, SELECT_EMPLOYEES).subscribe(o);
  o.assertCursor()
      .hasRow("alice", "Alice Allison")
      .hasRow("bob", "Bob Bobberson")
      .hasRow("eve", "Eve Evenson")
      .isExhausted();

  db.executeUpdateDelete(TABLE_EMPLOYEE, statement);
  o.assertNoMoreEvents();
}
项目:chat-sdk-android-push-firebase    文件:BLinkedAccountDao.java   
/** @inheritdoc */
@Override
protected void bindValues(SQLiteStatement stmt, BLinkedAccount entity) {
    stmt.clearBindings();

    Long id = entity.getId();
    if (id != null) {
        stmt.bindLong(1, id);
    }

    String Token = entity.getToken();
    if (Token != null) {
        stmt.bindString(2, Token);
    }

    Integer type = entity.getType();
    if (type != null) {
        stmt.bindLong(3, type);
    }

    Long BUserDaoId = entity.getBUserDaoId();
    if (BUserDaoId != null) {
        stmt.bindLong(4, BUserDaoId);
    }
}
项目:GhostContactBook    文件:UserBeanDao.java   
@Override
protected final void bindValues(SQLiteStatement stmt, UserBean entity) {
    stmt.clearBindings();

    Long id = entity.getId();
    if (id != null) {
        stmt.bindLong(1, id);
    }
    stmt.bindString(2, entity.getTitle());
    stmt.bindString(3, entity.getFirst());
    stmt.bindString(4, entity.getLast());
    stmt.bindString(5, entity.getEmail());
    stmt.bindString(6, entity.getDob());
    stmt.bindString(7, entity.getPhone());
    stmt.bindString(8, entity.getCell());
    stmt.bindString(9, entity.getThumbnailPic());
    stmt.bindString(10, entity.getMediumPic());
    stmt.bindString(11, entity.getLargePic());
}
项目:rongyunDemo    文件:BlackListDao.java   
/** @inheritdoc */
@Override
protected void bindValues(SQLiteStatement stmt, BlackList entity) {
    stmt.clearBindings();
    stmt.bindString(1, entity.getUserId());

    String status = entity.getStatus();
    if (status != null) {
        stmt.bindString(2, status);
    }

    Long timestamp = entity.getTimestamp();
    if (timestamp != null) {
        stmt.bindLong(3, timestamp);
    }
}
项目:OpenHub    文件:LocalUserDao.java   
@Override
protected final void bindValues(SQLiteStatement stmt, LocalUser entity) {
    stmt.clearBindings();
    stmt.bindString(1, entity.getLogin());

    String name = entity.getName();
    if (name != null) {
        stmt.bindString(2, name);
    }

    String avatarUrl = entity.getAvatarUrl();
    if (avatarUrl != null) {
        stmt.bindString(3, avatarUrl);
    }

    Integer followers = entity.getFollowers();
    if (followers != null) {
        stmt.bindLong(4, followers);
    }

    Integer following = entity.getFollowing();
    if (following != null) {
        stmt.bindLong(5, following);
    }
}
项目:buildAPKsApps    文件:DataManager.java   
public void updateItemStarness(int itemId, boolean star)
{
    Log.d(L.TAG, "Setting star property of  " + itemId + " to " + star);

    SQLiteDatabase db = helper.getWritableDatabase();
    SQLiteStatement stmt = db.compileStatement("update items set star=? where id=?");        
    stmt.bindLong(1, star?1:0);
    stmt.bindLong(2, itemId);
    stmt.execute();
    stmt.close();
    db.close();
}
项目:Cable-Android    文件:SmsMigrator.java   
private static void addTranslatedTypeToStatement(SQLiteStatement statement, Cursor cursor,
                                                 int index, String key)
{
  int columnIndex = cursor.getColumnIndexOrThrow(key);

  if (cursor.isNull(columnIndex)) {
    statement.bindLong(index, SmsDatabase.Types.BASE_INBOX_TYPE | SmsDatabase.Types.ENCRYPTION_SYMMETRIC_BIT);
  } else {
    long theirType = cursor.getLong(columnIndex);
    statement.bindLong(index, SmsDatabase.Types.translateFromSystemBaseType(theirType) | SmsDatabase.Types.ENCRYPTION_SYMMETRIC_BIT);
  }
}
项目:GitHub    文件:AbstractDao.java   
protected void updateInsideSynchronized(T entity, SQLiteStatement stmt, boolean lock) {
    // To do? Check if it's worth not to bind PKs here (performance).
    bindValues(stmt, entity);
    int index = config.allColumns.length + 1;
    K key = getKey(entity);
    if (key instanceof Long) {
        stmt.bindLong(index, (Long) key);
    } else if (key == null) {
        throw new DaoException("Cannot update entity without key - was it inserted before?");
    } else {
        stmt.bindString(index, key.toString());
    }
    stmt.execute();
    attachEntity(key, entity, lock);
}
项目:Android-SQLite-Master-Project    文件:UserDaoByBuilders.java   
private static void insertUser(@NonNull SQLiteStatement statement, @NonNull User user) {
    InsertSqlStatementBinder
            .startBind(statement)
            .bindLong(user.getId())
            .bindString(user.getName())
            .bindStringEmptySafe(user.getSecondName())
            .bindString(user.getEmail())
            .bindDate(user.getBirthday())
            .executeInsert();
}
项目:Bee-Analyzer    文件:MapsActivity.java   
public void InsertToSqlite(String imei, String latitude, String longitude, String out)
{
    SQLiteStatement statement = localdb.compileStatement("INSERT INTO position VALUES(?,?,?,datetime(),?)");
    statement.bindString(1, imei);
    statement.bindString(2, latitude);
    statement.bindString(3, longitude);
    statement.bindString(4, out);
    statement.executeInsert();
    statement.close();
}
项目:GitHub    文件:CustomTypeEntityDao.java   
@Override
protected final void bindValues(SQLiteStatement stmt, CustomTypeEntity entity) {
    stmt.clearBindings();

    Long id = entity.getId();
    if (id != null) {
        stmt.bindLong(1, id);
    }

    MyTimestamp myCustomTimestamp = entity.getMyCustomTimestamp();
    if (myCustomTimestamp != null) {
        stmt.bindLong(2, myCustomTimestampConverter.convertToDatabaseValue(myCustomTimestamp));
    }
}
项目:GitHub    文件:ExtendsImplementsEntityDao.java   
@Override
protected final void bindValues(SQLiteStatement stmt, ExtendsImplementsEntity entity) {
    stmt.clearBindings();

    Long id = entity.getId();
    if (id != null) {
        stmt.bindLong(1, id);
    }

    String text = entity.getText();
    if (text != null) {
        stmt.bindString(2, text);
    }
}
项目:GitHub    文件:StringKeyValueEntityDao.java   
@Override
protected final void bindValues(SQLiteStatement stmt, StringKeyValueEntity entity) {
    stmt.clearBindings();

    String key = entity.getKey();
    if (key != null) {
        stmt.bindString(1, key);
    }

    String value = entity.getValue();
    if (value != null) {
        stmt.bindString(2, value);
    }
}
项目:Expert-Android-Programming    文件:RestaurantImageDao.java   
/** @inheritdoc */
@Override
protected void bindValues(SQLiteStatement stmt, RestaurantImage entity) {
     stmt.clearBindings();

     int c = 0;         
     Long id = entity.getId();
     ++c;
     if (id != null) {
         stmt.bindLong(c, id);
     }
    ++c; stmt.bindString(c, handleNull(entity.getRestaurant_id()));
    ++c; stmt.bindString(c, handleNull(entity.getRestaurant_branch_id()));
    ++c; stmt.bindString(c, handleNull(entity.getImage()));
}
项目:pvdisplay    文件:PvDataOperations.java   
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);
    }
}
项目:unity-obb-downloader    文件:DownloadsDB.java   
public long getIDByIndex(int index) {
    SQLiteStatement downloadByIndex = getDownloadByIndexStatement();
    downloadByIndex.clearBindings();
    downloadByIndex.bindLong(1, index);
    try {
        return downloadByIndex.simpleQueryForLong();
    } catch (SQLiteDoneException e) {
        return -1;
    }
}
项目:SQLite-Performance    文件:DbHelper.java   
private void createFiles(SQLiteDatabase db) {
    mFileNames = new String[mFiles];
    byte[] rawData = new byte[mFileSize+mFiles];
    Random random = new Random();
    random.nextBytes(rawData);

    ByteArrayOutputStream[] streams = new ByteArrayOutputStream[mFiles];
    for (int i = 0; i < mFiles; i++) {
        streams[i] = new ByteArrayOutputStream(mFileSize);
        streams[i].write(rawData, i, mFileSize);
        mFileNames[i] = String.valueOf(i);
    }

    SQLiteStatement insert = db.compileStatement("INSERT INTO files (filename, data) VALUES (?, ?)");
    for (int i = 0; i < mFiles; i++) {
        insert.bindString(1, mFileNames[i]);
        insert.bindBlob(2, streams[i].toByteArray());

        insert.execute();
    }
}