public ViewColumnSchema[] GetViewColumns(string connectionString, ViewSchema view)
        {
            var columns = new List <ViewColumnSchema>();

            string sql = string.Format("SELECT * FROM GetViewColumns('{0}')", view.Name);

            using (VistaDBConnection connection = GetConnection(connectionString))
                using (var adapter = new VistaDBDataAdapter(sql, connection))
                    using (var table = new DataTable())
                    {
                        adapter.Fill(table);

                        foreach (DataRow row in table.Rows)
                        {
                            string name       = row["COLUMN_NAME"].ToString();
                            string nativeType = row["DATA_TYPE_NAME"].ToString();
                            var    size       = (int)(row["COLUMN_SIZE"] ?? 0);
                            var    allowNull  = (bool)(row["ALLOW_NULL"] ?? true);

                            var column = new ViewColumnSchema(
                                view, name, GetDbType(nativeType),
                                nativeType, size, 0, 0, allowNull);

                            columns.Add(column);
                        }
                    }

            return(columns.ToArray());
        }
Beispiel #2
0
        public ViewColumnSchema[] GetViewColumns(string connectionString, ViewSchema view)
        {
            DataTable dt = GetSchemaData(connectionString,
                                         Columns,
                                         null /*restrictions[0] - catalog*/,
                                         null /*restrictions[1] - unused*/,
                                         view.Name /*restrictions[2] - table*/,
                                         null /*restrictions[3] - column*/);

            var extendedProperties = new List <ExtendedProperty>();
            var columns            = new ViewColumnSchema[dt.Rows.Count];
            int columnIndex        = 0;

            foreach (DataRow dr in dt.Rows)
            {
                string name        = (string)dr[ColumnsNameColumn];
                string nativeType  = dr.IsNull(ColumnsTypeColumn) ? "text" : (string)dr[ColumnsTypeColumn];
                DbType dbType      = DbTypeFromType(connectionString, nativeType);
                bool   allowDBNull = dr.IsNull(ColumnsNullableColumn) || (bool)dr[ColumnsNullableColumn];
                int    size        = dr.IsNull(ColumnsSize) ? 0 : (int)dr[ColumnsSize];
                int    precision   = dr.IsNull(ColumnsPrecision) ? 0 : (int)dr[ColumnsPrecision];
                int    scale       = dr.IsNull(ColumnsScale) ? 0 : (int)dr[ColumnsScale];

                int    ordinalPosition = dr.IsNull("ORDINAL_POSITION") ? 0 : (int)dr["ORDINAL_POSITION"];
                string edmType         = dr.IsNull("EDM_TYPE") ? "String" : (string)dr["EDM_TYPE"];
                bool   isAutoIncrement = !dr.IsNull("AUTOINCREMENT") && (bool)dr["AUTOINCREMENT"];
                bool   isUnique        = !dr.IsNull("UNIQUE") && (bool)dr["UNIQUE"];
                bool   hasDefault      = !dr.IsNull("COLUMN_HASDEFAULT") && (bool)dr["COLUMN_HASDEFAULT"];
                string columnDefault   = dr.IsNull("COLUMN_DEFAULT") ? string.Empty : (string)dr["COLUMN_DEFAULT"];
                string collation       = dr.IsNull("COLLATION_NAME") ? string.Empty : (string)dr["COLLATION_NAME"];

                extendedProperties.Clear();
                extendedProperties.Add(ExtendedProperty.Readonly(ExtendedPropertyNames.Description, ""));
                extendedProperties.Add(ExtendedProperty.Readonly(ExtendedPropertyNames.ObjectID, ordinalPosition));
                extendedProperties.Add(ExtendedProperty.Readonly(ExtendedPropertyNames.IsIdentity, isAutoIncrement));
                extendedProperties.Add(ExtendedProperty.Readonly("CS_IsUnique", isUnique));     // Added for backwards compatibility.
                extendedProperties.Add(ExtendedProperty.Readonly("CS_HasDefault", hasDefault)); // Added for backwards compatibility.
                extendedProperties.Add(ExtendedProperty.Readonly(ExtendedPropertyNames.DefaultValue, columnDefault));
                extendedProperties.Add(ExtendedProperty.Readonly(ExtendedPropertyNames.Collation, collation));
                extendedProperties.Add(ExtendedProperty.Readonly(ExtendedPropertyNames.SystemType, edmType));
                extendedProperties.Add(ExtendedProperty.Readonly("CS_SQLiteType", edmType));  // Added for backwards compatibility.


                var col = new ViewColumnSchema(view, name, dbType, nativeType, size,
                                               Convert.ToByte(precision), scale, allowDBNull,
                                               extendedProperties.ToArray());

                columns[columnIndex++] = col;
            }

            return(columns);
        }