Java Code Examples for android.database.sqlite.SQLiteDoneException

The following examples show how to use android.database.sqlite.SQLiteDoneException. 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
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 Project: NetGuard   Source File: DatabaseHelper.java    License: 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 Project: QtAndroidTools   Source File: DownloadsDB.java    License: 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 Project: Meteorite   Source File: BaseQueriable.java    License: 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
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
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 Project: play-apk-expansion   Source File: DownloadsDB.java    License: 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 Project: sqlitemagic   Source File: Column.java    License: 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 Project: travelguide   Source File: DownloadsDB.java    License: 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 Project: Alite   Source File: DownloadsDB.java    License: 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 Project: Mover   Source File: SqliteJobQueue.java    License: 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 Project: UnityOBBDownloader   Source File: DownloadsDB.java    License: 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 Project: XPrivacy   Source File: PrivacyService.java    License: 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());
	}
}