android.database.sqlite.SQLiteDoneException Java Examples

The following examples show how to use android.database.sqlite.SQLiteDoneException. 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: DatabaseHelper.java    From tracker-control-android with GNU General Public License v3.0 6 votes vote down vote up
public String getQName(int uid, String ip) {
    lock.readLock().lock();
    try {
        // Custom code
        if (readableDb == null)
            readableDb = this.getReadableDatabase();
        SQLiteDatabase db = readableDb;
        // There is a segmented index on resource
        String query = "SELECT d.qname";
        query += " FROM dns AS d";
        query += " WHERE d.resource = '" + ip.replace("'", "''") + "'";
        query += " ORDER BY d.qname";
        query += " LIMIT 1";
        // There is no way to known for sure which domain name an app used, so just pick the first one
        return db.compileStatement(query).simpleQueryForString();
    } catch (SQLiteDoneException ignored) {
        // Not found
        return null;
    } finally {
        lock.readLock().unlock();
    }
}
 
Example #2
Source File: DatabaseHelper.java    From NetGuard with GNU General Public License v3.0 6 votes vote down vote up
public String getQName(int uid, String ip) {
    lock.readLock().lock();
    try {
        SQLiteDatabase db = this.getReadableDatabase();
        // There is a segmented index on resource
        String query = "SELECT d.qname";
        query += " FROM dns AS d";
        query += " WHERE d.resource = '" + ip.replace("'", "''") + "'";
        query += " ORDER BY d.qname";
        query += " LIMIT 1";
        // There is no way to known for sure which domain name an app used, so just pick the first one
        return db.compileStatement(query).simpleQueryForString();
    } catch (SQLiteDoneException ignored) {
        // Not found
        return null;
    } finally {
        lock.readLock().unlock();
    }
}
 
Example #3
Source File: DownloadsDB.java    From QtAndroidTools with MIT License 5 votes vote down vote up
public long getIDByIndex(int index) {
    SQLiteStatement downloadByIndex = getDownloadByIndexStatement();
    downloadByIndex.clearBindings();
    downloadByIndex.bindLong(1, index);
    try {
        return downloadByIndex.simpleQueryForLong();
    } catch (SQLiteDoneException e) {
        return -1;
    }
}
 
Example #4
Source File: BaseQueriable.java    From Meteorite with Apache License 2.0 5 votes vote down vote up
/**
 * Execute a statement that returns a 1 by 1 table with a numeric value.
 * For example, SELECT COUNT(*) FROM table.
 * Please see {@link SQLiteStatement#simpleQueryForLong()}.
 * <p>
 * catches a {@link SQLiteDoneException} if result is not found and returns 0. The error can safely be ignored.
 */
@Override
public long count(@NonNull DatabaseWrapper databaseWrapper) {
    try {
        String query = getQuery();
        FlowLog.log(FlowLog.Level.V, "Executing query: " + query);
        return SqlUtils.longForQuery(databaseWrapper, query);
    } catch (SQLiteDoneException sde) {
        // catch exception here, log it but return 0;
        FlowLog.log(FlowLog.Level.W, sde);
    }
    return 0;
}
 
Example #5
Source File: NotificationCountStorage.java    From revolution-irc with GNU General Public License v3.0 5 votes vote down vote up
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;
    }
}
 
Example #6
Source File: NotificationCountStorage.java    From revolution-irc with GNU General Public License v3.0 5 votes vote down vote up
private String getFirstMessageId(UUID server, String channel) {
    synchronized (mDatabaseLock) {
        waitForDatabase();
        mGetFirstMessageIdStatement.bindString(1, server.toString());
        mGetFirstMessageIdStatement.bindString(2, channel);
        String ret;
        try {
            ret = mGetFirstMessageIdStatement.simpleQueryForString();
        } catch (SQLiteDoneException ignored) {
            ret = null;
        }
        mGetFirstMessageIdStatement.clearBindings();
        return ret;
    }
}
 
Example #7
Source File: DownloadsDB.java    From play-apk-expansion with Apache License 2.0 5 votes vote down vote up
public long getIDByIndex(int index) {
    SQLiteStatement downloadByIndex = getDownloadByIndexStatement();
    downloadByIndex.clearBindings();
    downloadByIndex.bindLong(1, index);
    try {
        return downloadByIndex.simpleQueryForLong();
    } catch (SQLiteDoneException e) {
        return -1;
    }
}
 
Example #8
Source File: Column.java    From sqlitemagic with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@androidx.annotation.Nullable
<V> V getFromStatement(@NonNull SupportSQLiteStatement stm) {
  try {
    return (V) valueParser.parseFromStatement(stm);
  } catch (SQLiteDoneException e) {
    // query returned no results
  }
  return null;
}
 
Example #9
Source File: DownloadsDB.java    From travelguide with Apache License 2.0 5 votes vote down vote up
public long getIDByIndex(int index) {
    SQLiteStatement downloadByIndex = getDownloadByIndexStatement();
    downloadByIndex.clearBindings();
    downloadByIndex.bindLong(1, index);
    try {
        return downloadByIndex.simpleQueryForLong();
    } catch (SQLiteDoneException e) {
        return -1;
    }
}
 
Example #10
Source File: DownloadsDB.java    From Alite with GNU General Public License v3.0 5 votes vote down vote up
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 File: SqliteJobQueue.java    From Mover with Apache License 2.0 5 votes vote down vote up
/**
 * {@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 #12
Source File: DownloadsDB.java    From UnityOBBDownloader with Apache License 2.0 5 votes vote down vote up
public long getIDByIndex(int index) {
    SQLiteStatement downloadByIndex = getDownloadByIndexStatement();
    downloadByIndex.clearBindings();
    downloadByIndex.bindLong(1, index);
    try {
        return downloadByIndex.simpleQueryForLong();
    } catch (SQLiteDoneException e) {
        return -1;
    }
}
 
Example #13
Source File: PrivacyService.java    From XPrivacy with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean isRestrictionSet(PRestriction restriction) throws RemoteException {
	try {
		// No permissions required
		boolean set = false;

		SQLiteDatabase db = getDb();
		if (db != null) {
			// Precompile statement when needed
			if (stmtGetRestriction == null) {
				String sql = "SELECT restricted FROM " + cTableRestriction
						+ " WHERE uid=? AND restriction=? AND method=?";
				stmtGetRestriction = db.compileStatement(sql);
			}

			// Execute statement
			mLock.readLock().lock();
			try {
				db.beginTransaction();
				try {
					try {
						synchronized (stmtGetRestriction) {
							stmtGetRestriction.clearBindings();
							stmtGetRestriction.bindLong(1, restriction.uid);
							stmtGetRestriction.bindString(2, restriction.restrictionName);
							stmtGetRestriction.bindString(3, restriction.methodName);
							stmtGetRestriction.simpleQueryForLong();
							set = true;
						}
					} catch (SQLiteDoneException ignored) {
					}

					db.setTransactionSuccessful();
				} finally {
					db.endTransaction();
				}
			} finally {
				mLock.readLock().unlock();
			}
		}

		return set;
	} catch (Throwable ex) {
		Util.bug(null, ex);
		throw new RemoteException(ex.toString());
	}
}