Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement: Support SQLite database migrations #21

Closed
ferventcoder opened this issue Oct 5, 2011 · 4 comments
Closed

Enhancement: Support SQLite database migrations #21

ferventcoder opened this issue Oct 5, 2011 · 4 comments

Comments

@ferventcoder
Copy link
Member

No description provided.

@ferventcoder
Copy link
Member Author

Good old System.Data.SQLite.dll doesn't ILMerge. boo.

@ferventcoder
Copy link
Member Author

This may be my answer... http://stackoverflow.com/q/6616923/18475

@ferventcoder
Copy link
Member Author

Wow, now that is some crazy code right there... lol

        public void enable_loading_from_merged_assembly()
        {
            AppDomain.CurrentDomain.AssemblyResolve += (sender, e) => load_sqlite_data_assembly(e.Name);
        }
        private Assembly load_sqlite_data_assembly(string assembly_name)
        {
            if (assembly_name.to_lower().StartsWith("system.data.sqlite"))
            {
                string resources_path = Path.Combine(output_path, "resources");
                string sqlite_file = Path.Combine(resources_path, "System.Data.SQLite.dll");
                FileInfo sqlite_dll = new FileInfo(sqlite_file);
                Log.bound_to(this).log_a_debug_event_containing("Loading System.Data.SQLite.dll from '{0}'. If it doesn't exist then it will be created from '{1}'.", sqlite_file, ApplicationParameters.sqlite_dll_resource);

                if (!sqlite_dll.Exists)
                {
                    if (!Directory.Exists(resources_path)) Directory.CreateDirectory(resources_path);

                    Assembly executing_assembly = Assembly.GetExecutingAssembly();

                    using (FileStream fs = sqlite_dll.OpenWrite())
                    using (Stream resource_stream = executing_assembly.GetManifestResourceStream(ApplicationParameters.sqlite_dll_resource))
                    {
                        const int size = 4096;
                        byte[] bytes = new byte[size];
                        int number_of_bytes;
                        while ((number_of_bytes = resource_stream.Read(bytes, 0, size)) > 0)
                        {
                            fs.Write(bytes, 0, number_of_bytes);
                        }
                        fs.Flush();
                        fs.Close();
                        resource_stream.Close();
                    }
                }


                return Assembly.LoadFrom(sqlite_file);
            }

            return null;
        }

@ferventcoder
Copy link
Member Author

Fixed in 05d56aa

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant