Use Cursor.getColumnIndexOrThrow()

This commit is contained in:
Marvin W 2021-03-17 19:21:59 +01:00
parent 1516af4395
commit c9e09e9714
No known key found for this signature in database
GPG Key ID: 072E9235DB996F2A
4 changed files with 22 additions and 33 deletions

View File

@ -1,17 +1,6 @@
/*
* Copyright (C) 2013-2017 microG Project Team
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* SPDX-FileCopyrightText: 2016, microG Project Team
* SPDX-License-Identifier: Apache-2.0
*/
package org.microg.gms.gcm;
@ -81,13 +70,13 @@ public class GcmDatabase extends SQLiteOpenHelper {
public final boolean wakeForDelivery;
private App(Cursor cursor) {
packageName = cursor.getString(cursor.getColumnIndex(FIELD_PACKAGE_NAME));
lastError = cursor.getString(cursor.getColumnIndex(FIELD_LAST_ERROR));
lastMessageTimestamp = cursor.getLong(cursor.getColumnIndex(FIELD_LAST_MESSAGE_TIMESTAMP));
totalMessageCount = cursor.getLong(cursor.getColumnIndex(FIELD_TOTAL_MESSAGE_COUNT));
totalMessageBytes = cursor.getLong(cursor.getColumnIndex(FIELD_TOTAL_MESSAGE_BYTES));
allowRegister = cursor.getLong(cursor.getColumnIndex(FIELD_ALLOW_REGISTER)) == 1;
wakeForDelivery = cursor.getLong(cursor.getColumnIndex(FIELD_WAKE_FOR_DELIVERY)) == 1;
packageName = cursor.getString(cursor.getColumnIndexOrThrow(FIELD_PACKAGE_NAME));
lastError = cursor.getString(cursor.getColumnIndexOrThrow(FIELD_LAST_ERROR));
lastMessageTimestamp = cursor.getLong(cursor.getColumnIndexOrThrow(FIELD_LAST_MESSAGE_TIMESTAMP));
totalMessageCount = cursor.getLong(cursor.getColumnIndexOrThrow(FIELD_TOTAL_MESSAGE_COUNT));
totalMessageBytes = cursor.getLong(cursor.getColumnIndexOrThrow(FIELD_TOTAL_MESSAGE_BYTES));
allowRegister = cursor.getLong(cursor.getColumnIndexOrThrow(FIELD_ALLOW_REGISTER)) == 1;
wakeForDelivery = cursor.getLong(cursor.getColumnIndexOrThrow(FIELD_WAKE_FOR_DELIVERY)) == 1;
}
public boolean hasError() {
@ -102,10 +91,10 @@ public class GcmDatabase extends SQLiteOpenHelper {
public final String registerId;
public Registration(Cursor cursor) {
packageName = cursor.getString(cursor.getColumnIndex(FIELD_PACKAGE_NAME));
signature = cursor.getString(cursor.getColumnIndex(FIELD_SIGNATURE));
timestamp = cursor.getLong(cursor.getColumnIndex(FIELD_TIMESTAMP));
registerId = cursor.getString(cursor.getColumnIndex(FIELD_REGISTER_ID));
packageName = cursor.getString(cursor.getColumnIndexOrThrow(FIELD_PACKAGE_NAME));
signature = cursor.getString(cursor.getColumnIndexOrThrow(FIELD_SIGNATURE));
timestamp = cursor.getLong(cursor.getColumnIndexOrThrow(FIELD_TIMESTAMP));
registerId = cursor.getString(cursor.getColumnIndexOrThrow(FIELD_REGISTER_ID));
}
}

View File

@ -51,7 +51,7 @@ public class PeopleManager {
String url = null;
if (cursor.moveToNext()) {
int idx = cursor.getColumnIndex("avatar");
if (!cursor.isNull(idx)) url = cursor.getString(idx);
if (idx >= 0 && !cursor.isNull(idx)) url = cursor.getString(idx);
}
cursor.close();
databaseHelper.close();

View File

@ -49,12 +49,12 @@ public class ConfigurationDatabaseHelper extends SQLiteOpenHelper {
}
private static ConnectionConfiguration configFromCursor(final Cursor cursor) {
String name = cursor.getString(cursor.getColumnIndex("name"));
String pairedBtAddress = cursor.getString(cursor.getColumnIndex("pairedBtAddress"));
int connectionType = cursor.getInt(cursor.getColumnIndex("connectionType"));
int role = cursor.getInt(cursor.getColumnIndex("role"));
int enabled = cursor.getInt(cursor.getColumnIndex("connectionEnabled"));
String nodeId = cursor.getString(cursor.getColumnIndex("nodeId"));
String name = cursor.getString(cursor.getColumnIndexOrThrow("name"));
String pairedBtAddress = cursor.getString(cursor.getColumnIndexOrThrow("pairedBtAddress"));
int connectionType = cursor.getInt(cursor.getColumnIndexOrThrow("connectionType"));
int role = cursor.getInt(cursor.getColumnIndexOrThrow("role"));
int enabled = cursor.getInt(cursor.getColumnIndexOrThrow("connectionEnabled"));
String nodeId = cursor.getString(cursor.getColumnIndexOrThrow("nodeId"));
if (NULL_STRING.equals(name)) name = null;
if (NULL_STRING.equals(pairedBtAddress)) pairedBtAddress = null;
return new ConnectionConfiguration(name, pairedBtAddress, connectionType, role, enabled > 0, nodeId);

View File

@ -289,8 +289,8 @@ public class NodeDatabaseHelper extends SQLiteOpenHelper {
Cursor status = db.query("assetsReadyStatus", null, "nowReady != markedReady", null, null, null, null);
while (status.moveToNext()) {
cv = new ContentValues();
cv.put("assetsPresent", status.getInt(status.getColumnIndex("nowReady")));
db.update("dataitems", cv, "_id=?", new String[]{Integer.toString(status.getInt(status.getColumnIndex("dataitems_id")))});
cv.put("assetsPresent", status.getInt(status.getColumnIndexOrThrow("nowReady")));
db.update("dataitems", cv, "_id=?", new String[]{Integer.toString(status.getInt(status.getColumnIndexOrThrow("dataitems_id")))});
}
status.close();
}