Java Code Examples for android.database.sqlite.SQLiteStatement#bindBlob()

The following examples show how to use android.database.sqlite.SQLiteStatement#bindBlob() . 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: WeatherEntityDao.java    From easyweather with MIT License 6 votes vote down vote up
@Override
protected final void bindValues(SQLiteStatement stmt, WeatherEntity entity) {
    stmt.clearBindings();
 
    Long id = entity.getId();
    if (id != null) {
        stmt.bindLong(1, id);
    }
 
    String cityName = entity.getCityName();
    if (cityName != null) {
        stmt.bindString(2, cityName);
    }
 
    byte[] weather = entity.getWeather();
    if (weather != null) {
        stmt.bindBlob(3, weather);
    }
 
    java.util.Date updateTime = entity.getUpdateTime();
    if (updateTime != null) {
        stmt.bindLong(4, updateTime.getTime());
    }
}
 
Example 2
Source File: LuaZipFileDao.java    From MiBandDecompiled with Apache License 2.0 6 votes vote down vote up
protected void bindValues(SQLiteStatement sqlitestatement, LuaZipFile luazipfile)
{
    sqlitestatement.clearBindings();
    Long long1 = luazipfile.getId();
    if (long1 != null)
    {
        sqlitestatement.bindLong(1, long1.longValue());
    }
    String s = luazipfile.getVersion();
    if (s != null)
    {
        sqlitestatement.bindString(2, s);
    }
    String s1 = luazipfile.getDate();
    if (s1 != null)
    {
        sqlitestatement.bindString(3, s1);
    }
    byte abyte0[] = luazipfile.getZipFile();
    if (abyte0 != null)
    {
        sqlitestatement.bindBlob(4, abyte0);
    }
}
 
Example 3
Source File: SqliteJobQueue.java    From Mover with Apache License 2.0 6 votes vote down vote up
private void bindValues(SQLiteStatement stmt, JobHolder jobHolder) {
    if (jobHolder.getId() != null) {
        stmt.bindLong(DbOpenHelper.ID_COLUMN.columnIndex + 1, jobHolder.getId());
    }
    stmt.bindLong(DbOpenHelper.PRIORITY_COLUMN.columnIndex + 1, jobHolder.getPriority());
    if(jobHolder.getGroupId() != null) {
        stmt.bindString(DbOpenHelper.GROUP_ID_COLUMN.columnIndex + 1, jobHolder.getGroupId());
    }
    stmt.bindLong(DbOpenHelper.RUN_COUNT_COLUMN.columnIndex + 1, jobHolder.getRunCount());
    byte[] baseJob = getSerializeBaseJob(jobHolder);
    if (baseJob != null) {
        stmt.bindBlob(DbOpenHelper.BASE_JOB_COLUMN.columnIndex + 1, baseJob);
    }
    stmt.bindLong(DbOpenHelper.CREATED_NS_COLUMN.columnIndex + 1, jobHolder.getCreatedNs());
    stmt.bindLong(DbOpenHelper.DELAY_UNTIL_NS_COLUMN.columnIndex + 1, jobHolder.getDelayUntilNs());
    stmt.bindLong(DbOpenHelper.RUNNING_SESSION_ID_COLUMN.columnIndex + 1, jobHolder.getRunningSessionId());
    stmt.bindLong(DbOpenHelper.REQUIRES_NETWORK_COLUMN.columnIndex + 1, jobHolder.requiresNetwork() ? 1L : 0L);
}
 
Example 4
Source File: GroupsDao.java    From Yahala-Messenger with MIT License 6 votes vote down vote up
/**
 * @inheritdoc
 */
@Override
protected void bindValues(SQLiteStatement stmt, Groups entity) {
    stmt.clearBindings();

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

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

    byte[] participants = entity.getParticipants();
    if (participants != null) {
        stmt.bindBlob(3, participants);
    }
}
 
Example 5
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 6
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 7
Source File: WallpapersDao.java    From Yahala-Messenger with MIT License 5 votes vote down vote up
/**
 * @inheritdoc
 */
@Override
protected void bindValues(SQLiteStatement stmt, Wallpapers entity) {
    stmt.clearBindings();

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

    byte[] data = entity.getData();
    if (data != null) {
        stmt.bindBlob(2, data);
    }
}
 
Example 8
Source File: Storage.java    From beacons-android with Apache License 2.0 4 votes vote down vote up
private void migrateEddystoneItems(SQLiteDatabase db) {
    SQLiteStatement updateStatement = createUpdater(db, "d0", "d1", "d2", "d3", "kind", "flags");
    Cursor cursor = db.rawQuery("SELECT e.rowid, url, domain, lockKey, flags" +
            " FROM " + EDDYSTONE_TABLE + " e" +
            " LEFT OUTER JOIN " + ITEMS_TABLE + " i ON e.rowid=i.rowid", null);
    while (cursor.moveToNext()) {
        updateStatement.clearBindings();

        updateStatement.bindLong(1, cursor.getLong(0));

        int flags = cursor.getInt(4);
        int type = flags >>> 4;

        if (!cursor.isNull(3)) {
            updateStatement.bindBlob(2, cursor.getBlob(3));   // lock key
        }
        updateStatement.bindLong(7, 0);

        String payload = cursor.getString(1);
        String domain = cursor.getString(2);

        switch (type) {
            case 0:         // EDDYSTONE_URL
                bindStringOrNull(updateStatement, 3, payload);
                updateStatement.bindLong(6, KIND_EDDYSTONE_URL);
                break;
            case 1:         // EDDYSTONE_UID
                updateStatement.bindBlob(3, Base64.decode(payload, Base64.DEFAULT));
                bindStringOrNull(updateStatement, 4, domain);
                updateStatement.bindLong(6, KIND_EDDYSTONE_UID);
                break;
            case 2:         // EDDYSTONE_EID
                byte[] eidRaw = Base64.decode(payload, Base64.DEFAULT);
                int eidTimeOffset = ByteBuffer.wrap(eidRaw, 16, 4).getInt();

                // sanitize time offset to match range; see EIDUtils.register()
                eidTimeOffset = Math.min(255, Math.max(-65280, eidTimeOffset));

                // sanitize rotation exponent to [0, 15] range
                byte rotationExponent = (byte) (eidRaw[20] & 0x0f);

                updateStatement.bindBlob(3, Arrays.copyOfRange(eidRaw, 0, 16));
                updateStatement.bindLong(4, rotationExponent);
                updateStatement.bindLong(5, eidTimeOffset);
                updateStatement.bindLong(6, KIND_EDDYSTONE_EID);
                break;
        }

        executeSafeUpdateOrDelete(updateStatement);
    }
    cursor.close();
    updateStatement.close();

    db.execSQL("DROP TABLE " + EDDYSTONE_TABLE);
}
 
Example 9
Source File: LauncherProvider.java    From LB-Launcher with Apache License 2.0 4 votes vote down vote up
private void normalizeIcons(SQLiteDatabase db) {
    Log.d(TAG, "normalizing icons");

    db.beginTransaction();
    Cursor c = null;
    SQLiteStatement update = null;
    try {
        boolean logged = false;
        update = db.compileStatement("UPDATE favorites "
                + "SET icon=? WHERE _id=?");

        c = db.rawQuery("SELECT _id, icon FROM favorites WHERE iconType=" +
                Favorites.ICON_TYPE_BITMAP, null);

        final int idIndex = c.getColumnIndexOrThrow(Favorites._ID);
        final int iconIndex = c.getColumnIndexOrThrow(Favorites.ICON);

        while (c.moveToNext()) {
            long id = c.getLong(idIndex);
            byte[] data = c.getBlob(iconIndex);
            try {
                Bitmap bitmap = Utilities.createIconBitmap(
                        BitmapFactory.decodeByteArray(data, 0, data.length),
                        mContext);
                if (bitmap != null) {
                    update.bindLong(1, id);
                    data = ItemInfo.flattenBitmap(bitmap);
                    if (data != null) {
                        update.bindBlob(2, data);
                        update.execute();
                    }
                    bitmap.recycle();
                }
            } catch (Exception e) {
                if (!logged) {
                    Log.e(TAG, "Failed normalizing icon " + id, e);
                } else {
                    Log.e(TAG, "Also failed normalizing icon " + id);
                }
                logged = true;
            }
        }
        db.setTransactionSuccessful();
    } catch (SQLException ex) {
        Log.w(TAG, "Problem while allocating appWidgetIds for existing widgets", ex);
    } finally {
        db.endTransaction();
        if (update != null) {
            update.close();
        }
        if (c != null) {
            c.close();
        }
    }
}
 
Example 10
Source File: MessagesDao.java    From Yahala-Messenger with MIT License 4 votes vote down vote up
/**
 * @inheritdoc
 */
@Override
protected void bindValues(SQLiteStatement stmt, Messages entity) {
    stmt.clearBindings();

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

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

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

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

    Integer send_state = entity.getSend_state();
    if (send_state != null) {
        stmt.bindLong(5, send_state);
    }

    java.util.Date date = entity.getDate();
    if (date != null) {
        stmt.bindLong(6, date.getTime());
    }

    Integer out = entity.getOut();
    if (out != null) {
        stmt.bindLong(7, out);
    }

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

    Integer ttl = entity.getTtl();
    if (ttl != null) {
        stmt.bindLong(9, ttl);
    }

    byte[] data = entity.getData();
    if (data != null) {
        stmt.bindBlob(10, data);
    }
}
 
Example 11
Source File: AndroidDatabaseConnection.java    From ormlite-android with ISC License 4 votes vote down vote up
private void bindArgs(SQLiteStatement stmt, Object[] args, FieldType[] argFieldTypes) throws SQLException {
	if (args == null) {
		return;
	}
	for (int i = 0; i < args.length; i++) {
		Object arg = args[i];
		if (arg == null) {
			stmt.bindNull(i + 1);
		} else {
			SqlType sqlType = argFieldTypes[i].getSqlType();
			switch (sqlType) {
				case STRING:
				case LONG_STRING:
				case CHAR:
					stmt.bindString(i + 1, arg.toString());
					break;
				case BOOLEAN:
				case BYTE:
				case SHORT:
				case INTEGER:
				case LONG:
					stmt.bindLong(i + 1, ((Number) arg).longValue());
					break;
				case FLOAT:
				case DOUBLE:
					stmt.bindDouble(i + 1, ((Number) arg).doubleValue());
					break;
				case BYTE_ARRAY:
				case SERIALIZABLE:
					stmt.bindBlob(i + 1, (byte[]) arg);
					break;
				case DATE:
					// this is mapped to a STRING under Android
				case BLOB:
					// this is only for derby serializable
				case BIG_DECIMAL:
					// this should be handled as a STRING
					throw new SQLException("Invalid Android type: " + sqlType);
				case UNKNOWN:
				default:
					throw new SQLException("Unknown sql argument type: " + sqlType);
			}
		}
	}
}
 
Example 12
Source File: SQLiteBlobHelper.java    From libcommon with Apache License 2.0 2 votes vote down vote up
/**
 * SQLiteStatement#bindBlobのヘルパーメソッド。longの配列をbyteの配列に変換して割り付ける
 *
 * @param stat
 * @param index
 * @param array
 * @param offset
 * @param num
 */
public static void bindBlobLongArray(@NonNull final SQLiteStatement stat,
	final int index, final long[] array, final int offset, final int num) {

	stat.bindBlob(index, longArrayToByteArray(array, offset, num));
}
 
Example 13
Source File: SQLiteBlobHelper.java    From libcommon with Apache License 2.0 2 votes vote down vote up
/**
 * SQLiteStatement#bindBlobのヘルパーメソッド。Bitmapをbyteの配列に変換して割り付ける
 *
 * @param stat
 * @param index
 * @param bitmap
 */
public static void bindBlobBitmap(@NonNull final SQLiteStatement stat,
	final int index, @NonNull final Bitmap bitmap) {

	stat.bindBlob(index, BitmapHelper.BitmapToByteArray(bitmap));
}
 
Example 14
Source File: SQLiteBlobHelper.java    From libcommon with Apache License 2.0 2 votes vote down vote up
/**
 * SQLiteStatement#bindBlobのヘルパーメソッド。longの配列をbyteの配列に変換して割り付ける
 *
 * @param stat
 * @param index
 * @param array
 */
public static void bindBlobLongArray(@NonNull final SQLiteStatement stat,
	final int index, @NonNull final long[] array) {

	stat.bindBlob(index, longArrayToByteArray(array, 0, array.length));
}
 
Example 15
Source File: SQLiteBlobHelper.java    From libcommon with Apache License 2.0 2 votes vote down vote up
/**
 * SQLiteStatement#bindBlobのヘルパーメソッド。shortの配列をbyteの配列に変換して割り付ける
 *
 * @param stat
 * @param index
 * @param array
 */
public static void bindBlobShortArray(@NonNull final SQLiteStatement stat,
	final int index, @NonNull final short[] array) {

	stat.bindBlob(index, shortArrayToByteArray(array, 0, array.length));
}
 
Example 16
Source File: SQLiteBlobHelper.java    From libcommon with Apache License 2.0 2 votes vote down vote up
/**
 * SQLiteStatement#bindBlobのヘルパーメソッド。intの配列をbyteの配列に変換して割り付ける
 *
 * @param stat
 * @param index
 * @param array
 */
public static void bindBlobIntArray(@NonNull final SQLiteStatement stat,
	final int index, @NonNull final int[] array, final int offset, final int num) {

	stat.bindBlob(index, intArrayToByteArray(array, offset, num));
}
 
Example 17
Source File: SQLiteBlobHelper.java    From libcommon with Apache License 2.0 2 votes vote down vote up
/**
 * SQLiteStatement#bindBlobのヘルパーメソッド。intの配列をbyteの配列に変換して割り付ける
 *
 * @param stat
 * @param index
 * @param array
 */
public static void bindBlobIntArray(@NonNull final SQLiteStatement stat,
	final int index, @NonNull final int[] array) {

	stat.bindBlob(index, intArrayToByteArray(array, 0, array.length));
}
 
Example 18
Source File: SQLiteBlobHelper.java    From libcommon with Apache License 2.0 2 votes vote down vote up
/**
 * SQLiteStatement#bindBlobのヘルパーメソッド。doubleの配列をbyteの配列に変換して割り付ける
 *
 * @param stat
 * @param index
 * @param array
 */
public static void bindBlobDoubleArray(@NonNull final SQLiteStatement stat,
	final int index, @NonNull final double[] array) {

	stat.bindBlob(index, doubleArrayToByteArray(array, 0, array.length));
}
 
Example 19
Source File: SQLiteBlobHelper.java    From libcommon with Apache License 2.0 2 votes vote down vote up
/**
 * SQLiteStatement#bindBlobのヘルパーメソッド。floatの配列をbyteの配列に変換して割り付ける
 *
 * @param stat
 * @param index
 * @param array
 * @param offset
 * @param num
 */
public static void bindBlobFloatArray(@NonNull final SQLiteStatement stat,
	final int index, @NonNull final float[] array, final int offset, final int num) {

	stat.bindBlob(index, floatArrayToByteArray(array, offset, num));
}
 
Example 20
Source File: SQLiteBlobHelper.java    From libcommon with Apache License 2.0 2 votes vote down vote up
/**
 * SQLiteStatement#bindBlobのヘルパーメソッド。floatの配列をbyteの配列に変換して割り付ける
 *
 * @param stat
 * @param index
 * @param array
 */
public static void bindBlobFloatArray(@NonNull final SQLiteStatement stat,
	final int index, @NonNull final float[] array) {

	stat.bindBlob(index, floatArrayToByteArray(array, 0, array.length));
}