public String getQName(int uid, String ip) { lock.readLock().lock(); try { SQLiteDatabase db = this.getReadableDatabase(); // There is a segmented index on resource // There is an index on access.daddr String query = "SELECT d.qname"; query += " FROM dns AS d"; query += " LEFT JOIN access AS a"; query += " ON a.daddr = d.qname AND a.uid = " + uid; query += " WHERE d.resource = '" + ip.replace("'", "''") + "'"; query += " ORDER BY CASE a.daddr WHEN NULL THEN 1 ELSE 0 END, d.qname"; query += " LIMIT 1"; return db.compileStatement(query).simpleQueryForString(); } catch (SQLiteDoneException ignored) { // Not found return null; } finally { lock.readLock().unlock(); } }
public String getQName(String ip) { mLock.readLock().lock(); try { SQLiteDatabase db = this.getReadableDatabase(); // There is a segmented index on resource String query = "SELECT qname"; query += " FROM dns"; query += " WHERE resource = '" + ip.replace("'", "''") + "'"; query += " ORDER BY time DESC"; query += " LIMIT 1"; return db.compileStatement(query).simpleQueryForString(); } catch (SQLiteDoneException ignored) { // Not found return null; } finally { mLock.readLock().unlock(); } }
public final String a(SQLiteDatabase paramSQLiteDatabase, String paramString) { if (paramString == null) { return null; } try { String str1 = this.z; String[] arrayOfString = new String[2]; arrayOfString[0] = this.s; arrayOfString[1] = paramString; String str2 = DatabaseUtils.stringForQuery(paramSQLiteDatabase, str1, arrayOfString); return str2; } catch (SQLiteDoneException localSQLiteDoneException) {} return null; }
public final long b(int paramInt, String paramString, long paramLong) { SQLiteDatabase localSQLiteDatabase = hsb.b(this.a, paramInt); try { String str = this.b; long l = DatabaseUtils.longForQuery(localSQLiteDatabase, 13 + String.valueOf(paramString).length() + String.valueOf(str).length() + "SELECT " + paramString + " FROM " + str, null); return l; } catch (SQLiteException localSQLiteException) { return -1L; } catch (SQLiteDoneException localSQLiteDoneException) {} return -1L; }
public static boolean e(Context paramContext, int paramInt) { SQLiteDatabase localSQLiteDatabase = bqj.a(paramContext, paramInt).getReadableDatabase(); try { long l = DatabaseUtils.longForQuery(localSQLiteDatabase, "SELECT wipeout_stats FROM account_status", null); boolean bool1 = l < 1L; boolean bool2 = false; if (!bool1) { bool2 = true; } return bool2; } catch (SQLiteDoneException localSQLiteDoneException) {} return false; }
private String r() { SQLiteDatabase localSQLiteDatabase = bqj.a(this.l, this.h).getReadableDatabase(); String[] arrayOfString; if (!TextUtils.isEmpty(this.d)) { arrayOfString = new String[2]; arrayOfString[0] = this.d; arrayOfString[1] = this.f; } try { String str = DatabaseUtils.stringForQuery(localSQLiteDatabase, "SELECT tile_id FROM all_tiles WHERE photo_id = ? AND view_id = ?", arrayOfString); if (!TextUtils.equals(str, this.e)) { this.e = str; } label71: return this.e; } catch (SQLiteDoneException localSQLiteDoneException) { break label71; } }
public int getProjectId(String languageCode, String slug, String version) throws IllegalArgumentException { // Logger.w(this.toString(), "Trying to get project Id for " + languageCode + " " + slug + " " + version); String languageId = String.valueOf(getLanguageId(languageCode)); String bookId = String.valueOf(getBookId(slug)); SQLiteDatabase db = getReadableDatabase(); final String projectIdQuery = String.format("SELECT %s FROM %s WHERE %s=? AND %s=? AND %s=?", ProjectContract.ProjectEntry._ID, ProjectContract.ProjectEntry.TABLE_PROJECT, ProjectContract.ProjectEntry.PROJECT_TARGET_LANGUAGE_FK, ProjectContract.ProjectEntry.PROJECT_BOOK_FK, ProjectContract.ProjectEntry.PROJECT_VERSION); int id = -1; try { id = (int) DatabaseUtils.longForQuery(db, projectIdQuery, new String[]{languageId, bookId, version}); } catch (SQLiteDoneException e) { //db.close(); throw new IllegalArgumentException("Project not found in database"); } //db.close(); return id; }
public int getChapterId(String languageCode, String slug, String version, int chapter){ // Logger.w(this.toString(), "trying to get chapter id for chapter " + chapter); String projectId = String.valueOf(getProjectId(languageCode, slug, version)); SQLiteDatabase db = getReadableDatabase(); final String chapterIdQuery = String.format("SELECT %s FROM %s WHERE %s=? AND %s=?", ProjectContract.ChapterEntry._ID, ProjectContract.ChapterEntry.TABLE_CHAPTER, ProjectContract.ChapterEntry.CHAPTER_PROJECT_FK, ProjectContract.ChapterEntry.CHAPTER_NUMBER); int id = -1; try { id = (int) DatabaseUtils.longForQuery(db, chapterIdQuery, new String[]{projectId, String.valueOf(chapter)}); } catch (SQLiteDoneException e){ //db.close(); throw new IllegalArgumentException("Chapter not found in database"); } //db.close(); return id; }
public int getUnitId(String languageCode, String slug, String version, int chapter, int startVerse) throws IllegalArgumentException{ // Logger.w(this.toString(), "Trying to get unit Id for start verse " + startVerse); String projectId = String.valueOf(getProjectId(languageCode, slug, version)); String chapterId = String.valueOf(getChapterId(languageCode, slug, version, chapter)); SQLiteDatabase db = getReadableDatabase(); final String unitIdQuery = String.format("SELECT %s FROM %s WHERE %s=? AND %s=? AND %s=?", ProjectContract.UnitEntry._ID, ProjectContract.UnitEntry.TABLE_UNIT, ProjectContract.UnitEntry.UNIT_PROJECT_FK, ProjectContract.UnitEntry.UNIT_CHAPTER_FK, ProjectContract.UnitEntry.UNIT_START_VERSE); int id = -1; try { id = (int) DatabaseUtils.longForQuery(db, unitIdQuery, new String[]{projectId, chapterId, String.valueOf(startVerse)}); } catch (SQLiteDoneException e){ //db.close(); throw new IllegalArgumentException("Unit not found in database"); } //db.close(); return id; }
public int getTakeId(FileNameExtractor fne) throws IllegalArgumentException{ Logger.w(this.toString(), "Attempting to get take id for " + fne.getLang() + " " + fne.getBook() + " " + fne.getSource() + " verse start " + fne.getStartVerse() + " take " + fne.getTake()); String unitId = String.valueOf(getUnitId(fne.getLang(), fne.getBook(), fne.getSource(), fne.getChapter(), fne.getStartVerse())); SQLiteDatabase db = getReadableDatabase(); final String takeIdQuery = String.format("SELECT %s FROM %s WHERE %s=? AND %s=?", ProjectContract.TakeEntry._ID, ProjectContract.TakeEntry.TABLE_TAKE, ProjectContract.TakeEntry.TAKE_UNIT_FK, ProjectContract.TakeEntry.TAKE_NUMBER); int id = -1; try { id = (int) DatabaseUtils.longForQuery(db, takeIdQuery, new String[]{unitId, String.valueOf(fne.getTake())}); } catch (SQLiteDoneException e){ //db.close(); throw new IllegalArgumentException("Take not found in database."); } //db.close(); return id; }
/** * Check for the existence of an identity. * @param identityName The name of the identity. * @return True if the identity exists, otherwise false. * @throws PibImpl.Error for a non-semantic (database access) error. */ public boolean hasIdentity(Name identityName) throws PibImpl.Error { // Use a statement because it allows binding a blob for the query. SQLiteStatement statement = database_.compileStatement(SELECT_hasIdentity); try { statement.bindBlob(1, identityName.wireEncode().getImmutableArray()); try { statement.simpleQueryForLong(); return true; } catch (SQLiteDoneException ex) { // No match. return false; } } finally { statement.close(); } }
/** * Check for the existence of a key with keyName. * @param keyName The name of the key. * @return True if the key exists, otherwise false. Return false if the * identity does not exist. * @throws PibImpl.Error for a non-semantic (database access) error. */ public boolean hasKey(Name keyName) throws PibImpl.Error { // Use a statement because it allows binding a blob for the query. SQLiteStatement statement = database_.compileStatement(SELECT_hasKey); try { statement.bindBlob(1, keyName.wireEncode().getImmutableArray()); try { statement.simpleQueryForLong(); return true; } catch (SQLiteDoneException ex) { // No match. return false; } } finally { statement.close(); } }
/** * Check for the existence of a certificate with name certificateName. * @param certificateName The name of the certificate. * @return True if the certificate exists, otherwise false. * @throws PibImpl.Error for a non-semantic (database access) error. */ public boolean hasCertificate(Name certificateName) throws PibImpl.Error { // Use a statement because it allows binding a blob for the query. SQLiteStatement statement = database_.compileStatement(SELECT_hasCertificate); try { statement.bindBlob(1, certificateName.wireEncode().getImmutableArray()); try { statement.simpleQueryForLong(); return true; } catch (SQLiteDoneException ex) { // No match. return false; } } finally { statement.close(); } }
private boolean hasDefaultIdentity() throws PibImpl.Error { // Use a statement because it allows binding a blob for the query. SQLiteStatement statement = database_.compileStatement (SELECT_hasDefaultIdentity); try { try { statement.simpleQueryForLong(); return true; } catch (SQLiteDoneException ex) { // No match. return false; } } finally { statement.close(); } }
private boolean hasDefaultKeyOfIdentity(Name identityName) throws PibImpl.Error { // Use a statement because it allows binding a blob for the query. SQLiteStatement statement = database_.compileStatement (SELECT_hasDefaultKeyOfIdentity); try { statement.bindBlob(1, identityName.wireEncode().getImmutableArray()); try { statement.simpleQueryForLong(); return true; } catch (SQLiteDoneException ex) { // No match. return false; } } finally { statement.close(); } }
private boolean hasDefaultCertificateOfKey(Name keyName) throws PibImpl.Error { // Use a statement because it allows binding a blob for the query. SQLiteStatement statement = database_.compileStatement (SELECT_hasDefaultCertificateOfKey); try { statement.bindBlob(1, keyName.wireEncode().getImmutableArray()); try { statement.simpleQueryForLong(); return true; } catch (SQLiteDoneException ex) { // No match. return false; } } finally { statement.close(); } }
/** * Check if there is a member with the given identity name. * @param identity The member's identity name. * @return True if there is a member. * @throws GroupManagerDb.Error for a database error. */ public boolean hasMember(Name identity) throws GroupManagerDb.Error { // Use a statement because it allows binding a blob for the query. SQLiteStatement statement = database_.compileStatement(SELECT_hasMember); try { statement.bindBlob (1, identity.wireEncode(TlvWireFormat.get()).getImmutableArray()); try { statement.simpleQueryForLong(); return true; } catch (SQLiteDoneException ex) { // No match. return false; } } finally { statement.close(); } }
/** * Get the name of the schedule for the given member's identity name. * @param identity The member's identity name. * @return The name of the schedule. * @throws GroupManagerDb.Error if there's no member with the given identity * name in the database, or other database error. */ public String getMemberSchedule(Name identity) throws GroupManagerDb.Error { // Use a statement because it allows binding a blob for the query. SQLiteStatement statement = database_.compileStatement (SELECT_getMemberSchedule); try { statement.bindBlob (1, identity.wireEncode(TlvWireFormat.get()).getImmutableArray()); try { return statement.simpleQueryForString(); } catch (SQLiteDoneException ex) { throw new GroupManagerDb.Error ("AndroidSqlite3GroupManagerDb.getMemberSchedule: Cannot get the result from the database"); } } finally { statement.close(); } }
/** * Check if there is an EKey with the name eKeyName in the database. * @param eKeyName The name of the EKey. * @return True if the EKey exists. * @throws GroupManagerDb.Error for a database error. */ public boolean hasEKey(Name eKeyName) throws GroupManagerDb.Error { // Use a statement because it allows binding a blob for the query. SQLiteStatement statement = database_.compileStatement(SELECT_hasEKey); try { statement.bindBlob (1, eKeyName.wireEncode(TlvWireFormat.get()).getImmutableArray()); try { statement.simpleQueryForLong(); return true; } catch (SQLiteDoneException ex) { // No match. return false; } } finally { statement.close(); } }
/** * Checking whether a site is already existed check is done by matching rss * link * */ public static boolean isItemExists( String item_link) { SQLiteDatabase db = GRSSDbHandler.getInstance().getReadableDatabase(); boolean bexists = false; String queryStr = "SELECT 1 FROM " + TABLE_RSSITEM + " WHERE " + KEY_LINK + " = ?"; try{ SQLiteStatement stmt = db.compileStatement(queryStr); stmt.bindString(1, item_link); long ret = stmt. simpleQueryForLong(); bexists = true; } catch (SQLiteDoneException e) { bexists = false; } finally{ db.close(); } return bexists; }
@TargetApi(Build.VERSION_CODES.HONEYCOMB) public TileReader getTileApi11(Tile tile) { InputStream in = null; mStmtGetTile.bindLong(1, tile.tileX); mStmtGetTile.bindLong(2, tile.tileY); mStmtGetTile.bindLong(3, tile.zoomLevel); try { ParcelFileDescriptor result = mStmtGetTile.simpleQueryForBlobFileDescriptor(); in = new FileInputStream(result.getFileDescriptor()); } catch (SQLiteDoneException e) { log.debug("not in cache {}", tile); return null; } finally { mStmtGetTile.clearBindings(); } if (dbg) log.debug("load tile {}", tile); return new CacheTileReader(tile, in); }
private int getChannelCounter(UUID server, String channel) { synchronized (mDatabaseLock) { waitForDatabase(); mGetNotificationCountStatement.bindString(1, server.toString()); mGetNotificationCountStatement.bindString(2, channel); long ret; try { ret = mGetNotificationCountStatement.simpleQueryForLong(); } catch (SQLiteDoneException e) { ret = 0; } mGetNotificationCountStatement.clearBindings(); return (int) ret; } }
public long getIDByIndex(int index) { SQLiteStatement downloadByIndex = getDownloadByIndexStatement(); downloadByIndex.clearBindings(); downloadByIndex.bindLong(1, index); try { return downloadByIndex.simpleQueryForLong(); } catch (SQLiteDoneException e) { return -1; } }
@SuppressWarnings("unchecked") @android.support.annotation.Nullable <V> V getFromStatement(@NonNull SupportSQLiteStatement stm) { try { return (V) valueParser.parseFromStatement(stm); } catch (SQLiteDoneException e) { // query returned no results } return null; }