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

Comments

Projects
None yet
1 participant
@ferventcoder
Member

ferventcoder commented Oct 5, 2011

No description provided.

@ferventcoder

This comment has been minimized.

Show comment
Hide comment
@ferventcoder

ferventcoder Nov 26, 2011

Member

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

Member

ferventcoder commented Nov 26, 2011

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

@ferventcoder

This comment has been minimized.

Show comment
Hide comment
@ferventcoder
Member

ferventcoder commented Nov 26, 2011

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

@ferventcoder

This comment has been minimized.

Show comment
Hide comment
@ferventcoder

ferventcoder Nov 27, 2011

Member

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;
        }
Member

ferventcoder commented Nov 27, 2011

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

This comment has been minimized.

Show comment
Hide comment
@ferventcoder
Member

ferventcoder commented Nov 27, 2011

Fixed in 05d56aa

@ferventcoder ferventcoder modified the milestone: 0.8.5 Jun 3, 2015

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