Ejemplo n.º 1
0
        public static void SaveSettings(bool shuttingDown)
        {
            lock (settings)
            {
                A.AddToLog("saving settings");

                string sql = "delete from settings;";
                foreach (string key in settings.Keys)
                {
                    sql += "insert into settings (name,value) values ('" + key + "', '" + QSqlLite.n(settings[key]) + "');";
                }
                QSqlLite.Exec(sql);
                dirty = false;
                BindingFlags flags = BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance | BindingFlags.GetField | BindingFlags.GetProperty;

                if (A.dbId > 0)
                {
                    sql = "delete from tables;delete from table_columns;delete from table_aliases;";
                    foreach (DbTable table in A.db.tables.Values)
                    {
                        if (table.hasSettings)
                        {
                            sql += QObject.RenderInsert(table, "tables", false, flags);
                            foreach (DbColumn column in table.columns.Values)
                            {
                                if (column.hasSettings)
                                {
                                    sql += QObject.RenderInsert(column, "table_columns", false, flags);
                                }
                            }
                            foreach (DbAlias a in table.aliases.Values)
                            {
                                if (a.hasSettings)
                                {
                                    sql += QObject.RenderInsert(a, "table_aliases", false, flags);
                                }
                            }
                        }
                    }
                    QSqlLite.Exec(sql);
                    if (shuttingDown)
                    {
                        initSettings.shutDownClean = true;
                        sql = "delete from init_settings;" + QObject.RenderInsert(initSettings, "init_settings", false);
                        QSqlLite.Exec(sql);
                    }
                }
            }
        }