praeclarum / sqlite-net

Simple, powerful, cross-platform SQLite client and ORM for .NET
MIT License
3.97k stars 1.42k forks source link

Android 10 release version results in file is not a database error #1241

Open VAI2MU opened 2 weeks ago

VAI2MU commented 2 weeks ago

When running the Release version of the app on Android 10, connection to the database is successfully established but on the first attempt to execute an SQL command an exception with the message "file is not a database" happens.

Used in a .net 8.0 Maui application

Packages in use: PackageReference Include="sqlite-net-sqlcipher" Version="1.8.116" PackageReference Include="SQLitePCLRaw.bundle_e_sqlcipher" Version="2.1.8"

Also tried with: PackageReference Include="sqlite-net-sqlcipher" Version="1.9.172" PackageReference Include="SQLitePCLRaw.bundle_e_sqlcipher" Version="2.1.8"

This issue doesn't appear on the same Android 10 device on Debug mode. It also doesn't appear on any iOS devices or Android 11 devices.

JonathanWebsdale commented 1 week ago

Seeing the same problem when migrating from Xamarin.Forms application to .NET 8 MAUI.

Attempting to open a connection to an encrypted DB generated using "sqlite-net-sqlcipher" Version="1.5.231" in our Xamarin.Forms app, with our .NET Maui app, using "sqlite-net-sqlcipher" Version="1.9.172"

var connectionString = new SQLiteConnectionString(<DBPath>, SQLiteOpenFlags.Create | SQLiteOpenFlags.ReadWrite | SQLiteOpenFlags.ProtectionComplete | SQLiteOpenFlags.SharedCache | SQLiteOpenFlags.FullMutex, true, <DBKey>);
var connection = new SQLite.SQLiteAsyncConnection(connectionString); 

var table = await connection.ExecuteScalarAsync<string>(mySelectQuery);

Results in an exception with the result "SQLite.SQLite3+Result.NonDBFile"

at SQLite.SQLite3.Prepare2(sqlite3 db, String query) at SQLite.SQLiteCommand.Prepare() at SQLite.SQLiteCommand.ExecuteScalar[String]() at SQLite.SQLiteAsyncConnection.<>cDisplayClass82_01[[System.String, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].<ExecuteScalarAsync>b__0(SQLiteConnectionWithLock conn) at SQLite.SQLiteAsyncConnection.<>c__DisplayClass33_01[[System.String, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].b0()

Attempting to re-compile and run the .NET MAUI application with version "1.5.231" of the package does work on Android in debug mode, however causes a different exception when attempting to run in iOS.

System.MissingMethodException: Method not found: string SQLitePCL.raw.sqlite3_column_text(SQLitePCL.sqlite3_stmt,int) at SQLite.SQLiteCommand.ReadCol(sqlite3_stmt stmt, Int32 index, ColType type, Type clrType) at SQLite.SQLiteCommand.ExecuteScalar[String]() at SQLite.SQLiteConnection.ExecuteScalar[String](String query, Object[] args) at SQLite.SQLiteConnection..ctor(String databasePath, SQLiteOpenFlags openFlags, Boolean storeDateTimeAsTicks, Object key) at SQLite.SQLiteConnectionWithLock..ctor(SQLiteConnectionString connectionString, SQLiteOpenFlags openFlags) at SQLite.SQLiteAsyncConnection..ctor(String databasePath, SQLiteOpenFlags openFlags, Boolean storeDateTimeAsTicks, Object key)