Java Code Examples for android.database.sqlite.SQLiteStatement

The following are top voted examples for showing how to use android.database.sqlite.SQLiteStatement. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: sctalk   File: UserDao.java   Source Code and License 8 votes vote down vote up
/** @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());
}
 
Example 2
Project: sqlbrite-sqlcipher   File: BriteDatabaseTest.java   Source Code and License 6 votes vote down vote up
@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();
}
 
Example 3
Project: healthvault-java-sdk   File: ViewProvider.java   Source Code and License 6 votes vote down vote up
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;
}
 
Example 4
Project: GitHub   File: DbManagerImpl.java   Source Code and License 6 votes vote down vote up
@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);
            }
        }
    }
}
 
Example 5
Project: FamilyBond   File: BpmDao.java   Source Code and License 6 votes vote down vote up
@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);
    }
}
 
Example 6
Project: GitHub   File: ToManyTargetEntityDao.java   Source Code and License 6 votes vote down vote up
@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);
    }
}
 
Example 7
Project: sqlbrite-sqlcipher   File: BriteDatabaseTest.java   Source Code and License 6 votes vote down vote up
@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();
}
 
Example 8
Project: sqlbrite-sqlcipher   File: BriteDatabaseTest.java   Source Code and License 6 votes vote down vote up
@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();
}
 
Example 9
Project: MeiLa_GNN   File: UserDao.java   Source Code and License 6 votes vote down vote up
@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);
    }
}
 
Example 10
Project: sctalk   File: SessionDao.java   Source Code and License 6 votes vote down vote up
/** @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());
}
 
Example 11
Project: Cable-Android   File: SmsDatabase.java   Source Code and License 6 votes vote down vote up
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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
}
 
Example 12
Project: LookWeather   File: CountyDao.java   Source Code and License 6 votes vote down vote up
@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());
}
 
Example 13
Project: sqlbrite-sqlcipher   File: BriteDatabaseTest.java   Source Code and License 6 votes vote down vote up
@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();
}
 
Example 14
Project: buildAPKsApps   File: DataManager.java   Source Code and License 6 votes vote down vote up
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;
}
 
Example 15
Project: OftenPorter   File: SqliteHandle.java   Source Code and License 6 votes vote down vote up
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");
        }

    }
}
 
Example 16
Project: OftenPorter   File: SqliteHandle.java   Source Code and License 6 votes vote down vote up
@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);
    }

}
 
Example 17
Project: wallpaperboard   File: Database.java   Source Code and License 6 votes vote down vote up
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();
}
 
Example 18
Project: AndroidBackendlessChat   File: ContactLinkDao.java   Source Code and License 6 votes vote down vote up
/** @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);
    }
}
 
Example 19
Project: AndroidBackendlessChat   File: UserThreadLinkDao.java   Source Code and License 6 votes vote down vote up
/** @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);
    }
}
 
Example 20
Project: AndroidBackendlessChat   File: FollowerLinkDao.java   Source Code and License 6 votes vote down vote up
/** @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);
    }
}
 
Example 21
Project: openlocate-android   File: LocationTable.java   Source Code and License 6 votes vote down vote up
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();
}
 
Example 22
Project: weex-3d-map   File: DefaultWXStorage.java   Source Code and License 6 votes vote down vote up
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();
        }
    }
}
 
Example 23
Project: Expert-Android-Programming   File: PhotoItemDao.java   Source Code and License 6 votes vote down vote up
/** @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);
}
 
Example 24
Project: sqlbrite-sqlcipher   File: BriteDatabaseTest.java   Source Code and License 6 votes vote down vote up
@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();
}
 
Example 25
Project: chat-sdk-android-push-firebase   File: BLinkedAccountDao.java   Source Code and License 6 votes vote down vote up
/** @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);
    }
}
 
Example 26
Project: GhostContactBook   File: UserBeanDao.java   Source Code and License 6 votes vote down vote up
@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());
}
 
Example 27
Project: rongyunDemo   File: BlackListDao.java   Source Code and License 6 votes vote down vote up
/** @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);
    }
}
 
Example 28
Project: OpenHub   File: LocalUserDao.java   Source Code and License 6 votes vote down vote up
@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);
    }
}
 
Example 29
Project: buildAPKsApps   File: DataManager.java   Source Code and License 5 votes vote down vote up
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();
}
 
Example 30
Project: Cable-Android   File: SmsMigrator.java   Source Code and License 5 votes vote down vote up
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);
  }
}
 
Example 31
Project: GitHub   File: AbstractDao.java   Source Code and License 5 votes vote down vote up
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);
}
 
Example 32
Project: Android-SQLite-Master-Project   File: UserDaoByBuilders.java   Source Code and License 5 votes vote down vote up
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();
}
 
Example 33
Project: Bee-Analyzer   File: MapsActivity.java   Source Code and License 5 votes vote down vote up
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();
}
 
Example 34
Project: GitHub   File: CustomTypeEntityDao.java   Source Code and License 5 votes vote down vote up
@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));
    }
}
 
Example 35
Project: GitHub   File: ExtendsImplementsEntityDao.java   Source Code and License 5 votes vote down vote up
@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);
    }
}
 
Example 36
Project: GitHub   File: StringKeyValueEntityDao.java   Source Code and License 5 votes vote down vote up
@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);
    }
}
 
Example 37
Project: Expert-Android-Programming   File: RestaurantImageDao.java   Source Code and License 5 votes vote down vote up
/** @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()));
}
 
Example 38
Project: pvdisplay   File: PvDataOperations.java   Source Code and License 5 votes vote down vote up
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 39
Project: unity-obb-downloader   File: DownloadsDB.java   Source Code and License 5 votes vote down vote up
public long getIDByIndex(int index) {
    SQLiteStatement downloadByIndex = getDownloadByIndexStatement();
    downloadByIndex.clearBindings();
    downloadByIndex.bindLong(1, index);
    try {
        return downloadByIndex.simpleQueryForLong();
    } catch (SQLiteDoneException e) {
        return -1;
    }
}
 
Example 40
Project: SQLite-Performance   File: DbHelper.java   Source Code and License 5 votes vote down vote up
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();
    }
}