示例#1
0
        public void Test_run_return_table_toDataTable_char()
        {
            DBConnection db = new DBConnection();

            db.connect(SERVER, PORT);
            BasicTable tb = (BasicTable)db.run("table(1 as id,'a' as name)");
            DataTable  dt = tb.toDataTable();
        }
示例#2
0
        public static void ExportDDBTableToWorksheet(BasicTable tb, ImportOpt opt)
        {
            List <string> format = new List <string>();

            for (int i = 0; i != tb.columns(); i++)
            {
                DATA_TYPE colType = tb.getColumn(i).getDataType();
                format.Add(DDBExcelNumericFormater.GetFormat(colType));
            }
            ExportDataTableToWorksheet(tb.toDataTable(), opt, format);
        }
示例#3
0
        public void Test_run_return_table_toDataTable()
        {
            string       script = @"table(take(0b 1b, 10) as tBOOL, char(1..10) as tCHAR, short(1..10) as tSHORT, int(1..10) as tINT, long(1..10) as tLONG, 2000.01.01 + 1..10 as tDATE, 2000.01M + 1..10 as tMONTH, 13:30:10.008 + 1..10 as tTIME, 13:30m + 1..10 as tMINUTE, 13:30:10 + 1..10 as tSECOND, 2012.06.13T13:30:10 + 1..10 as tDATETIME, 2012.06.13T13:30:10.008 + 1..10 as tTIMESTAMP,09:00:01.000100001 + 1..10 as tNANOTIME,2016.12.30T09:00:01.000100001 + 1..10 as tNANOTIMESTAMP, 2.1f + 1..10 as tFLOAT, 2.1 + 1..10 as tDOUBLE, take(`A`B`C`D, 10) as tSYMBOL)";
            DBConnection db     = new DBConnection();

            db.connect(SERVER, PORT);
            BasicTable tb = (BasicTable)db.run(script);
            DataTable  dt = tb.toDataTable();

            Assert.AreEqual(10, dt.Rows.Count);
            Assert.AreEqual("3", dt.Rows[2]["tSHORT"].ToString());
        }
示例#4
0
        public void Test_GetNullTable()
        {
            string       sql = "t=table(10:0,`id`str`long`double,[INT,STRING,LONG,DOUBLE]);insert into t values(1,NULL,NULL,NULL);t";
            DBConnection db  = new DBConnection();

            db.connect(SERVER, PORT);
            BasicTable bt = (BasicTable)db.run(sql);
            DataTable  dt = bt.toDataTable();

            Assert.AreEqual(DBNull.Value, dt.Rows[0][1]);
            Assert.AreEqual(DBNull.Value, dt.Rows[0][2]);
            Assert.AreEqual(DBNull.Value, dt.Rows[0][3]);
        }
示例#5
0
        public static DataTable RunScriptAndFetchResultAsTable(DBConnection conn, string script)
        {
            BasicTable tb = RunScriptAndFetchResultAsBasicTable(conn, script);

            return(tb.toDataTable());
        }
示例#6
0
        /*
         *  return null if get DT_VOID
         *  return table or throw exception if not DT_VOID
         */
        public static TableResult RunScriptAndFetchResultAsDataTable(DBConnection conn, string script)
        {
            IEntity entity = RunScript(conn, script);

            if (entity.getDataType() == DATA_TYPE.DT_VOID)
            {
                return(null);
            }

            TableResult result = new TableResult
            {
                srcForm       = entity.getDataForm(),
                columnSrcType = new List <DATA_TYPE>()
            };

            if (entity.isTable())
            {
                BasicTable basicTable = entity as BasicTable;
                for (int i = 0; i != basicTable.columns(); i++)
                {
                    result.columnSrcType.Add(basicTable.getColumn(i).getDataType());
                }

                result.table = basicTable.toDataTable();
                return(result);
            }

            result.table = entity.toDataTable();

            if (entity.isDictionary())
            {
                BasicDictionary basicDictionary = entity as BasicDictionary;
                result.columnSrcType.Add(basicDictionary.KeyDataType);
                result.columnSrcType.Add(basicDictionary.getDataType());
                return(result);
            }

            if (entity.isMatrix())
            {
                IMatrix m         = entity as IMatrix;
                IVector colLabels = m.getColumnLabels();
                if (!(colLabels == null || colLabels.columns() == 0))
                {
                    result.matrix_ColumnLabels = new List <string>();
                    for (int i = 0; i != colLabels.rows(); i++)
                    {
                        result.matrix_ColumnLabels.Add(colLabels.get(i).getString());
                    }
                }

                IVector rowLabels = m.getRowLabels();
                if (!(rowLabels == null || rowLabels.columns() == 0))
                {
                    result.matrix_RowLabels = new List <string>();
                    for (int i = 0; i != rowLabels.rows(); i++)
                    {
                        result.matrix_RowLabels.Add(rowLabels.get(i).getString());
                    }
                }
            }

            for (int i = 0; i != result.table.Columns.Count; i++)
            {
                result.columnSrcType.Add(entity.getDataType());
            }
            return(result);
        }