Java Code Examples for android.database.sqlite.SQLiteStatement#simpleQueryForLong()
The following examples show how to use
android.database.sqlite.SQLiteStatement#simpleQueryForLong() .
These examples are extracted from open source projects.
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 Project: ucar-weex-core File: DefaultWXStorage.java License: Apache License 2.0 | 6 votes |
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 2
Source Project: weex-uikit File: DefaultWXStorage.java License: MIT License | 6 votes |
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 3
Source Project: ApkTrack File: SugarRecord.java License: GNU General Public License v3.0 | 6 votes |
public static <T> long count(Class<?> type, String whereClause, String[] whereArgs, String groupBy, String orderBy, String limit) { long result = -1; String filter = (!TextUtils.isEmpty(whereClause)) ? " where " + whereClause : ""; SQLiteStatement sqliteStatement; try { sqliteStatement = getSugarDataBase().compileStatement("SELECT count(*) FROM " + NamingHelper.toSQLName(type) + filter); } catch (SQLiteException e) { e.printStackTrace(); return result; } if (whereArgs != null) { for (int i = whereArgs.length; i != 0; i--) { sqliteStatement.bindString(i, whereArgs[i - 1]); } } try { result = sqliteStatement.simpleQueryForLong(); } finally { sqliteStatement.close(); } return result; }
Example 4
Source Project: QtAndroidTools File: DownloadsDB.java License: MIT License | 5 votes |
public long getIDByIndex(int index) { SQLiteStatement downloadByIndex = getDownloadByIndexStatement(); downloadByIndex.clearBindings(); downloadByIndex.bindLong(1, index); try { return downloadByIndex.simpleQueryForLong(); } catch (SQLiteDoneException e) { return -1; } }
Example 5
Source Project: play-apk-expansion File: DownloadsDB.java License: Apache License 2.0 | 5 votes |
public long getIDByIndex(int index) { SQLiteStatement downloadByIndex = getDownloadByIndexStatement(); downloadByIndex.clearBindings(); downloadByIndex.bindLong(1, index); try { return downloadByIndex.simpleQueryForLong(); } catch (SQLiteDoneException e) { return -1; } }
Example 6
Source Project: EasyVPN-Free File: DBHelper.java License: GNU General Public License v3.0 | 5 votes |
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 7
Source Project: EasyVPN-Free File: DBHelper.java License: GNU General Public License v3.0 | 5 votes |
public long getCountBasic() { SQLiteDatabase db = this.getWritableDatabase(); SQLiteStatement statement = db.compileStatement("SELECT COUNT(*) FROM " + TABLE_SERVERS + " WHERE " + KEY_TYPE + " = 0"); long count = statement.simpleQueryForLong(); db.close(); return count; }
Example 8
Source Project: EasyVPN-Free File: DBHelper.java License: GNU General Public License v3.0 | 5 votes |
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 9
Source Project: ormlite-android File: AndroidDatabaseConnection.java License: ISC License | 5 votes |
@Override public long queryForLong(String statement) throws SQLException { SQLiteStatement stmt = null; try { stmt = db.compileStatement(statement); long result = stmt.simpleQueryForLong(); logger.trace("{}: query for long simple query returned {}: {}", this, result, statement); return result; } catch (android.database.SQLException e) { throw SqlExceptionUtil.create("queryForLong from database failed: " + statement, e); } finally { closeQuietly(stmt); } }
Example 10
Source Project: Alite File: DownloadsDB.java License: GNU General Public License v3.0 | 5 votes |
public long getIDByIndex(int index) { SQLiteStatement downloadByIndex = getDownloadByIndexStatement(); downloadByIndex.clearBindings(); downloadByIndex.bindLong(1, index); try { return downloadByIndex.simpleQueryForLong(); } catch (SQLiteDoneException e) { return -1; } }
Example 11
Source Project: squidb File: SQLiteDatabaseAdapter.java License: Apache License 2.0 | 5 votes |
@Override public long simpleQueryForLong(String sql, Object[] bindArgs) { SQLiteStatement statement = null; try { statement = db.compileStatement(sql); SquidCursorFactory.bindArgumentsToProgram(statement, bindArgs); return statement.simpleQueryForLong(); } finally { if (statement != null) { statement.close(); } } }
Example 12
Source Project: Applozic-Android-SDK File: DBUtils.java License: BSD 3-Clause "New" or "Revised" License | 5 votes |
public static boolean isTableEmpty(SQLiteDatabase database, String table) { String sql = "SELECT COUNT(*) FROM " + table; SQLiteStatement statement = database.compileStatement(sql); long records = statement.simpleQueryForLong(); statement.close(); return records == 0; }
Example 13
Source Project: Mover File: SqliteJobQueue.java License: Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public int count() { SQLiteStatement stmt = sqlHelper.getCountStatement(); synchronized (stmt) { stmt.clearBindings(); stmt.bindLong(1, sessionId); return (int) stmt.simpleQueryForLong(); } }
Example 14
Source Project: Mover File: SqliteJobQueue.java License: Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public Long getNextJobDelayUntilNs(boolean hasNetwork) { SQLiteStatement stmt = hasNetwork ? sqlHelper.getNextJobDelayedUntilWithNetworkStatement() : sqlHelper.getNextJobDelayedUntilWithoutNetworkStatement(); synchronized (stmt) { try { stmt.clearBindings(); return stmt.simpleQueryForLong(); } catch (SQLiteDoneException e){ return null; } } }
Example 15
Source Project: HayaiLauncher File: LaunchableActivityPrefs.java License: Apache License 2.0 | 5 votes |
public void writePreference(String className, long number, int priority, int usageQuantity) { Log.d("LaunchablePrefs", "writePreference running"); final SQLiteDatabase db = getWritableDatabase(); final SQLiteStatement countStatement = db.compileStatement(String.format( "SELECT COUNT(*) FROM %s WHERE %s = ?", TABLE_NAME, KEY_CLASSNAME)); countStatement.bindString(1, className); final long count = countStatement.simpleQueryForLong(); countStatement.close(); final SQLiteStatement statement; if (count == 0) { statement = db.compileStatement("INSERT INTO " + TABLE_NAME + " (" + KEY_CLASSNAME + ", " + KEY_LASTLAUNCHTIMESTAMP + "," + KEY_FAVORITE + "," + KEY_USAGEQUANTIY + ") VALUES(?,?,?,?)"); statement.bindString(1, className); statement.bindLong(2, number); statement.bindLong(3, priority); statement.bindLong(4, usageQuantity); } else { statement = db.compileStatement("UPDATE " + TABLE_NAME + " SET " + KEY_LASTLAUNCHTIMESTAMP + "=? , " + KEY_FAVORITE + "=? , " + KEY_USAGEQUANTIY + "=? WHERE " + KEY_CLASSNAME + "=?"); statement.bindLong(1, number); statement.bindLong(2, priority); statement.bindLong(3, usageQuantity); statement.bindString(4, className); } statement.executeInsert(); statement.close(); db.close(); }
Example 16
Source Project: UnityOBBDownloader File: DownloadsDB.java License: Apache License 2.0 | 5 votes |
public long getIDByIndex(int index) { SQLiteStatement downloadByIndex = getDownloadByIndexStatement(); downloadByIndex.clearBindings(); downloadByIndex.bindLong(1, index); try { return downloadByIndex.simpleQueryForLong(); } catch (SQLiteDoneException e) { return -1; } }
Example 17
Source Project: android_9.0.0_r45 File: DatabaseUtils.java License: Apache License 2.0 | 4 votes |
/** * Utility method to run the pre-compiled query and return the value in the * first column of the first row. */ public static long longForQuery(SQLiteStatement prog, String[] selectionArgs) { prog.bindAllArgsAsStrings(selectionArgs); return prog.simpleQueryForLong(); }
Example 18
Source Project: styT File: noteEdit.java License: Apache License 2.0 | 4 votes |
@Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); if (id == R.id.sort_e) { String content = et_content.getText().toString(); // Log.d("LOG1", content); // 获取写日志时间 Date date = new Date(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); String dateNum = sdf.format(date); String sql; String sql_count = "SELECT COUNT(*) FROM note"; SQLiteStatement statement = dbread.compileStatement(sql_count); long count = statement.simpleQueryForLong(); // Log.d("COUNT", count + ""); //Log.d("ENTER_STATE", ENTER_STATE + ""); // 添加一个新的日志 if (ENTER_STATE == 0) { if (!content.equals("")) { sql = "insert into " + NotesDB.TABLE_NAME_NOTES + " values(" + count + "," + "'" + content + "'" + "," + "'" + dateNum + "')"; // Log.d("LOG", sql); Toast.makeText(noteEdit.this, "保存成功", Toast.LENGTH_SHORT).show(); dbread.execSQL(sql); } } // 查看并修改一个已有的日志 else { Toast.makeText(noteEdit.this, "更新成功", Toast.LENGTH_SHORT).show(); // Log.d("执行命令", "执行了该函数"); String updatesql = "update note set content='" + content + "' where _id=" + id; dbread.execSQL(updatesql); // et_content.setText(last_content); } Intent data = new Intent(); setResult(2, data); finish(); } return super.onOptionsItemSelected(item); }
Example 19
Source Project: OpenCircle File: UpdateUtil.java License: GNU General Public License v3.0 | 3 votes |
public static boolean isAdded(SQLiteDatabase db, String remote_id, String TABLE_NAME){ String select_string = "select count(*) from "+TABLE_NAME+" where remote_id='" + remote_id + "'; "; SQLiteStatement s = db.compileStatement(select_string ); long count = s.simpleQueryForLong(); if(count > 0){ return true; } return false; }
Example 20
Source Project: azure-mobile-apps-android-client File: SQLiteStoreTestsUtilities.java License: Apache License 2.0 | 3 votes |
public long countRows(String tableName) { SQLiteDatabase db = this.getReadableDatabase(); String countQuery = "SELECT COUNT(1) from " + tableName; SQLiteStatement s = db.compileStatement(countQuery); long count = s.simpleQueryForLong(); return count; }