/// <summary> /// Obtiene el esquema /// </summary> internal async Task <SchemaDbModel> GetSchemaAsync(PostgreSqlProvider provider, TimeSpan timeout, CancellationToken cancellationToken) { var schema = new SchemaDbModel(); // Abre la conexión provider.Open(); // Carga los datos using (DbDataReader rdoData = await provider.ExecuteReaderAsync(GetSqlReadSchema(), null, CommandType.Text, timeout, cancellationToken)) { while (!cancellationToken.IsCancellationRequested && await rdoData.ReadAsync(cancellationToken)) { schema.Add(rdoData.IisNull <string>("TableType").Equals("TABLE", StringComparison.CurrentCultureIgnoreCase), rdoData.IisNull <string>("SchemaName"), rdoData.IisNull <string>("TableName"), rdoData.IisNull <string>("ColumnName"), GetFieldType(rdoData.IisNull <string>("ColumnType")), rdoData.IisNull <string>("ColumnType"), rdoData.IisNull <int>("ColumnLength", 0), rdoData.IisNull <int>("PrimaryKey") == 1, rdoData.IisNull <int>("IsRequired") == 1); } } // Cierra la conexión provider.Close(); // Devuelve el esquema return(schema); }
/// <summary> /// Obtiene el esquema /// </summary> internal async Task <SchemaDbModel> GetSchemaAsync(SparkProvider provider, TimeSpan timeout, CancellationToken cancellationToken) { SchemaDbModel schema = new SchemaDbModel(); List <string> tables = new List <string>(); // Obtiene el esquema using (OdbcConnection connection = new OdbcConnection(provider.ConnectionString.ConnectionString)) { // Abre la conexión await connection.OpenAsync(cancellationToken); // Obtiene las tablas using (DataTable table = connection.GetSchema("Tables")) { foreach (DataRow row in table.Rows) { if (!cancellationToken.IsCancellationRequested && row.IisNull <string>("Table_Type").Equals("TABLE", StringComparison.CurrentCultureIgnoreCase)) { tables.Add(row.IisNull <string>("Table_Name")); } } } // Carga las columnas if (!cancellationToken.IsCancellationRequested) { using (DataTable table = connection.GetSchema("Columns")) { foreach (DataRow row in table.Rows) { if (!cancellationToken.IsCancellationRequested && tables.FirstOrDefault(item => item.Equals(row.IisNull <string>("Table_Name"), StringComparison.CurrentCultureIgnoreCase)) != null) { schema.Add(true, row.IisNull <string>("Table_Schem"), row.IisNull <string>("Table_Name"), row.IisNull <string>("Column_Name"), GetFieldType(row.IisNull <string>("Type_Name")), row.IisNull <string>("Type_Name"), row.IisNull <int>("Column_Size", 0), false, row.IisNull <string>("Is_Nullable").Equals("No", StringComparison.CurrentCultureIgnoreCase)); } } } } // Cierra la conexión connection.Close(); } // Devuelve el esquema return(schema); }