Exemplo n.º 1
0
        public static int SaveQuery(int tabId, int currentQueryId, string expr, bool executing)
        {
            // string now = "'" + DateTime.Now.ToString("u") + "'";
            double now = DateTime.Now.ToEpoch();

            expr = QSqlLite.n(expr);
            bool   justUpdate = (currentQueryId != 0 && 0 != QSqlLite.SqlInt("select count(*) from queries where id=" + currentQueryId + " and expr='" + expr + "'"));
            string sql;

            if (justUpdate)
            {
                sql  = "update queries set expr='" + expr + "',when_changed=" + now;
                sql += " where id = " + currentQueryId;
                QSqlLite.Exec(sql);
            }
            else
            {
                sql            = "insert into queries (tab_id, expr,when_changed) values (" + tabId + ",'" + expr + "'," + now + ")";
                currentQueryId = QSqlLite.Exec(sql);
            }

            return(currentQueryId);
        }
Exemplo n.º 2
0
 public static void SetQueryName(int id, string name)
 {
     QSqlLite.Exec("update tabs set name='" + QSqlLite.n(name) + "' where id=" + id);
 }
Exemplo n.º 3
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);
                    }
                }
            }
        }