private static DbDataReader CreateReader(object result)
        {
            if (result == null)
            {
                return(KdbPlusDataReader.CreateEmptyReader());
            }

            Type resultType = result.GetType();

            // table is returned from k+ as flip
            if (resultType == _flipType)
            {
                return(new KdbPlusDataReader((c.Flip)result));
            }

            // result returned as dict
            if (resultType == _dictType)
            {
                return(new KdbPlusDataReader(c.td(result)));
            }

            // collection is returned
            if (result as IEnumerable != null)
            {
                return(KdbPlusDataReader.CreateReaderFromCollection(result));
            }

            // primitive e.g. count is returned
            return(KdbPlusDataReader.CreateReaderFromPrimitive(result));
        }
Beispiel #2
0
        /// <summary>
        /// Converts c.Dict into DataTable.
        /// </summary>
        /// <param name="dict">The dict.</param>
        /// <param name="tableName">Name of the table.</param>
        /// <returns></returns>
        public static DataTable ToDataTable(this c.Dict dict, string tableName)
        {
            Guard.ThrowIfNull(dict, "dict");
            if (String.IsNullOrEmpty(tableName))
            {
                tableName = "Table1";
            }

            KdbPlusDataReader reader = new KdbPlusDataReader(new c.Flip(dict));

            DataTable table = new DataTable(tableName);

            table.Load(reader);

            return(table);
        }
Beispiel #3
0
        private static DataReaderCollection CreateReaders(c.Dict kdbResult)
        {
            Dictionary <string, IDataReader> tableReaders = new Dictionary <string, IDataReader>();

            string[] tableNames = (string[])kdbResult.x;

            object[] tables = (object[])kdbResult.y;

            for (int i = 0; i < tableNames.Length; i++)
            {
                object[] temp = tables[i] as object[];
                if (temp != null && temp.Length == 0)
                {
                    tableReaders[tableNames[i]] = KdbPlusDataReader.CreateEmptyReader();
                }
                else
                {
                    tableReaders[tableNames[i]] = new KdbPlusDataReader(c.td(tables[i]));
                }
            }

            return(new DataReaderCollection(tableReaders));
        }