views:

53

answers:

2

I want to implement a function for System.Data.SQLite in C#. Implementing the SQLiteFunction interface is easy (seen examples over the Internet).

The question is where should I put the compiled code? Do I need the source to be compiled altogether with the System.Data.SQLite project? Do I have a better option, so that my functions will reside in a separate DLL?

Clarification: The function is supposed to be known not only for my C# code but also for sqlite3 client (for example), so I will be able to use it while executing INSERT commands that come in plain text.

A: 

There's a static method SQLiteFunction.RegisterFunction, but documentation says that it's...

...a workaround for the Compact Framework where enumerating assemblies is not currently supported.

Additionally, from what I can tell based on documentation to SQLiteFunctionAttribute:

A simple custom attribute to enable us to easily find user-defined functions in the loaded assemblies and initialize them in SQLite as connections are made.

and

Using reflection, enumerate all assemblies in the current appdomain looking for classes that have a SQLiteFunctionAttribute attribute, and registering them accordingly.

all user-defined functions are loaded automatically from all loaded assemblies.

Anton Gogolev
A: 

SQLite looks at all of your application's assemblies and recognises types that have the [SQLiteFunction] attribute. So you can put them wherever you like, as long as that assembly is already loaded by the time you make your first SQLite call.

If it's just one or two functions I'd be inclined to put them in one of your application's existing assemblies.

Tim Robinson
Sorry, but here is another (interesting) issue: I want to make it available even for regular text/sql scripts. How can I make it loadable by the time I run 'sqlite3' for example? (hopefully I am asking the right question)
BreakPhreak
I think for that you need to modify sqlite3. `[SQLiteFunction]` is specific to .NET.
Tim Robinson