utelle/SQLite3MultipleCiphers

HasCodec not set

Nailik opened this issue · 2 comments

Hi,

i have recognized that no SQLITE_HAS_CODEC 1 is defined in the almagation release file.

This results in 2 issues:
When building the android aar libarary by exchanging the default sqlite3 files with the sqlite3mutlipleciphers almagation files the tests fail when using PRAGMA key = 'secret' inside the SQLiteOpenHelper onConfigure method.
Another issue ist that the tests use SQLiteDatabase.hasCodec() and then some tests are not executed.

The bigger issue is obviously that the Pragma is not working. The next call after the SQLiteOpenHelper finishes will result in SQLiteDatabaseCorrupException.

#ifndef SQLITE_HAS_CODEC
#define SQLITE_HAS_CODEC 1
#endif

to the header file both issues can be resolved.

So what are the reasons that this is missing?

i have recognized that no SQLITE_HAS_CODEC 1 is defined in the amalgamation release file.

That's right. This preprocessor symbol is neither defined nor referenced in the SQLite3 Multiple Ciphers source code. As described in the project's readme file this symbol and all related code was removed from the SQLite source code on Feb 7, 2020: see “Simplify the code by removing the unsupported and undocumented SQLITE_HAS_CODEC compile-time option”.

This results in 2 issues: When building the android aar libarary by exchanging the default sqlite3 files with the sqlite3mutlipleciphers almagation files the tests fail when using PRAGMA key = 'secret' inside the SQLiteOpenHelper onConfigure method. Another issue ist that the tests use SQLiteDatabase.hasCodec() and then some tests are not executed.

Well, it's not the job of the source code to define this SQLITE_HAS_CODEC preprocessor symbol. It is the job of the build files to do that. And - what a surprise - that is exactly what the SQLite Android build file sqlite3\src\main\jni\sqlite\Android.mk recommends to do right at the top of the file:

# If using SEE, uncomment the following:
# LOCAL_CFLAGS += -DSQLITE_HAS_CODEC

Change this to

# If using SEE, uncomment the following:
LOCAL_CFLAGS += -DSQLITE_HAS_CODEC

and your build and test should succeed.

Additionally, you should put the following list of options (or a subset thereof - depending on your needs) to the Android build file:

# Enable SQLite3MC settings
LOCAL_CFLAGS += -DSQLITE_SECURE_DELETE=1
LOCAL_CFLAGS += -DSQLITE_DQS=0
LOCAL_CFLAGS += -DSQLITE_SOUNDEX=1
LOCAL_CFLAGS += -DSQLITE_ENABLE_COLUMN_METADATA=1
LOCAL_CFLAGS += -DSQLITE_ENABLE_DESERIALIZE=1
LOCAL_CFLAGS += -DSQLITE_ENABLE_FTS3_PARENTHESIS=1
LOCAL_CFLAGS += -DSQLITE_ENABLE_FTS4=1
LOCAL_CFLAGS += -DSQLITE_ENABLE_GEOPOLY=1
LOCAL_CFLAGS += -DSQLITE_ENABLE_EXTFUNC=1
LOCAL_CFLAGS += -DSQLITE_ENABLE_MATH_FUNCTIONS=1
LOCAL_CFLAGS += -DSQLITE_ENABLE_CSV=1
LOCAL_CFLAGS += -DSQLITE_ENABLE_VSV=1
LOCAL_CFLAGS += -DSQLITE_ENABLE_SHA3=1
LOCAL_CFLAGS += -DSQLITE_ENABLE_CARRAY=1
LOCAL_CFLAGS += -DSQLITE_ENABLE_FILEIO=1
LOCAL_CFLAGS += -DSQLITE_ENABLE_SERIES=1
LOCAL_CFLAGS += -DSQLITE_ENABLE_UUID=1
LOCAL_CFLAGS += -DSQLITE_ENABLE_REGEXP=1
LOCAL_CFLAGS += -DSQLITE_USER_AUTHENTICATION=0

The bigger issue is obviously that the Pragma is not working. The next call after the SQLiteOpenHelper finishes will result in SQLiteDatabaseCorrupException.

This issue will vanish if you follow the above steps.

#ifndef SQLITE_HAS_CODEC
#define SQLITE_HAS_CODEC 1
#endif

to the header file both issues can be resolved.

Yes, that's one way you can resolve it. However, as said it is not the job of this project to define preprocessor symbols that are required to successfully compile wrappers or extensions outside this project.

So what are the reasons that this is missing?

The preprocessor symbol SQLITE_HAS_CODEC is not missing, it is not defined on purpose. It is not used at all within the SQLite3 Multiple Ciphers project. So, why should the symbol be defined in the header file? That could cause unwanted side effects.

Wrappers or extensions that are based on the SQLite3 Multiple Ciphers project should define the symbols they need to enable or disable certain features themselves.

Thank you very much for this detailed fast explanation.