private static SqlType GetDataType(System.Data.LibCore.Clr.UtlMetaData metaData) { SqlType defaultType = SqlType.GetDefaultType((int)metaData.UtlDbType); if (defaultType.AcceptsPrecision()) { defaultType.Precision = metaData.Precision; } if (defaultType.AcceptsScale()) { defaultType.Scale = metaData.Scale; } return(defaultType); }
public override DataTable GetSchemaTable() { this.CheckClosed(); if ((this._rResult == null) || (!this._rResult.IsData() && ((this._commandBehavior & CommandBehavior.SchemaOnly) == CommandBehavior.Default))) { throw UtlException.GetException(0x1ca); } DataTable table = new DataTable("SchemaTable"); ResultMetaData metaData = this._rResult.MetaData; table.Locale = CultureInfo.InvariantCulture; table.Columns.Add(SchemaTableColumn.ColumnName, typeof(string)); table.Columns.Add(SchemaTableColumn.ColumnOrdinal, typeof(int)); table.Columns.Add(SchemaTableColumn.ColumnSize, typeof(long)); table.Columns.Add(SchemaTableColumn.NumericPrecision, typeof(long)); table.Columns.Add(SchemaTableColumn.NumericScale, typeof(short)); table.Columns.Add(SchemaTableColumn.IsUnique, typeof(bool)); table.Columns.Add(SchemaTableColumn.IsKey, typeof(bool)); table.Columns.Add(SchemaTableOptionalColumn.BaseServerName, typeof(string)); table.Columns.Add(SchemaTableOptionalColumn.BaseCatalogName, typeof(string)); table.Columns.Add(SchemaTableColumn.BaseColumnName, typeof(string)); table.Columns.Add(SchemaTableColumn.BaseSchemaName, typeof(string)); table.Columns.Add(SchemaTableColumn.BaseTableName, typeof(string)); table.Columns.Add(SchemaTableColumn.DataType, typeof(Type)); table.Columns.Add(SchemaTableColumn.AllowDBNull, typeof(bool)); table.Columns.Add(SchemaTableColumn.ProviderType, typeof(int)); table.Columns.Add(SchemaTableColumn.IsAliased, typeof(bool)); table.Columns.Add(SchemaTableColumn.IsExpression, typeof(bool)); table.Columns.Add(SchemaTableOptionalColumn.IsAutoIncrement, typeof(bool)); table.Columns.Add(SchemaTableOptionalColumn.IsRowVersion, typeof(bool)); table.Columns.Add(SchemaTableOptionalColumn.IsHidden, typeof(bool)); table.Columns.Add(SchemaTableColumn.IsLong, typeof(bool)); table.Columns.Add(SchemaTableOptionalColumn.IsReadOnly, typeof(bool)); table.Columns.Add(SchemaTableOptionalColumn.ProviderSpecificDataType, typeof(Type)); table.Columns.Add(SchemaTableOptionalColumn.DefaultValue, typeof(string)); DataTable schema = null; DataTable table3 = null; if ((this._commandBehavior & CommandBehavior.KeyInfo) != CommandBehavior.Default) { string[] restrictionValues = new string[6]; restrictionValues[1] = metaData.columns[0].GetSchemaNameString(); restrictionValues[2] = metaData.columns[0].GetTableNameString(); restrictionValues[5] = "true"; schema = this._command.Connection.GetSchema("INDEXCOLUMNS", restrictionValues); string[] textArray2 = new string[3]; textArray2[1] = metaData.columns[0].GetSchemaNameString(); textArray2[2] = metaData.columns[0].GetTableNameString(); table3 = this._command.Connection.GetSchema("COLUMNS", textArray2); } table.BeginLoadData(); for (int i = 0; i < metaData.GetColumnCount(); i++) { DataRow row = table.NewRow(); if ((metaData.ColumnLabels[i] == null) && string.IsNullOrEmpty(metaData.columns[i].GetNameString())) { row[SchemaTableColumn.ColumnName] = DBNull.Value; } else { row[SchemaTableColumn.ColumnName] = metaData.ColumnLabels[i] ?? metaData.columns[i].GetNameString(); } row[SchemaTableColumn.ColumnOrdinal] = i; row[SchemaTableColumn.ColumnSize] = metaData.ColumnTypes[i].GetAdoPrecision(); row[SchemaTableColumn.ProviderType] = metaData.ColumnTypes[i].GetAdoTypeCode(); SqlType type = metaData.ColumnTypes[i]; if (type.IsNumberType()) { if (type.AcceptsPrecision()) { row[SchemaTableColumn.NumericPrecision] = ((NumberType)metaData.ColumnTypes[i]).GetNumericPrecisionInRadix(); } else { row[SchemaTableColumn.NumericPrecision] = DBNull.Value; } if (type.AcceptsScale()) { row[SchemaTableColumn.NumericScale] = type.GetAdoScale(); } else { row[SchemaTableColumn.NumericScale] = DBNull.Value; } } row[SchemaTableColumn.IsLong] = type.IsLobType(); row[SchemaTableColumn.AllowDBNull] = metaData.columns[i].GetNullability() > 0; row[SchemaTableOptionalColumn.IsReadOnly] = !metaData.columns[i].IsWriteable(); row[SchemaTableOptionalColumn.IsAutoIncrement] = metaData.columns[i].IsIdentity(); row[SchemaTableOptionalColumn.IsHidden] = false; row[SchemaTableOptionalColumn.IsRowVersion] = false; row[SchemaTableColumn.IsUnique] = false; row[SchemaTableColumn.IsKey] = false; row[SchemaTableColumn.DataType] = this.GetFieldType(i); if (string.IsNullOrEmpty(metaData.columns[i].GetNameString())) { row[SchemaTableColumn.BaseColumnName] = DBNull.Value; } else { row[SchemaTableColumn.BaseColumnName] = metaData.columns[i].GetNameString(); } row[SchemaTableColumn.IsExpression] = string.IsNullOrEmpty(metaData.columns[i].GetNameString()); row[SchemaTableColumn.IsAliased] = string.Compare(metaData.columns[i].GetNameString(), metaData.ColumnLabels[i], StringComparison.OrdinalIgnoreCase) > 0; if (string.IsNullOrEmpty(metaData.columns[i].GetTableNameString())) { row[SchemaTableColumn.BaseTableName] = DBNull.Value; } else { row[SchemaTableColumn.BaseTableName] = metaData.columns[i].GetTableNameString(); } if (string.IsNullOrEmpty(metaData.columns[i].GetCatalogNameString())) { row[SchemaTableOptionalColumn.BaseCatalogName] = "PUBLIC"; } else { row[SchemaTableOptionalColumn.BaseCatalogName] = metaData.columns[i].GetCatalogNameString(); } if (string.IsNullOrEmpty(metaData.columns[i].GetSchemaNameString())) { row[SchemaTableColumn.BaseSchemaName] = DBNull.Value; } else { row[SchemaTableColumn.BaseSchemaName] = metaData.columns[i].GetSchemaNameString(); } if ((this._commandBehavior & CommandBehavior.KeyInfo) != CommandBehavior.Default) { Dictionary <string, string> dictionary = new Dictionary <string, string>(); for (int j = 0; j < schema.Rows.Count; j++) { string key = (string)schema.Rows[j]["INDEX_NAME"]; if (!dictionary.ContainsKey(key)) { dictionary.Add(key, (string)schema.Rows[j]["COLUMN_NAME"]); } else { dictionary[key] = string.Empty; } } foreach (string str2 in dictionary.Keys) { if (!string.IsNullOrEmpty(dictionary[str2]) && (string.Compare(metaData.columns[i].GetNameString(), dictionary[str2], StringComparison.OrdinalIgnoreCase) == 0)) { row[SchemaTableColumn.IsUnique] = true; } } for (int k = 0; k < table3.Rows.Count; k++) { if (string.Compare(metaData.columns[i].GetNameString(), (string)table3.Rows[k]["COLUMN_NAME"], StringComparison.OrdinalIgnoreCase) == 0) { row[SchemaTableOptionalColumn.DefaultValue] = table3.Rows[k]["COLUMN_DEF"]; row[SchemaTableColumn.IsKey] = table3.Rows[k]["IS_PRIMARY_KEY"]; } } } table.Rows.Add(row); } table.AcceptChanges(); table.EndLoadData(); return(table); }