diff --git a/src/SQLite.cs b/src/SQLite.cs index 72525c56..5677605d 100644 --- a/src/SQLite.cs +++ b/src/SQLite.cs @@ -706,6 +706,28 @@ public void EnableLoadExtension (bool enabled) throw SQLiteException.New (r, msg); } } + + /// + /// Load extension. + /// + public void LoadExtension (string filename) + { + SQLite3.Result r = SQLite3.LoadExtension (Handle, filename, null, out var msg); + if (r != SQLite3.Result.OK) { + throw SQLiteException.New (r, msg); + } + } + + /// + /// Load extension. + /// + public void LoadExtension (string filename, string customInitFunctionName) + { + SQLite3.Result r = SQLite3.LoadExtension (Handle, filename, customInitFunctionName, out var msg); + if (r != SQLite3.Result.OK) { + throw SQLiteException.New (r, msg); + } + } #if !USE_SQLITEPCL_RAW static byte[] GetNullTerminatedUtf8 (string s) @@ -5050,6 +5072,9 @@ public enum ConfigOption : int [DllImport(LibraryPath, EntryPoint = "sqlite3_enable_load_extension", CallingConvention=CallingConvention.Cdecl)] public static extern Result EnableLoadExtension (IntPtr db, int onoff); + [DllImport (LibraryPath, EntryPoint = "sqlite3_load_extension", CallingConvention = CallingConvention.Cdecl)] + public static extern Result LoadExtension (IntPtr db, [MarshalAs (UnmanagedType.LPStr)] string filename, [MarshalAs (UnmanagedType.LPStr)] string initFunctionName, [MarshalAs(UnmanagedType.LPStr)] out string errorMsg); + [DllImport(LibraryPath, EntryPoint = "sqlite3_close", CallingConvention=CallingConvention.Cdecl)] public static extern Result Close (IntPtr db); @@ -5401,6 +5426,16 @@ public static Result EnableLoadExtension (Sqlite3DatabaseHandle db, int onoff) { return (Result)Sqlite3.sqlite3_enable_load_extension (db, onoff); } + + public static Result LoadExtension (Sqlite3DatabaseHandle db, string fileName, string initFunctionName, out string errorMessage) + { + var result = (Result)Sqlite3.sqlite3_load_extension (db, SQLitePCL.utf8z.FromString (fileName), + SQLitePCL.utf8z.FromString (initFunctionName), out SQLitePCL.utf8z pzErrMsg); + + errorMessage = pzErrMsg.utf8_to_string (); + + return result; + } public static int LibVersionNumber () { diff --git a/tests/SQLite.Tests/SQLite.Tests.csproj b/tests/SQLite.Tests/SQLite.Tests.csproj index 5c14b15d..25a7da11 100644 --- a/tests/SQLite.Tests/SQLite.Tests.csproj +++ b/tests/SQLite.Tests/SQLite.Tests.csproj @@ -12,8 +12,17 @@ + + + + USE_SQLITEPCL_RAW;RELEASE + + + USE_SQLITEPCL_RAW;DEBUG + + SQLite.cs