コード例 #1
0
ファイル: TableOut.cs プロジェクト: fjiang2/sqlcon
        public static string ToJson(DataTable dt)
        {
            //array
            if (dt.Columns.Count == 1)
            {
                //string name = dt.Columns[0].ColumnName;
                string json = VAL.Boxing(dt.ToArray(row => row[0])).ToJson();
                //string.Format("{0}={1}", name, json);
                return json;
            }

            string[] columns = dt.Columns.Cast<DataColumn>().Select(col => col.ColumnName).ToArray();
            VAL L = new VAL();
            foreach (DataRow row in dt.Rows)
            {
                VAL V = new VAL();
                for (int i = 0; i < columns.Length; i++)
                {
                    V.AddMember(columns[i], row[i]);
                }
                L.Add(V);
            }

            return L.ToJson();
        }
コード例 #2
0
ファイル: DataLakeExtension.cs プロジェクト: fjiang2/sqlcon
        private static string ToJson(JsonStyle style, VAL val)
        {
            switch (style)
            {
            case JsonStyle.Coded:
                return(val.ToString());

            case JsonStyle.Extended:
                return(val.ToExJson());
            }

            return(val.ToJson());
        }
コード例 #3
0
        private static void _DisplayColumnNodes(ApplicationCommand cmd, TableName tname)
        {
            TableSchema schema = new TableSchema(tname);

            cout.WriteLine("TABLE: {0}", tname.Path);

            bool hasJson = cmd.Has("json");
            VAL  lines   = new VAL();

            int i     = 0;
            int count = 0;
            int h     = 0;

            foreach (IColumn column in schema.Columns)
            {
                if (IsMatch(cmd.wildcard, column.ColumnName))
                {
                    count++;

                    List <string> L = new List <string>();
                    if (column.IsIdentity)
                    {
                        L.Add("++");
                    }
                    if (column.IsPrimary)
                    {
                        L.Add("pk");
                    }

                    string       fk  = string.Empty;
                    ColumnSchema col = column as ColumnSchema;
                    if (col.IsForeignKey)
                    {
                        L.Add("fk");
                        if (cmd.HasForeignKey)
                        {
                            fk = $"-> {col.PK_Schema}.[{col.PK_Table}].[{col.PK_Column}]";
                        }
                    }

                    string keys = string.Join(",", L);

                    if (!hasJson)
                    {
                        cout.WriteLine("{0,5} {1,26} {2,-16} {3,10} {4,10} {5}",
                                       sub(++i),
                                       string.Format("[{0}]", column.ColumnName),
                                       column.GetSQLType(),
                                       keys,
                                       column.Nullable ? "null" : "not null",
                                       fk);
                    }
                    else
                    {
                        VAL line = new VAL();
                        if (keys != "")
                        {
                            line.AddMember("Key", keys);
                        }
                        line.AddMember("Column", column.ColumnName);
                        line.AddMember("Type", column.GetSQLType());
                        if (column.Nullable)
                        {
                            line.AddMember("Null", column.Nullable);
                        }
                        lines.Add(line);
                    }

                    h = PagePause(cmd, ++h);
                }
            }

            if (!hasJson)
            {
                cout.WriteLine("\t{0} Column(s)", count);
            }
            else
            {
                cout.WriteLine(lines.ToJson());
            }
        }