示例#1
0
 public int QueryCount(int queryId)
 {
     var doQuery = new DoQueryCount.Builder(Application.Client.Ticket, Application.Token, Application.Client.AccountDomain, TableId)
         .SetQid(queryId)
         .Build();
     var xml = doQuery.Post().CreateNavigator();
     return int.Parse(xml.SelectSingleNode("/qdbapi/numMatches").Value);
 }
示例#2
0
 private void _doQuery(DoQuery qry)
 {
     Records.Clear();
     try
     {
         XPathNavigator xml = qry.Post().CreateNavigator();
         LoadColumns(xml); //Must be done each time, incase the schema changes due to another user, or from a previous query that has a differing subset of columns
         LoadRecords(xml);
     }
     catch (ViewTooLargeException)
     {
         //split into smaller queries automagically
         List<string> optionsList = new List<string>();
         string query = qry.Query;
         string collist = qry.Collist;
         int maxCount = 0;
         int baseSkip = 0;
         if (!string.IsNullOrEmpty(qry.Options))
         {
             string[] optArry = qry.Options.Split('.');
             foreach (string opt in optArry)
             {
                 if (opt.StartsWith("num-"))
                 {
                     maxCount = int.Parse(opt.Substring(4));
                 }
                 else if (opt.StartsWith("skp-"))
                 {
                     baseSkip = int.Parse(opt.Substring(4));
                 }
                 else
                 {
                     optionsList.Add(opt);
                 }
             }
         }
         if (maxCount == 0)
         {
             DoQueryCount dqryCnt;
             if (string.IsNullOrEmpty(query))
                 dqryCnt = new DoQueryCount.Builder(Application.Client.Ticket, Application.Token, Application.Client.AccountDomain, TableId)
                     .Build();
             else
                 dqryCnt = new DoQueryCount.Builder(Application.Client.Ticket, Application.Token, Application.Client.AccountDomain, TableId)
                     .SetQuery(query)
                     .Build();
             var cntXml = dqryCnt.Post().CreateNavigator();
             maxCount = int.Parse(cntXml.SelectSingleNode("/qdbapi/numMatches").Value);
         }
         int stride = maxCount/2;
         int fetched = 0;
         while (fetched < maxCount)
         {
             List<string> optLst = new List<string>();
             optLst.AddRange(optionsList);
             optLst.Add("skp-" + (fetched + baseSkip));
             optLst.Add("num-" + stride);
             string options = string.Join(".",optLst);
             DoQuery dqry;
             if (string.IsNullOrEmpty(query))
                dqry = new DoQuery.Builder(Application.Client.Ticket, Application.Token, Application.Client.AccountDomain, TableId)
                    .SetCList(collist)
                    .SetOptions(options)
                    .SetFmt(true)
                    .Build();
             else
                dqry = new DoQuery.Builder(Application.Client.Ticket, Application.Token, Application.Client.AccountDomain, TableId)
                    .SetQuery(query)
                    .SetCList(collist)
                    .SetOptions(options)
                    .SetFmt(true)
                    .Build();
             try
             {
                 XPathNavigator xml = dqry.Post().CreateNavigator();
                 if (fetched == 0) LoadColumns(xml);
                 LoadRecords(xml);
                 fetched += stride;
             }
             catch (ViewTooLargeException)
             {
                 stride = stride/2;
             }
         }
     }
 }