Support
Quality
Security
License
Reuse
kandi has reviewed Android-Debug-Database and discovered the below as its top functions. This is intended to give you an instant insight into Android-Debug-Database implemented functionality, and help decide if they suit your requirements.
A library for debugging android databases and shared preferences - Make Debugging Great Again
Using Android Debug Database Library in your application
debugImplementation 'com.amitshekhar.android:debug-db:1.0.6'
Getting address with toast, in case you missed the address log in logcat
public static void showDebugDBAddressLogToast(Context context) {
if (BuildConfig.DEBUG) {
try {
Class<?> debugDB = Class.forName("com.amitshekhar.DebugDB");
Method getAddressLog = debugDB.getMethod("getAddressLog");
Object value = getAddressLog.invoke(null);
Toast.makeText(context, (String) value, Toast.LENGTH_LONG).show();
} catch (Exception ignore) {
}
}
}
Adding custom database files
public static void setCustomDatabaseFiles(Context context) {
if (BuildConfig.DEBUG) {
try {
Class<?> debugDB = Class.forName("com.amitshekhar.DebugDB");
Class[] argTypes = new Class[]{HashMap.class};
Method setCustomDatabaseFiles = debugDB.getMethod("setCustomDatabaseFiles", argTypes);
HashMap<String, Pair<File, String>> customDatabaseFiles = new HashMap<>();
// set your custom database files
customDatabaseFiles.put(ExtTestDBHelper.DATABASE_NAME,
new Pair<>(new File(context.getFilesDir() + "/" + ExtTestDBHelper.DIR_NAME +
"/" + ExtTestDBHelper.DATABASE_NAME), ""));
setCustomDatabaseFiles.invoke(null, customDatabaseFiles);
} catch (Exception ignore) {
}
}
}
Adding InMemory Room databases
public static void setInMemoryRoomDatabases(SupportSQLiteDatabase... database) {
if (BuildConfig.DEBUG) {
try {
Class<?> debugDB = Class.forName("com.amitshekhar.DebugDB");
Class[] argTypes = new Class[]{HashMap.class};
HashMap<String, SupportSQLiteDatabase> inMemoryDatabases = new HashMap<>();
// set your inMemory databases
inMemoryDatabases.put("InMemoryOne.db", database[0]);
Method setRoomInMemoryDatabase = debugDB.getMethod("setInMemoryRoomDatabases", argTypes);
setRoomInMemoryDatabase.invoke(null, inMemoryDatabases);
} catch (Exception ignore) {
}
}
}
License
Copyright (C) 2019 Amit Shekhar
Copyright (C) 2011 Android Open Source Project
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.
Inconsistent Android SQLite registers
for(int i=0; i<cursor.getCount(); i++){
cursor.moveToNext();
//Do stuff with cursor info
}
QUESTION
Inconsistent Android SQLite registers
Asked 2020-Jul-30 at 07:44I have a local SQLite database on my Android app. In order to perform some tests, I do some insertions with values.put(regValues);
db.insert(register);
db.close();
. Then, I do some queries with the data and here it when it all gets messy:
The data is stored on a local SQLite database. When I query the data on my Android app with a general statement such as SELECT * FROM TABLE
, it only retrieves 2 of the 8 inserted registers. This could be an insertion error, but here is the thing:
On Android, the query and the iteration is done the following way:
Cursor cursor = db.query(TABLE_NAME,
new String[]{TABLE_NAME.COLUMN_ID},
null,
null,
null, null, null, null);
cursor.moveToFirst();
int numberRegs = 0;
while(cursor.moveToNext()){
numberRegs++;
}
Log.d(LOG_TAG, "numberRegs: " + numberRegs);
When I check the registers with this web debugger, I can see all the 8 inserted registers. To complicate things a bit more, I have tried to download the database local
on my computer and see if I could see the 8 registers inserted on the database, but I only see 4 of them.
Due to this, I am completely lost because I am not able to know the real state of the local SQLite database. Therefore, my questions are: why does this inconsistency happen and what can I do to fix it in order to see on my queries on Android the 8 registers instead of the current 2?
ANSWER
Answered 2020-Jul-30 at 07:44The problem was that using while(cursor.moveToNext())
stops before iterating through all registers. Instead of this, the iteration should be done like this:
for(int i=0; i<cursor.getCount(); i++){
cursor.moveToNext();
//Do stuff with cursor info
}
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
No vulnerabilities reported
Save this library and start creating your kit
Explore Related Topics
Save this library and start creating your kit