コード例 #1
0
        /// <summary>
        /// Merge data cache and table to the result
        /// </summary>
        /// <param name="qrDataCache">data cache</param>
        /// <param name="table">table from server</param>
        /// <param name="result">add the merge table to result</param>
        private void MergeDataCache(QueryResult qrDataCache, Hubble.Framework.Data.DataTable table, QueryResult result)
        {
            int  i    = 0;
            bool find = false;

            for (; i < qrDataCache.DataSet.Tables.Count; i++)
            {
                if (qrDataCache.DataSet.Tables[i].TableName.Equals(table.TableName, StringComparison.CurrentCultureIgnoreCase))
                {
                    find = true;
                    break;
                }
            }

            if (find)
            {
                Hubble.Framework.Data.DataTable[] tables = new Hubble.Framework.Data.DataTable[qrDataCache.DataSet.Tables.Count];
                qrDataCache.DataSet.Tables.CopyTo(tables, 0);

                do
                {
                    qrDataCache.DataSet.Tables.Remove(tables[i]);
                    result.AddDataTable(tables[i]);

                    if (++i >= tables.Length)
                    {
                        break;
                    }
                }while (!IsSelectOrSpTalbe(tables[i]));
            }
        }
コード例 #2
0
        public Hubble.Core.Query.DocumentResultForSort[] Distinct(
            Hubble.Core.Query.DocumentResultForSort[] result, out Hubble.Framework.Data.DataTable table)
        {
            Init();

            Dictionary <ulong, int> distinctByDict = new Dictionary <ulong, int>(); //key is the value of the distinct fields, value is distinct count

            table = null;
            List <Hubble.Core.Query.DocumentResultForSort> distinctResult =
                new List <Hubble.Core.Query.DocumentResultForSort>();

            for (int i = 0; i < result.Length; i++)
            {
                ulong key = GetKey(ref result[i]);

                int count;

                if (distinctByDict.TryGetValue(key, out count))
                {
                    distinctByDict[key] = count + 1;

                    if (count + 1 <= _DistinctCount)
                    {
                        distinctResult.Add(result[i]);
                    }
                }
                else
                {
                    distinctByDict.Add(key, 1);
                    distinctResult.Add(result[i]);
                }
            }

            return(distinctResult.ToArray());
        }
コード例 #3
0
ファイル: Document.cs プロジェクト: wj60387/hubble
        public static Hubble.Framework.Data.DataSet ToDataSet(List <Field> schema, List <Document> docs)
        {
            Hubble.Framework.Data.DataTable dt = new Hubble.Framework.Data.DataTable();

            foreach (Field field in  schema)
            {
                Hubble.Framework.Data.DataColumn col = new Hubble.Framework.Data.DataColumn(field.Name,
                                                                                            DataTypeConvert.GetClrType(field.DataType));
                dt.Columns.Add(col);
            }

            foreach (Document doc in docs)
            {
                Hubble.Framework.Data.DataRow row = dt.NewRow();

                foreach (FieldValue fv in doc.FieldValues)
                {
                    if (fv.Value == null)
                    {
                        row[fv.FieldName] = System.DBNull.Value;
                    }
                    else
                    {
                        Type type = DataTypeConvert.GetClrType(fv.Type);

                        if (fv.Type == DataType.TinyInt)
                        {
                            bool bitValue;

                            //check the bit data type of database
                            if (bool.TryParse(fv.Value, out bitValue))
                            {
                                if (bitValue)
                                {
                                    row[fv.FieldName] = (byte)1;
                                }
                                else
                                {
                                    row[fv.FieldName] = (byte)0;
                                }

                                continue;
                            }
                        }

                        row[fv.FieldName] =
                            System.ComponentModel.TypeDescriptor.GetConverter(type).ConvertFrom(fv.Value);
                    }
                }

                dt.Rows.Add(row);
            }

            Hubble.Framework.Data.DataSet ds = new Hubble.Framework.Data.DataSet();
            ds.Tables.Add(dt);
            return(ds);
        }
コード例 #4
0
ファイル: ParseGroupByCount.cs プロジェクト: wj60387/hubble
        unsafe private Hubble.Framework.Data.DataTable GetTable(ulong[] keyList, int relCount)
        {
            GroupByPair[] groupByPair = GetGroupByPairs(keyList, relCount);
            //GroupByPair[] groupByPair = new GroupByPair[groupByDict.Count];

            //int i = 0;

            //foreach(ulong key in groupByDict.Keys)
            //{
            //    groupByPair[i++] = new GroupByPair(key, groupByDict[key]);
            //}

            Array.Sort(groupByPair);

            Hubble.Framework.Data.DataTable table = new Hubble.Framework.Data.DataTable();

            foreach (Field field in _GroupByFields)
            {
                Hubble.Framework.Data.DataColumn col = new Hubble.Framework.Data.DataColumn(field.Name,
                                                                                            DataTypeConvert.GetClrType(field.DataType));

                table.Columns.Add(col);
            }

            table.Columns.Add(new Hubble.Framework.Data.DataColumn("Count", typeof(int)));

            foreach (GroupByPair gbp in groupByPair)
            {
                Hubble.Framework.Data.DataRow row = table.NewRow();

                int preDataLength = 0;
                int col           = _GroupByFields.Count - 1;

                for (; col >= 0; col--)
                {
                    row[col] = GetFieldValue(_GroupByFields[col], ref preDataLength, gbp.Key);
                }

                row[_GroupByFields.Count] = gbp.Count;

                table.Rows.Add(row);

                if (table.Rows.Count >= _Top)
                {
                    break;
                }
            }

            table.TableName       = "GroupByCount_" + _GroupByFieldsString;
            table.MinimumCapacity = groupByPair.Length;

            return(table);
        }
コード例 #5
0
 private bool IsSelectOrSpTalbe(Hubble.Framework.Data.DataTable table)
 {
     if (table.TableName.IndexOf("Select_", 0, StringComparison.CurrentCultureIgnoreCase) == 0)
     {
         return(true);
     }
     else if (table.TableName.IndexOf("StoreProc_", 0, StringComparison.CurrentCultureIgnoreCase) == 0)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
コード例 #6
0
ファイル: StoredProcedure.cs プロジェクト: wj60387/hubble
        protected void AddColumn(string columnName)
        {
            if (_QueryResult.DataSet.Tables.Count == 0)
            {
                _QueryResult.DataSet.Tables.Add(new Hubble.Framework.Data.DataTable());
            }

            Hubble.Framework.Data.DataTable table = _QueryResult.DataSet.Tables[0];

            table.TableName = "StoreProc_" + Name;

            Hubble.Framework.Data.DataColumn col = new Hubble.Framework.Data.DataColumn(columnName);

            table.Columns.Add(col);
        }
コード例 #7
0
ファイル: StoredProcedure.cs プロジェクト: wj60387/hubble
        protected void OutputValue(string columnName, object value)
        {
            Hubble.Framework.Data.DataTable table = _QueryResult.DataSet.Tables[0];

            if (table.Rows.Count == 0)
            {
                table.Rows.Add(table.NewRow());
            }

            if (value == null)
            {
                table.Rows[table.Rows.Count - 1][columnName] = DBNull.Value;
            }
            else
            {
                table.Rows[table.Rows.Count - 1][columnName] = value;
            }
        }
コード例 #8
0
        public void AddDataTable(Hubble.Framework.Data.DataTable table)
        {
            string tableName = table.TableName;

            int  serial = 0;
            bool find   = false;

            foreach (Hubble.Framework.Data.DataTable tb in DataSet.Tables)
            {
                int index = tb.TableName.IndexOf(tableName, 0, StringComparison.CurrentCultureIgnoreCase);

                if (index >= 0)
                {
                    find = true;

                    string serialStr = tb.TableName.Substring(index + tableName.Length);

                    if (serialStr == "")
                    {
                        continue;
                    }
                    else
                    {
                        serial = int.Parse(serialStr);
                        serial++;
                    }
                }
            }

            if (find)
            {
                table.TableName = tableName + serial.ToString();
            }

            DataSet.Tables.Add(table);
        }
コード例 #9
0
ファイル: StoredProcedure.cs プロジェクト: wj60387/hubble
        protected void NewRow()
        {
            Hubble.Framework.Data.DataTable table = _QueryResult.DataSet.Tables[0];

            table.Rows.Add(table.NewRow());
        }