I have an ADO.NET program that uses the MSSQL getdate function. I can reconfigure this application to use arbitrary ADO.NET providers, but for nontechnical reasons I can't easily change its code to eliminate use of this function. I'd like to test the program against SQLite, but without getdate() the program can't run.
SQLite is extensible, and System.Data.SQLite supports user-defined functions via SQLiteFunction and SQLiteFunctionAttribute. Unfortunately for me, I'd have to change the source code of my app-under-test to provide a suitable getdate definition. Wouldn't it be great if I could define the function in my test library and register the function from the SQLite connection string used by the application I'm testing?
Here's a patch against 1.0.65.0 that implements this feature:
---
Index: System.Data.SQLite/SQLiteConnection.cs
===================================================================
--- System.Data.SQLite/SQLiteConnection.cs (revision 1)
+++ System.Data.SQLite/SQLiteConnection.cs (working copy)
@@ -143,6 +143,12 @@
/// <description>N</description>
/// <description>Serializable</description>
/// </item>
+ /// <item>
+ /// <description>FunAssemblies</description>
+ /// <description>Additional assemblies to load for their SQLite function definitions</description>
+ /// <description>N</description>
+ /// <description>none</description>
+ /// </item>
/// </list>
/// </remarks>
public sealed partial class SQLiteConnection : DbConnection, ICloneable
@@ -594,6 +600,12 @@
/// <description>N</description>
/// <description>Serializable</description>
/// </item>
+ /// <item>
+ /// <description>FunAssemblies</description>
+ /// <description>Additional assemblies to load for their SQLite function definitions</description>
+ /// <description>N</description>
+ /// <description>none</description>
+ /// </item>
/// </list>
/// </remarks>
#if !PLATFORM_COMPACTFRAMEWORK
@@ -810,6 +822,16 @@
else
flags |= SQLiteOpenFlagsEnum.ReadWrite;
+
+#if !PLATFORM_COMPACTFRAMEWORK
+ string funAssemblies = FindKey(opts, "funAssemblies", String.Empty);
+ if (funAssemblies.Length > 0) {
+ foreach (String asmName in funAssemblies.Split(new char[ { ':' })) {
+ System.Reflection.Assembly.Load(asmName);
+ }
+ }
+#endif
+
_sql.Open(fileName, flags, maxPoolSize, usePooling);
_binaryGuid = (SQLiteConvert.ToBoolean(FindKey(opts, "BinaryGUID", Boolean.TrueString)) == true);