Convert CrossProcessCursorWrapper to SQLiteCursor


#1

I have code

SQLiteCursor cur = (SQLiteCursor)CApp.Db.rawQuery(myQuery, null);

and it works for non-Cipher version. When I use SQLCipher classes it throws ClassCastException.
Can you tell me how to change code? How to create SQLiteCursor using Database.rawQuery()?


#2

SQLCipher for Android has its own SQLiteCursor class. You cannot create a framework SQLiteCursor class from a SQLCipher for Android query result. You will need to change your import statements to use net.sqlcipher.database.SQLiteCursor.


#3

I use SQLiteCursor from net.sqlcipher.databaseAQLiteCursor;
Code compiles but throws ClassCastException when executing.
Error message is “java.lang.ClassCastException net.sqlcipher.CrossProcessCursorWrapper cannot be cast to android.database.CrossProcessCursorWrapper”


#4

The code in your first post does not do a cast to CrossProcessCursorWrapper. It does a cast to SQLiteCursor.

I suggest that you post the complete Java stack trace for your crash, along with all of your code that is referenced in that stack trace.


#5

A code sufficient to reproduce the error

import net.sqlcipher.database.SQLiteCursor;

SQLiteCursor cur = null;
try
{
cur = (SQLiteCursor)CApp.Db.rawQuery(myQuery, null);
while(cur.moveToNext())
{
}
}
catch(Exception ex)
{
}

I found solution using that code:
cur = (SQLiteCursor)((CrossProcessCursorWrapper)CApp.Db.rawQuery(query, args)).getWrappedCursor();
All classes are from SQLiteCipher.


#6

Hi @korwinek

In this case, you should just be able to reference the net.zetetic.Cursor interface instead which would remove your need of get the wrapped cursor and performing a cast. An example can be found in our test suite here.


#7

Example shows how to create net.zetetic.Cursor, but I need to create net.zetetic.SQLiteCursor object which allows me to call method setSelectionArguments() and then method requery().


#8

Hello @korwinek

Your example above only showed the usage of moveToNext which would be satisfied by the interface, however if you do need setSelectionArguments you would need to cast to the concrete instance.


#9

@developernotes
Thank you for help and quick response.

I converted all hundreds of thousands of code lines to use SQLCipher. It compiles :grinning: and now it’s time for testing.


#10

Hello @korwinek

We are happy to help, take care!