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

The following are Jave code examples for showing how to use execute() of the android.database.sqlite.SQLiteStatement class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: wallpaperboard   File: Database.java   Source Code and License Vote up 6 votes
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 2
Project: openlocate-android   File: LocationTable.java   Source Code and License Vote up 6 votes
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 3
Project: q-mail   File: Storage.java   Source Code and License Vote up 5 votes
void put(Map<String, String> insertables) {
    String sql = "INSERT INTO preferences_storage (primkey, value) VALUES (?, ?)";
    SQLiteStatement stmt = workingDB.get().compileStatement(sql);

    for (Map.Entry<String, String> entry : insertables.entrySet()) {
        String key = entry.getKey();
        String value = entry.getValue();
        stmt.bindString(1, key);
        stmt.bindString(2, value);
        stmt.execute();
        stmt.clearBindings();
        liveUpdate(key, value);
    }
    stmt.close();
}
 
Example 4
Project: wallpaperboard   File: Database.java   Source Code and License Vote up 5 votes
public void updateWallpapers(@NonNull List<Wallpaper> wallpapers) {
    if (!openDatabase()) {
        LogUtil.e("Database error: updateWallpapers() failed to open database");
        return;
    }

    String query = "UPDATE " +TABLE_WALLPAPERS+ " SET " +KEY_FAVORITE+ " = ?, " +KEY_SIZE+ " = ?, "
            +KEY_MIME_TYPE+ " = ?, " +KEY_WIDTH+ " = ?," +KEY_HEIGHT+ " = ?, " +KEY_COLOR+ " = ? "
            +"WHERE " +KEY_URL+ " = ?";
    SQLiteStatement statement = mDatabase.get().mSQLiteDatabase.compileStatement(query);
    mDatabase.get().mSQLiteDatabase.beginTransaction();

    for (Wallpaper wallpaper : wallpapers) {
        statement.clearBindings();

        statement.bindLong(1, wallpaper.isFavorite() ? 1 : 0);
        statement.bindLong(2, wallpaper.getSize());

        String mimeType = wallpaper.getMimeType();
        if (mimeType != null) {
            statement.bindString(3, mimeType);
        } else {
            statement.bindNull(3);
        }

        ImageSize dimension = wallpaper.getDimensions();
        int width = dimension == null ? 0 : dimension.getWidth();
        int height = dimension == null ? 0 : dimension.getHeight();
        statement.bindLong(4, width);
        statement.bindLong(5, height);

        statement.bindLong(6, wallpaper.getColor());
        statement.bindString(7, wallpaper.getUrl());
        statement.execute();
    }

    mDatabase.get().mSQLiteDatabase.setTransactionSuccessful();
    mDatabase.get().mSQLiteDatabase.endTransaction();
}
 
Example 5
Project: GitHub   File: AbstractDao.java   Source Code and License Vote up 5 votes
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 6
Project: MapaDeIgarassuAdmin   File: DataBaseUtil.java   Source Code and License Vote up 5 votes
public void updateLocation(LocationModel locationModel) {
    SQLiteDatabase db = this.getWritableDatabase();
    SQLiteStatement stmt = db.compileStatement(Constants.UPDATE_TABLE_LOCATION);
    stmt.bindString(1, locationModel.getName());
    stmt.bindDouble(2, locationModel.getLongitude());
    stmt.bindDouble(3, locationModel.getLatitude());
    stmt.bindString(4, locationModel.getAddress());
    stmt.bindString(5, locationModel.getDescription());
    stmt.bindLong(6, locationModel.getId());
    stmt.execute();
}
 
Example 7
Project: pvdisplay   File: PvDataOperations.java   Source Code and License Vote up 5 votes
public void saveDaily(List<DailyPvDatum> dailyPvData) {
    SQLiteDatabase db = pvDataHelper.getWritableDatabase();

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

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

    RecordPvDatum recordPvDatum = loadRecord();
    if (maxEnergyGenerated > recordPvDatum.getDailyEnergyGenerated()) {
        recordPvDatum.setDailyEnergyGenerated(maxEnergyGenerated);
        saveRecord(recordPvDatum);
    }
}
 
Example 8
Project: csync-android   File: SqliteDBManager.java   Source Code and License Vote up 5 votes
@Override public void onCreate(SQLiteDatabase db) {
  SQLiteStatement createDataTable = db.compileStatement(DataTable.Statements.CREATE_TABLE);
  SQLiteStatement createRvtsTable = db.compileStatement(RvtsTable.Statements.CREATE_TABLE);
  SQLiteStatement createDirtyTable = db.compileStatement(DirtyTable.Statements.CREATE_TABLE);

  createDataTable.execute();
  createRvtsTable.execute();
  createDirtyTable.execute();
}
 
Example 9
Project: weex-3d-map   File: DefaultWXStorage.java   Source Code and License Vote up 5 votes
private boolean performSetItem(String key, String value, boolean isPersistent, boolean allowRetryWhenFull) {
    SQLiteDatabase database = mDatabaseSupplier.getDatabase();
    if (database == null) {
        return false;
    }

    WXLogUtils.d(WXSQLiteOpenHelper.TAG_STORAGE, "set k-v to storage(key:" + key + ",value:" + value + ",isPersistent:" + isPersistent + ",allowRetry:" + allowRetryWhenFull + ")");
    String sql = "INSERT OR REPLACE INTO " + WXSQLiteOpenHelper.TABLE_STORAGE + " VALUES (?,?,?,?);";
    SQLiteStatement statement = null;
    String timeStamp = WXSQLiteOpenHelper.sDateFormatter.format(new Date());
    try {
        statement = database.compileStatement(sql);
        statement.clearBindings();
        statement.bindString(1, key);
        statement.bindString(2, value);
        statement.bindString(3, timeStamp);
        statement.bindLong(4, isPersistent ? 1 : 0);
        statement.execute();
        return true;
    } catch (Exception e) {
        WXLogUtils.e(WXSQLiteOpenHelper.TAG_STORAGE, "DefaultWXStorage occurred an exception when execute setItem :" + e.getMessage());
        if (e instanceof SQLiteFullException) {
            if (allowRetryWhenFull && trimToSize()) {
                //try again
                //setItem/setItemPersistent method only allow try once when occurred a sqliteFullException.
                WXLogUtils.d(WXSQLiteOpenHelper.TAG_STORAGE, "retry set k-v to storage(key:" + key + ",value:" + value + ")");
                return performSetItem(key, value, isPersistent, false);
            }
        }

        return false;
    } finally {
        if(statement != null) {
            statement.close();
        }
    }
}
 
Example 10
Project: unity-obb-downloader   File: DownloadsDB.java   Source Code and License Vote up 5 votes
public void updateDownloadCurrentBytes(final DownloadInfo di) {
    SQLiteStatement downloadCurrentBytes = getUpdateCurrentBytesStatement();
    downloadCurrentBytes.clearBindings();
    downloadCurrentBytes.bindLong(1, di.mCurrentBytes);
    downloadCurrentBytes.bindLong(2, di.mIndex);
    downloadCurrentBytes.execute();
}
 
Example 11
Project: buildAPKsApps   File: DataManager.java   Source Code and License Vote up 5 votes
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 12
Project: weex-uikit   File: DefaultWXStorage.java   Source Code and License Vote up 5 votes
private boolean performSetItem(String key, String value, boolean isPersistent, boolean allowRetryWhenFull) {
    SQLiteDatabase database = mDatabaseSupplier.getDatabase();
    if (database == null) {
        return false;
    }

    WXLogUtils.d(WXSQLiteOpenHelper.TAG_STORAGE, "set k-v to storage(key:" + key + ",value:" + value + ",isPersistent:" + isPersistent + ",allowRetry:" + allowRetryWhenFull + ")");
    String sql = "INSERT OR REPLACE INTO " + WXSQLiteOpenHelper.TABLE_STORAGE + " VALUES (?,?,?,?);";
    SQLiteStatement statement = null;
    String timeStamp = WXSQLiteOpenHelper.sDateFormatter.format(new Date());
    try {
        statement = database.compileStatement(sql);
        statement.clearBindings();
        statement.bindString(1, key);
        statement.bindString(2, value);
        statement.bindString(3, timeStamp);
        statement.bindLong(4, isPersistent ? 1 : 0);
        statement.execute();
        return true;
    } catch (Exception e) {
        WXLogUtils.e(WXSQLiteOpenHelper.TAG_STORAGE, "DefaultWXStorage occurred an exception when execute setItem :" + e.getMessage());
        if (e instanceof SQLiteFullException) {
            if (allowRetryWhenFull && trimToSize()) {
                //try again
                //setItem/setItemPersistent method only allow try once when occurred a sqliteFullException.
                WXLogUtils.d(WXSQLiteOpenHelper.TAG_STORAGE, "retry set k-v to storage(key:" + key + ",value:" + value + ")");
                return performSetItem(key, value, isPersistent, false);
            }
        }

        return false;
    } finally {
        if(statement != null) {
            statement.close();
        }
    }
}
 
Example 13
Project: buildAPKsApps   File: DataManager.java   Source Code and License Vote up 5 votes
public void updateListLabel(int listId, String newLabel)
{
    Log.d(L.TAG, "Updating label of list " + listId + " to " + newLabel);

    SQLiteDatabase db = helper.getWritableDatabase();
    SQLiteStatement stmt = db.compileStatement("update lists set label=? where id=?");        
    stmt.bindString(1, newLabel);
    stmt.bindLong(2, listId);
    stmt.execute();
    stmt.close();
    db.close();
}
 
Example 14
Project: buildAPKsApps   File: DataManager.java   Source Code and License Vote up 5 votes
public void moveItem(int itemId, int toListId)
{
    Log.d(L.TAG, "Moving item " + itemId + " to list " + toListId);
    
    SQLiteDatabase db = helper.getWritableDatabase();
    SQLiteStatement stmt = db.compileStatement("update items set list_id=? where id=?");        
    stmt.bindLong(1, toListId);
    stmt.bindLong(2, itemId);
    stmt.execute();
    stmt.close();
    db.close();
}
 
Example 15
Project: buildAPKsApps   File: DataManager.java   Source Code and License Vote up 5 votes
public void deleteInactive(int list_id)
{
    Log.d(L.TAG, "Deleting inactive items from list " + list_id);

    SQLiteDatabase db = helper.getWritableDatabase();
    SQLiteStatement stmt = db.compileStatement("delete from items where list_id=? and active=0");        
    stmt.bindLong(1, list_id);
    stmt.execute();
    stmt.close();
    db.close();
}
 
Example 16
Project: SlotNSlot_Android   File: DownloadsDB.java   Source Code and License Vote up 5 votes
public void updateDownloadCurrentBytes(final DownloadInfo di) {
    SQLiteStatement downloadCurrentBytes = getUpdateCurrentBytesStatement();
    downloadCurrentBytes.clearBindings();
    downloadCurrentBytes.bindLong(1, di.mCurrentBytes);
    downloadCurrentBytes.bindLong(2, di.mIndex);
    downloadCurrentBytes.execute();
}
 
Example 17
Project: SQLite-Performance   File: DbHelper.java   Source Code and License Vote up 5 votes
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 18
Project: MapaDeIgarassuAdmin   File: DataBaseUtil.java   Source Code and License Vote up 4 votes
public void deleteLocation(int locationId) {
    SQLiteDatabase db = this.getWritableDatabase();
    SQLiteStatement stmt = db.compileStatement(Constants.DELETE_LOCATION);
    stmt.bindLong(1, locationId);
    stmt.execute();
}
 
Example 19
Project: wallpaperboard   File: Database.java   Source Code and License Vote up 4 votes
public void add(@NonNull List<?> categoryLIst, @NonNull List<?> wallpaperList) {
    if (!openDatabase()) {
        LogUtil.e("Database error: add() failed to open database");
        return;
    }

    Iterator categoryIterator = categoryLIst.iterator();
    Iterator wallpaperIterator = wallpaperList.iterator();
    int size = categoryLIst.size() > wallpaperList.size() ? categoryLIst.size() : wallpaperList.size();

    String categoryQuery = "INSERT OR IGNORE INTO " +TABLE_CATEGORIES+ " (" +KEY_NAME+ ") VALUES (?);";
    String wallpaperQuery = "INSERT OR IGNORE INTO " +TABLE_WALLPAPERS+ " (" +KEY_NAME+ "," +KEY_AUTHOR+ "," +KEY_URL+ ","
            +KEY_THUMB_URL+ "," +KEY_CATEGORY+ "," +KEY_ADDED_ON+ ") VALUES (?,?,?,?,?,?);";

    SQLiteStatement categoryStatements = mDatabase.get().mSQLiteDatabase.compileStatement(categoryQuery);
    SQLiteStatement wallpaperStatements = mDatabase.get().mSQLiteDatabase.compileStatement(wallpaperQuery);
    mDatabase.get().mSQLiteDatabase.beginTransaction();

    int i = 0;
    do {
        categoryStatements.clearBindings();
        wallpaperStatements.clearBindings();

        if (categoryIterator.hasNext()) {
            Category category;
            if (categoryIterator.next() instanceof Category) {
                category = (Category) categoryLIst.get(i);
            } else {
                category = JsonHelper.getCategory(categoryLIst.get(i));
            }

            if (category != null) {
                categoryStatements.bindString(1, category.getName());
                categoryStatements.execute();
            }
        }

        if (wallpaperIterator.hasNext()) {
            Wallpaper wallpaper;
            if (wallpaperIterator.next() instanceof Wallpaper) {
                wallpaper = (Wallpaper) wallpaperList.get(i);
            } else {
                wallpaper = JsonHelper.getWallpaper(wallpaperList.get(i));
            }

            if (wallpaper != null) {
                if (wallpaper.getUrl() != null) {
                    String name = wallpaper.getName();
                    if (name == null) name = "";

                    wallpaperStatements.bindString(1, name);

                    if (wallpaper.getAuthor() != null) {
                        wallpaperStatements.bindString(2, wallpaper.getAuthor());
                    } else {
                        wallpaperStatements.bindNull(2);
                    }

                    wallpaperStatements.bindString(3, wallpaper.getUrl());
                    wallpaperStatements.bindString(4, wallpaper.getThumbUrl());
                    wallpaperStatements.bindString(5, wallpaper.getCategory());
                    wallpaperStatements.bindString(6, TimeHelper.getLongDateTime());
                    wallpaperStatements.execute();
                }
            }
        }
        i++;
    } while (i < size);

    mDatabase.get().mSQLiteDatabase.setTransactionSuccessful();
    mDatabase.get().mSQLiteDatabase.endTransaction();
}
 
Example 20
Project: wallpaperboard   File: Database.java   Source Code and License Vote up 4 votes
public void addWallpapers(@NonNull List<?> list) {
    if (!openDatabase()) {
        LogUtil.e("Database error: addWallpapers() failed to open database");
        return;
    }

    String query = "INSERT OR IGNORE INTO " +TABLE_WALLPAPERS+ " (" +KEY_NAME+ "," +KEY_AUTHOR+ "," +KEY_URL+ ","
            +KEY_THUMB_URL+ "," +KEY_CATEGORY+ "," +KEY_ADDED_ON+ ") VALUES (?,?,?,?,?,?);";
    SQLiteStatement statement = mDatabase.get().mSQLiteDatabase.compileStatement(query);
    mDatabase.get().mSQLiteDatabase.beginTransaction();

    for (int i = 0; i < list.size(); i++) {
        statement.clearBindings();

        Wallpaper wallpaper;
        if (list.get(i) instanceof Wallpaper) {
            wallpaper = (Wallpaper) list.get(i);
        } else {
            wallpaper = JsonHelper.getWallpaper(list.get(i));
        }

        if (wallpaper != null) {
            if (wallpaper.getUrl() != null) {
                String name = wallpaper.getName();
                if (name == null) name = "";

                statement.bindString(1, name);

                if (wallpaper.getAuthor() != null) {
                    statement.bindString(2, wallpaper.getAuthor());
                } else {
                    statement.bindNull(2);
                }

                statement.bindString(3, wallpaper.getUrl());
                statement.bindString(4, wallpaper.getThumbUrl());
                statement.bindString(5, wallpaper.getCategory());
                statement.bindString(6, TimeHelper.getLongDateTime());
                statement.execute();
            }
        }
    }
    mDatabase.get().mSQLiteDatabase.setTransactionSuccessful();
    mDatabase.get().mSQLiteDatabase.endTransaction();
}