Mono.Data.Sqlite.dll compatibility with SQLite.Net
I solved this by using a second class to abstract the database calls. I have two assemblies containing platform specific versions of a SQLQuery
class, one for windows projects and one for monotouch.
My database layer just calls SQLQuery
so my calls are something like
SQLQuery q = new SQLQuery("SELECT * FROM foo WHERE bar = @bar");q.AddParameter("bar", bar);DataTable dt = q.GetResultsDT();
and this will work on either platform, as long as the SQLQuery
assembly for that platform is referenced in the project.
One way to get around this is to define a project constant, and then use #if
blocks.
Your using:
#if MONO_SQLITEusing Mono.Data.Sqlite.dll#elseusing System.Data.SQLite;#endif
Your code:
#if MONO_SQLITE SqliteCommand command = new SqliteCommand(sql, DbConnection); SqliteDataReader reader = command.ExecuteReader(); #else SQLiteCommand command = new SQLiteCommand(sql, DbConnection); SQLiteDataReader reader = command.ExecuteReader();#endif
Depending on whether you are using Mono or the .Net stack, you then just add or remove the MONO_SQLITE
constant definition from your project.
The Mono C# compiler also defines the symbol __MonoCS__
. I don't know if MonoTouch does so, but if it did you could also do:
#if __MonoCS__// ... mono stuff#else// ... MS stuff#endif