예제 #1
0
        public static List <QueryInfo> GetQueryInfo(IEnumerable <int> ids)
        {
            List <QueryInfo> result = new List <QueryInfo>();
            string           idList = ids.Join();

            if (idList != "")
            {
                using (QSqlLite s = new QSqlLite())
                {
                    // this order will put the newest versions at the bottom of the results
                    // so if multiple version are opened, it will end up with the latest version anyways
                    s.Open(@"
select t.id, t.name, q.expr, t.visible, q.id 
from queries q 
inner join tabs t on t.id=q.tab_id 
where q.id in (" + idList + ") order by q.id");
                    while (s.GetRow())
                    {
                        result.Add(new QueryInfo {
                            queryVersionId = s.GetInt(4), visible = s.GetBool(3), queryId = s.GetInt(0), tabLabel = s.GetString(1), expr = s.GetString(2)
                        });
                    }
                }
            }

            return(result);
        }
예제 #2
0
        public static int GetQueries(List <Query> result)
        {
            if (A.dbId == 0)
            {
                return(0);
            }
            QSqlLite.Exec("delete from queries where expr=''");
            QSqlLite.Exec("delete from tabs where databaseId=@1 and id not in (select tab_id from queries)", A.dbId);
            using (QSqlLite s = new QSqlLite())
            {
                s.Open("select t.id, t.name, (select q.id from queries q where q.tab_id=t.id order by q.id desc limit 1) from tabs t where t.databaseId=@1 and t.visible<>0 order by t.pos", A.dbId);
                while (s.GetRow())
                {
                    result.Add(new Query(s.GetInt(0), s[1], s.GetInt(2)));
                }
            }

            return(result.Count);
        }
예제 #3
0
        public static List <QueryHistory> GetQueryHistory()
        {
            List <QueryHistory> result = new List <QueryHistory>();
            string sql = "t.databaseId=@1";

            if (S.Get("ShowClosedQueries", false))
            {
                sql = T.AppendTo(sql, "t.visible<>0", " and ");
            }
            if (sql != "")
            {
                sql = " where " + sql;
            }
            sql = @"
select q.id, q.tab_id, q.expr, q.when_changed, t.visible, t.name, q.failed, q.rows, q.ms
from queries q 
inner join tabs t on t.id=q.tab_id " + sql + " order by q.when_changed desc limit 100";
            using (QSqlLite s = new QSqlLite())
            {
                s.Open(sql, A.dbId);
                while (s.GetRow())
                {
                    string z = s.GetString(6);
                    result.Add(new QueryHistory
                    {
                        queryVersionId = s.GetInt(0),
                        id             = s.GetInt(1),
                        expr           = s.GetString(2),
                        whenChanged    = Convert.ToDouble(s.GetString(3)).ToDateTime(),
                        visible        = s.GetBool(4),
                        label          = s.GetString(5),
                        failed         = s.GetBool(6),
                        rows           = s.GetInt(7),
                        ms             = (s.GetString(8) == "" ? 0 : Convert.ToInt32(s.GetString(8)))
                    });
                }
            }

            return(result);
        }
예제 #4
0
        public static List <KeyValuePair <string, int> > GetConnections(out int selectedIndex)
        {
            selectedIndex = -1;
            List <KeyValuePair <string, int> > result = new List <KeyValuePair <string, int> >();

            using (QSqlLite s = new QSqlLite())
            {
                s.Open("select databaseId, host, database, type from databases order by database, host");
                while (s.GetRow())
                {
                    string nam = s[2];
                    if (s[3] == "SQLite")
                    {
                        nam = T.GetFileNameFromFilePath(nam, true);
                    }
                    result.Add(new KeyValuePair <string, int>(s[1] + " / " + nam, s.GetInt(0)));
                    if (s.GetInt(0) == initSettings.databaseId)
                    {
                        selectedIndex = result.Count - 1;
                    }
                }
            }
            return(result);
        }