コード例 #1
0
        private static DataTable DescribeColumns(ClickHouseConnection connection, string[] restrictions)
        {
            var query    = new StringBuilder("SELECT database as Database, table as Table, name as Name, type as ProviderType, type as DataType FROM system.columns");
            var database = restrictions != null && restrictions.Length > 0 ? restrictions[0] : null;
            var table    = restrictions != null && restrictions.Length > 1 ? restrictions[1] : null;

            if (database != null)
            {
                query.Append($" WHERE database='{database}'");
            }

            if (table != null)
            {
                query.Append($" AND table='{table}'");
            }

            var result = connection.ExecuteDataTable(query.ToString());

            foreach (var row in result.Rows.Cast <DataRow>())
            {
                var clickHouseType = TypeConverter.ParseClickHouseType((string)row["ProviderType"]);
                row["ProviderType"] = clickHouseType.ToString();
                // TODO: this should return actual framework type like other implementations do
                row["DataType"] = clickHouseType.FrameworkType.ToString().Replace("System.", string.Empty);
            }

            return(result);
        }