<commit_before>using System;
using System.Runtime.InteropServices;
using SQLite.Net.Interop;

namespace SQLite.Net.Platform.Win32
{
    internal static class SQLiteApiWin32Internal
    {
        static SQLiteApiWin32Internal()
        {
            // load native library
            int ptrSize = Marshal.SizeOf(typeof (IntPtr));
            if (ptrSize == 8)
            {
                IntPtr ret = LoadLibrary(@"x64\SQLite.Interop.dll");
                if (ret == IntPtr.Zero)
                {
                    throw new Exception("Failed to load native sqlite library");
                }
            }
            else if (ptrSize == 4)
            {
                IntPtr ret = LoadLibrary(@"x86\SQLite.Interop.dll");
                if (ret == IntPtr.Zero)
                {
                    throw new Exception("Failed to load native sqlite library");
                }
            }
        }

        [DllImport("kernel32", SetLastError = true, CharSet = CharSet.Unicode)]
        private static extern IntPtr LoadLibrary(string lpFileName);

        [DllImport("SQLite.Interop.dll", EntryPoint = "sqlite3_open", CallingConvention = CallingConvention.Cdecl)]
        public static extern Result sqlite3_open([MarshalAs(UnmanagedType.LPStr)] string filename, out IntPtr db);

        [DllImport("SQLite.Interop.dll", EntryPoint = "sqlite3_open_v2", CallingConvention = CallingConvention.Cdecl)]
        public static extern Result sqlite3_open([MarshalAs(UnmanagedType.LPStr)] string filename, out IntPtr db,
            int flags,
            IntPtr zvfs);

        [DllImport("SQLite.Interop.dll", EntryPoint = "sqlite3_open16", CallingConvention = CallingConvention.Cdecl)]
        public static extern Result sqlite3_open16([MarshalAs(UnmanagedType.LPWStr)] string filename, out IntPtr db);

        [DllImport("SQLite.Interop.dll", EntryPoint = "sqlite3_enable_load_extension",
            CallingConvention = CallingConvention.Cdecl)]
        public static extern Result sqlite3_enable_load_extension(IntPtr db, int onoff);

        [DllImport("SQLite.Interop.dll", EntryPoint = "sqlite3_close", CallingConvention = CallingConvention.Cdecl)]
        public static extern Result sqlite3_close(IntPtr db);

        [DllImport("SQLite.Interop.dll", EntryPoint = "sqlite3_config", CallingConvention = CallingConvention.Cdecl)]
        public static extern Result sqlite3_config(ConfigOption option);

        [DllImport("SQLite.Interop.dll", EntryPoint = "sqlite3_win32_set_directory",
            CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
        public static extern int sqlite3_win32_set_directory(uint directoryType, string directoryPath);<commit_msg>SQliteApiWin32Internal fails to load the interop library when the current working directory of the process is not where SQLite.Net.Platform.Win32.dll is placed. ex) when loading SQLite.Net.dll from a PowerShell binary module. Modified the static constructor of SQLiteApiWin32Internal to use the assembly's location information to locate the interop dll.<commit_after>using System;
using System.IO;
using System.Runtime.InteropServices;
using SQLite.Net.Interop;
using System.Reflection;

namespace SQLite.Net.Platform.Win32
{
    internal static class SQLiteApiWin32Internal
    {
        static SQLiteApiWin32Internal()
        {
            // load native library
            int ptrSize = Marshal.SizeOf(typeof (IntPtr));
            string relativePath = ptrSize == 8 ? @"x64\SQLite.Interop.dll" : @"x86\SQLite.Interop.dll";
            string currentPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            string interopPath = Path.Combine(currentPath, relativePath);

            IntPtr ret = LoadLibrary(interopPath);
            if (ret == IntPtr.Zero)
            {
                throw new Exception("Failed to load native sqlite library");
            }
        }

        [DllImport("kernel32", SetLastError = true, CharSet = CharSet.Unicode)]
        private static extern IntPtr LoadLibrary(string lpFileName);

        [DllImport("SQLite.Interop.dll", EntryPoint = "sqlite3_open", CallingConvention = CallingConvention.Cdecl)]
        public static extern Result sqlite3_open([MarshalAs(UnmanagedType.LPStr)] string filename, out IntPtr db);

        [DllImport("SQLite.Interop.dll", EntryPoint = "sqlite3_open_v2", CallingConvention = CallingConvention.Cdecl)]
        public static extern Result sqlite3_open([MarshalAs(UnmanagedType.LPStr)] string filename, out IntPtr db,
            int flags,
            IntPtr zvfs);

        [DllImport("SQLite.Interop.dll", EntryPoint = "sqlite3_open16", CallingConvention = CallingConvention.Cdecl)]
        public static extern Result sqlite3_open16([MarshalAs(UnmanagedType.LPWStr)] string filename, out IntPtr db);

        [DllImport("SQLite.Interop.dll", EntryPoint = "sqlite3_enable_load_extension",
            CallingConvention = CallingConvention.Cdecl)]
        public static extern Result sqlite3_enable_load_extension(IntPtr db, int onoff);

        [DllImport("SQLite.Interop.dll", EntryPoint = "sqlite3_close", CallingConvention = CallingConvention.Cdecl)]
        public static extern Result sqlite3_close(IntPtr db);

        [DllImport("SQLite.Interop.dll", EntryPoint = "sqlite3_config", CallingConvention = CallingConvention.Cdecl)]
        public static extern Result sqlite3_config(ConfigOption option);

        [DllImport("SQLite.Interop.dll", EntryPoint = "sqlite3_win32_set_directory",
            CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
        public static extern int sqlite3_win32_set_directory(uint directoryType, string directoryPath);
{'fraction_non_alphanumeric': 0.08883426966292135, 'fraction_numerical': 0.01386938202247191, 'mean_word_length': 3.164473684210526, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3951949', 'n_tokens_mistral': 1650, 'n_tokens_neox': 1554, 'n_words': 373}