views:

242

answers:

7

Can someone help/guide me with using SQLite lib on Linux (MONO) and Windows (.NET)

On linux i use native mono sqlite client, and on windows i use http://sqlite.phxsoftware.com/

is there a way to define 'using' directives like this :

#if (linux)
  using Mono.Data.Sqlite;
#else
  using System.Data.SQLite;

Another problem is small differencies on both implementations, like :

cmd = new SqliteCommand(); // mono
cmd = new SQLiteCommand(); // sqlite.phxsoftware.com

Waiting for any help

If you know better or simplier way to do this it'll very thankfull for info.

Thanks

+1  A: 

There is a fully managed SQLite translation. If you use that, then you could use the same DLL on Mono and Windows.

Another way to solve your issue is to create your own database-interface and then implement that interface once for Mono and one for Microsoft .NET in separate DLLs. (Basically the same way you create code that runs against different databases)

Arve
its based on SQLite 3.4.0, which is outdated and database will suffer incompatibility issues i guess
alienv
A: 

You can solve the naming differences using alias

#if (linux)
  using SqlCommand = Mono.Data.Sqlite.SqliteCommand;
#else
  using SqlCommand = System.Data.SQLite;

Using different assemblies for different builds is a more complex task i think.. you can have a look at the MSBuild documentation

munissor
What if the internal implementation(method and properties) of SqliteCommand and SQLite are different?
A9S6
You are right, I assumed that all the 2 implementation inherits from System.Data.SqlClient.SqlCommand
munissor
A: 

The open-source Vici CoolStorage ORM library works on Windows (.NET), Mono (Mac,Linux and Windows) and MonoTouch (iPhone) using that platform's SQLite driver.

To use it on these different platforms, you don't have to change anything to your source code. Just recompile, and it should work.

Philippe Leybaert
A: 

IMO you should first try to find an implementation that works in both Windows and Linux. If that doesn't work, create an assembly that defines a common interface for SQLite and put all you "#if LINUX" code in that assembly. Then use that assembly in the main application to avoid cluttering the main app with all the # defines.

A9S6
A: 

The SQLite ADO.NET provider is actually a mixed-mode assembly, which contains the native SQLite library. This native library is not the same on Windows and Linux of course, so this provider doesn't work on Linux. However, there is a managed-only version of the provider (SQLite-1.0.65.0-managedonly-binaries.zip on the download page). So I think you just need to use this version of the provider, and provide the adequate native SQLite dynamic library along with it (.dll on Windows, .so on Linux)

Thomas Levesque
+1  A: 

You can just use the mono implementation of SQLite for both, Windows and Linux versions of your software. Just include the mono assembly for SQLite in your software package and refer to it locally.

As you can read here in the last post, you can use the managed way of mono solely in your code and need just to redistribute the native part for windows differently. But you do not have to mess with to managed implementations and redundand code through that.

BeowulfOF
so ill need to provide and include mono sqlite .so in windows build ?
alienv
well, i have to admit, it does not seem so simple.
BeowulfOF
+2  A: 

You can use csharp-sqlite which is a port to C# of Sql-Lite. It is very active and based on 3.6.22 version of SqlLite. See Miguel's comments on attempts to try to speed it up.

Kris Erickson
+1, just wanted to add that so far the project seems active and they keep up to date w/ SQLite versions.
torial