public virtual Recordset FetchRecordset(DbService dbService, bool addFields) { if (dbService == null) { throw new ArgumentNullException("dbService"); } var source = dbService.Source as DbSource; if (source != null) { switch (source.ServerType) { case enSourceType.SqlDatabase: { var broker = CreateDatabaseBroker(); var outputDescription = broker.TestService(dbService); if (outputDescription == null || outputDescription.DataSourceShapes == null || outputDescription.DataSourceShapes.Count == 0) { throw new Exception("Error retrieving shape from service output."); } dbService.Recordset.Name = dbService.Recordset.Name.Replace(".", "_"); dbService.Recordset.Fields.Clear(); ServiceMappingHelper smh = new ServiceMappingHelper(); smh.MapDbOutputs(outputDescription, ref dbService, addFields); return(dbService.Recordset); } case enSourceType.MySqlDatabase: { var broker = new MySqlDatabaseBroker(); var outputDescription = broker.TestService(dbService); if (outputDescription == null || outputDescription.DataSourceShapes == null || outputDescription.DataSourceShapes.Count == 0) { throw new Exception("Error retrieving shape from service output."); } dbService.Recordset.Name = dbService.Recordset.Name.Replace(".", "_"); dbService.Recordset.Fields.Clear(); ServiceMappingHelper smh = new ServiceMappingHelper(); smh.MySqlMapDbOutputs(outputDescription, ref dbService, addFields); return(dbService.Recordset); } default: return(null); } } return(null); // Clear out the Recordset.Fields list because the sequence and // number of fields may have changed since the last invocation. // // Create a copy of the Recordset.Fields list before clearing it // so that we don't lose the user-defined aliases. // }
private Recordset FetchDbSourceRecordset(ref DbService dbService, bool addFields, DbSource source) { switch (source.ServerType) { case enSourceType.SqlDatabase: { var broker = new SqlDatabaseBroker { CommandTimeout = dbService.CommandTimeout }; var outputDescription = broker.TestService(dbService); if (outputDescription?.DataSourceShapes == null || outputDescription.DataSourceShapes.Count == 0) { throw new Exception(ErrorResource.ErrorRetrievingShapeFromServiceOutput); } if (dbService.Recordset != null) { dbService.Recordset.Name = dbService.Method.ExecuteAction; if (dbService.Recordset.Name != null) { dbService.Recordset.Name = dbService.Recordset.Name.Replace(".", "_"); } dbService.Recordset.Fields.Clear(); var smh = new ServiceMappingHelper(); smh.MapDbOutputs(outputDescription, ref dbService, addFields); } return(dbService.Recordset); } case enSourceType.MySqlDatabase: { var broker = new MySqlDatabaseBroker { CommandTimeout = dbService.CommandTimeout }; var outputDescription = broker.TestService(dbService); if (outputDescription?.DataSourceShapes == null || outputDescription.DataSourceShapes.Count == 0) { throw new Exception(ErrorResource.ErrorRetrievingShapeFromServiceOutput); } dbService.Recordset.Fields.Clear(); var smh = new ServiceMappingHelper(); smh.MySqlMapDbOutputs(outputDescription, ref dbService, addFields); return(dbService.Recordset); } case enSourceType.SQLiteDatabase: { var broker = new SqliteDatabaseBroker { CommandTimeout = dbService.CommandTimeout }; var outputDescription = broker.TestService(dbService); if (outputDescription?.DataSourceShapes == null || outputDescription.DataSourceShapes.Count == 0) { throw new Exception(ErrorResource.ErrorRetrievingShapeFromServiceOutput); } dbService.Recordset.Fields.Clear(); var smh = new ServiceMappingHelper(); smh.MySqlMapDbOutputs(outputDescription, ref dbService, addFields); return(dbService.Recordset); } case enSourceType.PostgreSQL: { var broker = new PostgreSqlDataBaseBroker { CommandTimeout = dbService.CommandTimeout }; var outputDescription = broker.TestService(dbService); if (outputDescription?.DataSourceShapes == null || outputDescription.DataSourceShapes.Count == 0) { throw new Exception(ErrorResource.ErrorRetrievingShapeFromServiceOutput); } dbService.Recordset.Fields.Clear(); var smh = new ServiceMappingHelper(); smh.MySqlMapDbOutputs(outputDescription, ref dbService, addFields); return(dbService.Recordset); } case enSourceType.Oracle: { var broker = new OracleDatabaseBroker { CommandTimeout = dbService.CommandTimeout }; var outputDescription = broker.TestService(dbService); if (outputDescription?.DataSourceShapes == null || outputDescription.DataSourceShapes.Count == 0) { throw new Exception(ErrorResource.ErrorRetrievingShapeFromServiceOutput); } dbService.Recordset.Fields.Clear(); var smh = new ServiceMappingHelper(); smh.MapDbOutputs(outputDescription, ref dbService, addFields); return(dbService.Recordset); } case enSourceType.ODBC: { var broker = new ODBCDatabaseBroker { CommandTimeout = dbService.CommandTimeout }; var outputDescription = broker.TestService(dbService); if (outputDescription?.DataSourceShapes == null || outputDescription.DataSourceShapes.Count == 0) { throw new Exception(ErrorResource.ErrorRetrievingShapeFromServiceOutput); } dbService.Recordset.Fields.Clear(); var smh = new ServiceMappingHelper(); smh.MapDbOutputs(outputDescription, ref dbService, addFields); dbService.Recordset.Name = @"Unnamed"; return(dbService.Recordset); } default: return(null); } }