android.database.sqlite.SQLiteStatement Java Examples

The following examples show how to use android.database.sqlite.SQLiteStatement. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SQLitePlugin.java    From react-native-sqlite-storage with MIT License 6 votes vote down vote up
private void bindArgsToStatement(SQLiteStatement myStatement, ReadableArray sqlArgs) {
    for (int i = 0; i < sqlArgs.size(); i++) {
        ReadableType type = sqlArgs.getType(i);
        if (type == ReadableType.Number){
            double tmp = sqlArgs.getDouble(i);
            if (tmp == (long) tmp) {
                myStatement.bindLong(i + 1, (long) tmp);
            } else {
                myStatement.bindDouble(i + 1, tmp);
            }
        } else if (sqlArgs.isNull(i)) {
            myStatement.bindNull(i + 1);
        } else {
            myStatement.bindString(i + 1, SQLitePluginConverter.getString(sqlArgs,i,""));
        }
    }
}
 
Example #2
Source File: MagicPhotoEntityDao.java    From PLDroidShortVideo with Apache License 2.0 6 votes vote down vote up
@Override
protected final void bindValues(SQLiteStatement stmt, MagicPhotoEntity entity) {
    stmt.clearBindings();
 
    Long id = entity.getId();
    if (id != null) {
        stmt.bindLong(1, id);
    }
    stmt.bindLong(2, entity.getWidth());
    stmt.bindLong(3, entity.getHeight());
 
    String groupPointsStr = entity.getGroupPointsStr();
    if (groupPointsStr != null) {
        stmt.bindString(4, groupPointsStr);
    }
 
    String groupTypeStr = entity.getGroupTypeStr();
    if (groupTypeStr != null) {
        stmt.bindString(5, groupTypeStr);
    }
 
    String imagePath = entity.getImagePath();
    if (imagePath != null) {
        stmt.bindString(6, imagePath);
    }
}
 
Example #3
Source File: DatabaseHelper.java    From Study_Android_Demo with Apache License 2.0 6 votes vote down vote up
private void loadVibrateSetting(SQLiteDatabase db, boolean deleteOld) {
    if (deleteOld) {
        db.execSQL("DELETE FROM system WHERE name='" + Settings.System.VIBRATE_ON + "'");
    }

    SQLiteStatement stmt = null;
    try {
        stmt = db.compileStatement("INSERT OR IGNORE INTO system(name,value)"
                + " VALUES(?,?);");

        // Vibrate on by default for ringer, on for notification
        int vibrate = 0;
        vibrate = AudioSystem.getValueForVibrateSetting(vibrate,
                AudioManager.VIBRATE_TYPE_NOTIFICATION,
                AudioManager.VIBRATE_SETTING_ONLY_SILENT);
        vibrate |= AudioSystem.getValueForVibrateSetting(vibrate,
                AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_ONLY_SILENT);
        loadSetting(stmt, Settings.System.VIBRATE_ON, vibrate);
    } finally {
        if (stmt != null) stmt.close();
    }
}
 
Example #4
Source File: MessageDao.java    From android-orm-benchmark-updated with Apache License 2.0 6 votes vote down vote up
@Override
protected final void bindValues(SQLiteStatement stmt, Message entity) {
    stmt.clearBindings();
 
    Long id = entity.getId();
    if (id != null) {
        stmt.bindLong(1, id);
    }
 
    String content = entity.getContent();
    if (content != null) {
        stmt.bindString(2, content);
    }
    stmt.bindLong(3, entity.getClient_id());
    stmt.bindLong(4, entity.getCreated_at());
    stmt.bindDouble(5, entity.getSorted_by());
    stmt.bindLong(6, entity.getCommand_id());
    stmt.bindLong(7, entity.getSender_id());
    stmt.bindLong(8, entity.getChannel_id());
}
 
Example #5
Source File: Database.java    From wallpaperboard with Apache License 2.0 6 votes vote down vote up
public void deleteWallpapers(@NonNull List<Wallpaper> wallpapers) {
    if (!openDatabase()) {
        LogUtil.e("Database error: deleteWallpapers() failed to open database");
        return;
    }

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

    for (Wallpaper wallpaper : wallpapers) {
        statement.clearBindings();
        statement.bindString(1, wallpaper.getUrl());
        statement.execute();
    }

    mDatabase.get().mSQLiteDatabase.setTransactionSuccessful();
    mDatabase.get().mSQLiteDatabase.endTransaction();
}
 
Example #6
Source File: Green_AtUsersBeanDao.java    From iBeebo with GNU General Public License v3.0 6 votes vote down vote up
/**
 * @inheritdoc
 */
@Override
protected void bindValues(SQLiteStatement stmt, Green_AtUsersBean entity) {
    stmt.clearBindings();

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

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

    String at_user_info_json = entity.getAt_user_info_json();
    if (at_user_info_json != null) {
        stmt.bindString(3, at_user_info_json);
    }
}
 
Example #7
Source File: SQLiteTemplate.java    From twitt4droid with Apache License 2.0 6 votes vote down vote up
/**
 * Submits a batch of commands to the database for execution..
 * 
 * @param sqls SQLs to execute.
 */
void batchExecute(String[] sqls) {
    SQLiteDatabase database = null;
    try {
        database = databaseHelper.getWritableDatabase();
        database.beginTransaction();
        for (String sql : sqls) {
            SQLiteStatement statement = database.compileStatement(sql);
            statement.execute();
            statement.close();
        }
        database.setTransactionSuccessful();
    } catch (Exception ex) {
        Log.e(TAG, "Couldn't execute batch " + Arrays.deepToString(sqls), ex);
    } finally {
        SQLiteUtils.endTransaction(database);
        SQLiteUtils.close(database);
    }
}
 
Example #8
Source File: SimpleMetaDataManager.java    From science-journal with Apache License 2.0 6 votes vote down vote up
@Nullable
private String getExternalSensorId(ExternalSensorSpec sensor, SQLiteDatabase db) {
  String sql =
      "SELECT IFNULL(MIN("
          + SensorColumns.SENSOR_ID
          + "), '') FROM "
          + Tables.EXTERNAL_SENSORS
          + " WHERE "
          + SensorColumns.CONFIG
          + "=? AND "
          + SensorColumns.TYPE
          + "=?";
  SQLiteStatement statement = db.compileStatement(sql);
  statement.bindBlob(1, sensor.getConfig());
  statement.bindString(2, sensor.getType());
  String sensorId = statement.simpleQueryForString();
  if (!sensorId.isEmpty()) {
    return sensorId;
  }
  return null;
}
 
Example #9
Source File: SQLiteTemplate.java    From tedroid with Apache License 2.0 6 votes vote down vote up
/**
 * Ejecuta una sentencia SQL (INSERT, UPDATE, DELETE, etc.) en la base de datos.
 * 
 * @param sql la sentencia SQL a ejecutar.
 */
void execute(String sql) {
    SQLiteDatabase database = null;
    SQLiteStatement statement = null;
    try {
        database = databaseHelper.getWritableDatabase();
        database.beginTransaction();
        statement = database.compileStatement(sql);
        statement.execute();
        database.setTransactionSuccessful();
    } catch (Exception ex) {
        Log.e(TAG, "Couldn't execute [" + sql + "]", ex);
    } finally {
        SQLiteUtils.close(statement);
        SQLiteUtils.endTransaction(database);
        SQLiteUtils.close(database);
    }
}
 
Example #10
Source File: HistoryEntityDao.java    From WaveHeartRate with Apache License 2.0 6 votes vote down vote up
/** @inheritdoc */
@Override
protected void bindValues(SQLiteStatement stmt, HistoryEntity entity) {
    stmt.clearBindings();
 
    Long id = entity.getId();
    if (id != null) {
        stmt.bindLong(1, id);
    }
 
    Long calculateTime = entity.getCalculateTime();
    if (calculateTime != null) {
        stmt.bindLong(2, calculateTime);
    }
 
    Integer rate = entity.getRate();
    if (rate != null) {
        stmt.bindLong(3, rate);
    }
}
 
Example #11
Source File: WordDao.java    From ml-authentication with Apache License 2.0 6 votes vote down vote up
@Override
protected final void bindValues(SQLiteStatement stmt, Word entity) {
    stmt.clearBindings();
 
    Long id = entity.getId();
    if (id != null) {
        stmt.bindLong(1, id);
    }
    stmt.bindString(2, localeConverter.convertToDatabaseValue(entity.getLocale()));
 
    Calendar timeLastUpdate = entity.getTimeLastUpdate();
    if (timeLastUpdate != null) {
        stmt.bindLong(3, timeLastUpdateConverter.convertToDatabaseValue(timeLastUpdate));
    }
    stmt.bindLong(4, entity.getRevisionNumber());
    stmt.bindString(5, contentStatusConverter.convertToDatabaseValue(entity.getContentStatus()));
    stmt.bindString(6, entity.getText());
    stmt.bindString(7, entity.getPhonetics());
    stmt.bindLong(8, entity.getUsageCount());
 
    SpellingConsistency spellingConsistency = entity.getSpellingConsistency();
    if (spellingConsistency != null) {
        stmt.bindString(9, spellingConsistencyConverter.convertToDatabaseValue(spellingConsistency));
    }
}
 
Example #12
Source File: BatchedSQLiteStatementTestCase.java    From SQLite-Performance with The Unlicense 6 votes vote down vote up
@Override
public Metrics runCase() {
    mDbHelper = new DbHelper(App.getInstance(), getClass().getName());
    Metrics result = new Metrics(getClass().getSimpleName()+" ("+mInsertions+" insertions)", mTestSizeIndex);
    SQLiteDatabase db = mDbHelper.getWritableDatabase();

    byte[] titleByteArry = new byte[50];
    byte[] urlByteArray = new byte[100];
    byte[] lyricsByteArray = new byte[2000];
    byte[] aboutByteArray = new byte[2000];
    Map<Integer, SQLiteStatement> statementCache = new HashMap<>();

    result.started();
    db.beginTransaction();
    mInsertId = 1;
    doInsertions(db, mInsertions, statementCache, titleByteArry, urlByteArray, lyricsByteArray, aboutByteArray);
    db.setTransactionSuccessful();
    db.endTransaction();
    result.finished();

    return result;
}
 
Example #13
Source File: Green_TimeLineStatusDao.java    From iBeebo with GNU General Public License v3.0 6 votes vote down vote up
/**
 * @inheritdoc
 */
@Override
protected void bindValues(SQLiteStatement stmt, Green_TimeLineStatus entity) {
    stmt.clearBindings();

    Integer _id = entity.get_id();
    if (_id != null) {
        stmt.bindLong(1, _id);
    }

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

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

    String json = entity.getJson();
    if (json != null) {
        stmt.bindString(4, json);
    }
}
 
Example #14
Source File: GeofenceStorage.java    From android-sdk with MIT License 6 votes vote down vote up
public void updateFences(List<String> fences) {
    SQLiteStatement stmt = null;
    try {
        long start = System.currentTimeMillis();
        db.beginTransaction();
        db.execSQL("DELETE FROM " + DBHelper.TABLE_GEOFENCES);
        stmt = db.compileStatement(
                "INSERT OR IGNORE INTO " + DBHelper.TABLE_GEOFENCES + " (" + DBHelper.TG_FENCE + ") VALUES (?)"
        );
        for (String fence : fences) {
            stmt.clearBindings();
            stmt.bindString(1, fence);
            stmt.executeInsert();
        }
        db.setTransactionSuccessful();
        count = fences.size();
        Logger.log.geofence("Saved "+fences.size()+" in "+(System.currentTimeMillis() - start) + " ms");
    } catch (SQLException ex) {
        Logger.log.geofenceError("Storage error", ex);
    } finally {
        if (stmt != null) {
            stmt.close();
        }
        db.endTransaction();
    }
}
 
Example #15
Source File: DatabaseHelper.java    From Study_Android_Demo with Apache License 2.0 6 votes vote down vote up
private void upgradeScreenTimeout(SQLiteDatabase db) {
     // Change screen timeout to current default
     String EnergyStar = SystemProperties.get("persist.hht.EnergyStar","false");
     db.beginTransaction();
     SQLiteStatement stmt = null;
     try {
         stmt = db.compileStatement("INSERT OR REPLACE INTO system(name,value)"
                 + " VALUES(?,?);");
if("false".equals(EnergyStar))
         loadIntegerSetting(stmt, Settings.System.SCREEN_OFF_TIMEOUT,
                 R.integer.def_screen_off_timeout);
else
	loadIntegerSetting(stmt, Settings.System.SCREEN_OFF_TIMEOUT,
                 R.integer.def_screen_off_timeout_EnergyStar);
         db.setTransactionSuccessful();
     } finally {
         db.endTransaction();
         if (stmt != null)
             stmt.close();
     }
 }
 
Example #16
Source File: UseAreaDao.java    From FoodOrdering with Apache License 2.0 6 votes vote down vote up
/** @inheritdoc */
@Override
protected void bindValues(SQLiteStatement stmt, UseArea entity) {
    stmt.clearBindings();
 
    String areaid = entity.getAreaid();
    if (areaid != null) {
        stmt.bindString(1, areaid);
    }
 
    String areaid2345 = entity.getAreaid2345();
    if (areaid2345 != null) {
        stmt.bindString(2, areaid2345);
    }
 
    String areaName = entity.getAreaName();
    if (areaName != null) {
        stmt.bindString(3, areaName);
    }
 
    Boolean main = entity.getMain();
    if (main != null) {
        stmt.bindLong(4, main ? 1L: 0L);
    }
}
 
Example #17
Source File: Benchmark.java    From sqlite-android with Apache License 2.0 6 votes vote down vote up
private void testAndroidSQLiteWrite(Statistics statistics) {
    Trace trace = new Trace("Android Write");
    SQLiteDatabase db = platformSQLite.getReadableDatabase();
    SQLiteStatement statement = db.compileStatement(
        String.format("insert into %s (%s, %s) values (?,?)",
            Record.TABLE_NAME,
            Record.COLUMN_CONTENT,
            Record.COLUMN_CREATED_TIME));
    try {
        db.beginTransaction();
        for (int i = 0; i < COUNT; i++) {
            Record record = Record.create(i);
            statement.bindString(1, record.getContent());
            statement.bindDouble(2, record.getCreatedTime());
            long id = statement.executeInsert();
            record.setId(id);
        }
        db.setTransactionSuccessful();
    } finally {
        db.endTransaction();
    }
    statistics.write( trace.exit() );
}
 
Example #18
Source File: DefaultWXStorage.java    From weex-uikit with MIT 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 #19
Source File: AddressBookDao.java    From AndroidDatabaseLibraryComparison with MIT License 6 votes vote down vote up
/** @inheritdoc */
@Override
protected void bindValues(SQLiteStatement stmt, AddressBook entity) {
    stmt.clearBindings();
 
    Long id = entity.getId();
    if (id != null) {
        stmt.bindLong(1, id);
    }
 
    String name = entity.getName();
    if (name != null) {
        stmt.bindString(2, name);
    }
 
    String author = entity.getAuthor();
    if (author != null) {
        stmt.bindString(3, author);
    }
}
 
Example #20
Source File: TransactionEntityDao.java    From Android with MIT License 6 votes vote down vote up
@Override
protected final void bindValues(SQLiteStatement stmt, TransactionEntity entity) {
    stmt.clearBindings();
 
    Long _id = entity.get_id();
    if (_id != null) {
        stmt.bindLong(1, _id);
    }
    stmt.bindString(2, entity.getMessage_id());
    stmt.bindString(3, entity.getHashid());
 
    Integer status = entity.getStatus();
    if (status != null) {
        stmt.bindLong(4, status);
    }
 
    Integer pay_count = entity.getPay_count();
    if (pay_count != null) {
        stmt.bindLong(5, pay_count);
    }
 
    Integer crowd_count = entity.getCrowd_count();
    if (crowd_count != null) {
        stmt.bindLong(6, crowd_count);
    }
}
 
Example #21
Source File: DbHelper.java    From SQLite-Performance with The Unlicense 6 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();
    }
}
 
Example #22
Source File: SessionDao.java    From sctalk with Apache License 2.0 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 #23
Source File: ImageCacheDao.java    From TLint with Apache License 2.0 6 votes vote down vote up
/**
 * @inheritdoc
 */
@Override
protected void bindValues(SQLiteStatement stmt, ImageCache entity) {
    stmt.clearBindings();

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

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

    String path = entity.getPath();
    if (path != null) {
        stmt.bindString(3, path);
    }
}
 
Example #24
Source File: DBHelper.java    From EasyVPN-Free with GNU General Public License v3.0 5 votes vote down vote up
public long getCountAdditional() {
    SQLiteDatabase db = this.getWritableDatabase();
    SQLiteStatement statement = db.compileStatement("SELECT COUNT(*) FROM "
            + TABLE_SERVERS
            + " WHERE "
            + KEY_TYPE
            + " = 1");
    long count = statement.simpleQueryForLong();
    db.close();
    return count;
}
 
Example #25
Source File: SimpleAddressItemDao.java    From AndroidDatabaseLibraryComparison with MIT License 5 votes vote down vote up
/** @inheritdoc */
@Override
protected void bindValues(SQLiteStatement stmt, SimpleAddressItem entity) {
    stmt.clearBindings();
 
    Long id = entity.getId();
    if (id != null) {
        stmt.bindLong(1, id);
    }
 
    String name = entity.getName();
    if (name != null) {
        stmt.bindString(2, name);
    }
 
    String address = entity.getAddress();
    if (address != null) {
        stmt.bindString(3, address);
    }
 
    String city = entity.getCity();
    if (city != null) {
        stmt.bindString(4, city);
    }
 
    String state = entity.getState();
    if (state != null) {
        stmt.bindString(5, state);
    }
 
    Long phone = entity.getPhone();
    if (phone != null) {
        stmt.bindLong(6, phone);
    }
}
 
Example #26
Source File: DBHelper.java    From EasyVPN-Free with GNU General Public License v3.0 5 votes vote down vote up
public long getCount() {
    SQLiteDatabase db = this.getWritableDatabase();
    SQLiteStatement statement = db.compileStatement("SELECT COUNT(*) FROM " + TABLE_SERVERS);
    long count = statement.simpleQueryForLong();
    db.close();
    return count;
}
 
Example #27
Source File: JoinVideosWithWordsDao.java    From ml-authentication with Apache License 2.0 5 votes vote down vote up
@Override
protected final void bindValues(SQLiteStatement stmt, JoinVideosWithWords entity) {
    stmt.clearBindings();
 
    Long id = entity.getId();
    if (id != null) {
        stmt.bindLong(1, id);
    }
    stmt.bindLong(2, entity.getVideoId());
    stmt.bindLong(3, entity.getWordId());
}
 
Example #28
Source File: StudentImageFeatureDao.java    From ml-authentication with Apache License 2.0 5 votes vote down vote up
@Override
protected final void bindValues(SQLiteStatement stmt, StudentImageFeature entity) {
    stmt.clearBindings();
 
    Long id = entity.getId();
    if (id != null) {
        stmt.bindLong(1, id);
    }
    stmt.bindLong(2, timeCreatedConverter.convertToDatabaseValue(entity.getTimeCreated()));
    stmt.bindString(3, entity.getFeatureVector());
}
 
Example #29
Source File: SqliteJobQueue.java    From Mover with Apache License 2.0 5 votes vote down vote up
private void onJobFetchedForRunning(JobHolder jobHolder) {
    SQLiteStatement stmt = sqlHelper.getOnJobFetchedForRunningStatement();
    jobHolder.setRunCount(jobHolder.getRunCount() + 1);
    jobHolder.setRunningSessionId(sessionId);
    synchronized (stmt) {
        stmt.clearBindings();
        stmt.bindLong(1, jobHolder.getRunCount());
        stmt.bindLong(2, sessionId);
        stmt.bindLong(3, jobHolder.getId());
        stmt.execute();
    }
}
 
Example #30
Source File: DownloadsDB.java    From QtAndroidTools with MIT License 5 votes vote down vote up
private SQLiteStatement getDownloadByIndexStatement() {
    if (null == mGetDownloadByIndex) {
        mGetDownloadByIndex = mHelper.getReadableDatabase().compileStatement(
                "SELECT " + BaseColumns._ID + " FROM "
                        + DownloadColumns.TABLE_NAME + " WHERE "
                        + DownloadColumns.INDEX + " = ?");
    }
    return mGetDownloadByIndex;
}