Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions src/SQLite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,28 @@ public void EnableLoadExtension (bool enabled)
throw SQLiteException.New (r, msg);
}
}

/// <summary>
/// Load extension.
/// </summary>
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);
}
}

/// <summary>
/// Load extension.
/// </summary>
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)
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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 ()
{
Expand Down
9 changes: 9 additions & 0 deletions tests/SQLite.Tests/SQLite.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,17 @@
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
<PackageReference Include="SourceGear.sqlite3" Version="3.50.3" />
<PackageReference Include="SQLitePCLRaw.config.e_sqlite3" Version="3.0.1" />
</ItemGroup>

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DefineConstants>USE_SQLITEPCL_RAW;RELEASE</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DefineConstants>USE_SQLITEPCL_RAW;DEBUG</DefineConstants>
</PropertyGroup>

<ItemGroup>
<Compile Include="..\..\src\SQLite.cs">
<Link>SQLite.cs</Link>
Expand Down