internal int FillFromReader(DataSet?dataset, DataTable?datatable, string?srcTable, DataReaderContainer dataReader, int startRecord, int maxRecords, DataColumn?parentChapterColumn, object?parentChapterValue) { int rowsAddedToDataSet = 0; int schemaCount = 0; do { AssertReaderHandleFieldCount(dataReader); if (0 >= dataReader.FieldCount) { continue; // loop to next result } SchemaMapping?mapping = FillMapping(dataset, datatable, srcTable, dataReader, schemaCount, parentChapterColumn, parentChapterValue); schemaCount++; // don't increment if no SchemaTable ( a non-row returning result ) if (null == mapping) { continue; // loop to next result } if (null == mapping.DataValues) { continue; // loop to next result } if (null == mapping.DataTable) { continue; // loop to next result } mapping.DataTable.BeginLoadData(); try { // startRecord and maxRecords only apply to the first resultset if ((1 == schemaCount) && ((0 < startRecord) || (0 < maxRecords))) { rowsAddedToDataSet = FillLoadDataRowChunk(mapping, startRecord, maxRecords); } else { int count = FillLoadDataRow(mapping); if (1 == schemaCount) { // only return LoadDataRow count for first resultset // not secondary or chaptered results rowsAddedToDataSet = count; } } } finally { mapping.DataTable.EndLoadData(); } if (null != datatable) { break; // do not read remaining results in single DataTable case } } while (FillNextResult(dataReader)); return(rowsAddedToDataSet); }
/// <summary> /// Internally sets the DataSet pointer. /// </summary> internal void SetDataSet(DataSet?dataSet) { if (_dataSet != dataSet) { _dataSet = dataSet; } }
private IActivityExecutionResult ExecuteQuery() { var sqlServerClient = _sqlClientFactory.CreateClient(new CreateSqlClientModel(Database, ConnectionString)); Output = sqlServerClient.ExecuteQuery(Query); return(Done()); }
private bool _IgnoreNSforTableLookup; // Everett Behavior : SQL BU DT 370850 internal Merger(DataSet dataSet, bool preserveChanges, MissingSchemaAction missingSchemaAction) { _dataSet = dataSet; _preserveChanges = preserveChanges; // map AddWithKey -> Add _missingSchemaAction = missingSchemaAction == MissingSchemaAction.AddWithKey ? MissingSchemaAction.Add : missingSchemaAction; }
private DataTable?GetTable(string tableName) { DataTable?dt = null; DataSet? ds = _dataViewManager.DataSet; if (ds != null) { dt = ds.Tables[tableName]; } return(dt); }
private SchemaMapping FillMappingInternal(DataSet?dataset, DataTable?datatable, string?srcTable, DataReaderContainer dataReader, int schemaCount, DataColumn?parentChapterColumn, object?parentChapterValue) { bool withKeyInfo = (Data.MissingSchemaAction.AddWithKey == MissingSchemaAction); string?tmp = null; if (null != dataset) { tmp = DataAdapter.GetSourceTableName(srcTable !, schemaCount); } return(new SchemaMapping(this, dataset, datatable, dataReader, withKeyInfo, SchemaType.Mapped, tmp, true, parentChapterColumn, parentChapterValue)); }
private DataTable?GetTable(int index) { DataTable?dt = null; DataSet? ds = _dataViewManager.DataSet; if (ds != null) { dt = ds.Tables[index]; } return(dt); }
internal DataViewManager(DataSet?dataSet, bool locked) { GC.SuppressFinalize(this); _dataSet = dataSet; if (_dataSet != null) { _dataSet.Tables.CollectionChanged += new CollectionChangeEventHandler(TableCollectionChanged); _dataSet.Relations.CollectionChanged += new CollectionChangeEventHandler(RelationCollectionChanged); } _locked = locked; _item = new DataViewManagerListItemTypeDescriptor(this); _dataViewSettingsCollection = new DataViewSettingCollection(this); }
internal object?FillSchemaFromReader(DataSet?dataset, DataTable?datatable, SchemaType schemaType, string?srcTable, IDataReader dataReader) { DataTable[]? dataTables = null; int schemaCount = 0; do { DataReaderContainer readerHandler = DataReaderContainer.Create(dataReader, ReturnProviderSpecificTypes); AssertReaderHandleFieldCount(readerHandler); if (0 >= readerHandler.FieldCount) { continue; } string?tmp = null; if (null != dataset) { tmp = DataAdapter.GetSourceTableName(srcTable !, schemaCount); schemaCount++; // don't increment if no SchemaTable ( a non-row returning result ) } SchemaMapping mapping = new SchemaMapping(this, dataset, datatable, readerHandler, true, schemaType, tmp, false, null, null); if (null != datatable) { // do not read remaining results in single DataTable case return(mapping.DataTable); } else if (null != mapping.DataTable) { if (null == dataTables) { dataTables = new DataTable[1] { mapping.DataTable }; } else { dataTables = DataAdapter.AddDataTableToArray(dataTables, mapping.DataTable); } } } while (dataReader.NextResult()); // FillSchema does not capture errors for FillError event object?value = dataTables; if ((null == value) && (null == datatable)) { value = Array.Empty <DataTable>(); } return(value); // null if datatable had no results }
public DataViewSettingsEnumerator(DataViewManager dvm) { DataSet?ds = dvm.DataSet; if (ds != null) { _dataViewSettings = dvm.DataViewSettings; _tableEnumerator = dvm.DataSet !.Tables.GetEnumerator(); } else { _dataViewSettings = null; _tableEnumerator = Array.Empty <DataTable>().GetEnumerator(); } }
internal void LoadDiffGram(DataSet ds, XmlReader dataTextReader) { XmlReader reader = DataTextReader.CreateReader(dataTextReader); _dataSet = ds; while (reader.LocalName == Keywords.SQL_BEFORE && reader.NamespaceURI == Keywords.DFFNS) { ProcessDiffs(ds, reader); reader.Read(); // now the reader points to the error section } while (reader.LocalName == Keywords.MSD_ERRORS && reader.NamespaceURI == Keywords.DFFNS) { ProcessErrors(ds, reader); Debug.Assert(reader.LocalName == Keywords.MSD_ERRORS && reader.NamespaceURI == Keywords.DFFNS, "something fishy"); reader.Read(); // pass the end of errors tag } }
internal PropertyDescriptorCollection GetPropertiesInternal() { if (_propsCollection == null) { PropertyDescriptor[]? props = null; DataSet?dataSet = _dataViewManager.DataSet; if (dataSet != null) { int tableCount = dataSet.Tables.Count; props = new PropertyDescriptor[tableCount]; for (int i = 0; i < tableCount; i++) { props[i] = new DataTablePropertyDescriptor(dataSet.Tables[i]); } } _propsCollection = new PropertyDescriptorCollection(props); } return(_propsCollection); }
// SDUB: GetListName and GetItemProperties almost the same in DataView and DataViewManager string System.ComponentModel.ITypedList.GetListName(PropertyDescriptor[] listAccessors) { DataSet?dataSet = DataSet; if (dataSet == null) { throw ExceptionBuilder.CanNotUseDataViewManager(); } if (listAccessors == null || listAccessors.Length == 0) { return(dataSet.DataSetName); } else { DataTable?table = dataSet.FindTable(null, listAccessors, 0); if (table != null) { return(table.TableName); } } return(string.Empty); }
PropertyDescriptorCollection System.ComponentModel.ITypedList.GetItemProperties(PropertyDescriptor[] listAccessors) { DataSet?dataSet = DataSet; if (dataSet == null) { throw ExceptionBuilder.CanNotUseDataViewManager(); } if (listAccessors == null || listAccessors.Length == 0) { return(new DataViewManagerListItemTypeDescriptor(this).GetPropertiesInternal()); } else { DataTable?table = dataSet.FindTable(null, listAccessors, 0); if (table != null) { return(table.GetPropertyDescriptorCollection(null)); } } return(new PropertyDescriptorCollection(null)); }
private SchemaMapping?FillMapping(DataSet?dataset, DataTable?datatable, string?srcTable, DataReaderContainer dataReader, int schemaCount, DataColumn?parentChapterColumn, object?parentChapterValue) { SchemaMapping?mapping = null; if (_hasFillErrorHandler) { try { // only try-catch if a FillErrorEventHandler is registered so that // in the default case we get the full callstack from users mapping = FillMappingInternal(dataset, datatable, srcTable, dataReader, schemaCount, parentChapterColumn, parentChapterValue); } catch (Exception e) when(ADP.IsCatchableExceptionType(e)) { ADP.TraceExceptionForCapture(e); OnFillErrorHandler(e, null, null); } } else { mapping = FillMappingInternal(dataset, datatable, srcTable, dataReader, schemaCount, parentChapterColumn, parentChapterValue); } return(mapping); }
internal void SetupMapping(XmlDataDocument xd, DataSet ds) { // If are already mapped, forget about our current mapping and re-do it again. if (IsMapped()) { _tableSchemaMap = new Hashtable(); _columnSchemaMap = new Hashtable(); } _doc = xd; _dataSet = ds; foreach (DataTable t in _dataSet.Tables) { AddTableSchema(t); foreach (DataColumn c in t.Columns) { // don't include auto-generated PK & FK to be part of mapping if (!IsNotMapped(c)) { AddColumnSchema(c); } } } }
/// <summary> /// This will generate a Business Asset Report for a BidPool and Relationship /// </summary> /// <param name="BidPoolId">If this is 0, then we will assume that we are going to use uwRelationshipId</param> /// <param name="uwRelationshipId">If this is zero, then we will assume that we are going top use BidPoolId</param> /// <returns>Name of the file generated</returns> private async Task <string> GenerateAsync(int BidPoolId, int uwRelationshipId) { try { var ModelSheetName = "1"; if (!this.ReloadTemplate(ModelSheetName)) { throw new Exception("Template could not be loaded :("); } // Generate a Sheet for each relationship. If uwRelationshipId <> 0 then only 1 sheet is needed. string sSQL1 = ""; if (uwRelationshipId == 0) { sSQL1 = @"SET ANSI_WARNINGS OFF; SELECT COUNT(*) AS TabCnt FROM (SELECT DISTINCT r.uwRelationshipId FROM UW.tbl_Relationship AS r INNER JOIN UW.tbl_CollateralNRE AS c ON r.uwRelationshipId = c.uwRelationshipId WHERE r.BidPoolId =@p0) AS a;"; } else { sSQL1 = @"SET ANSI_WARNINGS OFF; SELECT 1 AS TabCnt ;"; } var retTabCnt = await MarsDb.QueryAsDataSetAsync(sSQL1, BidPoolId); System.Data.DataTable aResultSet = retTabCnt.Tables[0]; var iTabCnt = 0; foreach (System.Data.DataRow a in aResultSet.Rows) { iTabCnt = (int)a["TabCnt"]; } for (int x = 2; x < iTabCnt + 1; x++) { sheet = workbook.CloneSheet(this.workbook.GetSheetIndex(ModelSheetName)); workbook.SetSheetName(workbook.NumberOfSheets - 1, x.ToString().AsSheetName()); } // Return to sheet "1" this.sheet = this.workbook.GetSheetAt(this.workbook.GetSheetIndex(ModelSheetName)); // Get Dataset for report using ADO; If uwRelationshipId <> 0 use uwRelationshipId else use BidPoolId string sSQL2 = ""; DataSet?retDataSet = null; if (uwRelationshipId == 0) { sSQL2 = @"SET ANSI_WARNINGS OFF; SELECT * FROM [UW].[vw_CollateralNRE] WHERE [BidPoolId]=@p0 ORDER BY uwRelationshipId ASC, uwNRECollateralId ASC;"; retDataSet = await MarsDb.QueryAsDataSetAsync(sSQL2, BidPoolId); } else { sSQL2 = @"SET ANSI_WARNINGS OFF; SELECT * FROM [UW].[vw_CollateralNRE] WHERE [uwRelationshipId]=@p0 ORDER BY uwRelationshipId ASC, uwNRECollateralId ASC;"; retDataSet = await MarsDb.QueryAsDataSetAsync(sSQL2, uwRelationshipId); } System.Data.DataTable firstResultSet = retDataSet.Tables[0]; var iRow = 1; var iRel = 0; var iNRECnt = 1; foreach (System.Data.DataRow row in firstResultSet.Rows) { if (iRow == 1) { iRel = (int)row["uwRelationshipId"]; } else if (iRel != (int)row["uwRelationshipId"]) { iSheet++; this.sheet = this.workbook.GetSheetAt(this.workbook.GetSheetIndex(iSheet.ToString())); iRow = 1; iNRECnt = 1; iRel = (int)row["uwRelationshipId"]; } var formatStr = @"_(* #,##0_);_(* (#,##0);_(* "" - ""??_);_(@_)"; var BACellStyle = new XSSFNPoiStyle() { Border = CellBorder.All, BorderStyle = BorderStyle.Thin, CellFormat = formatStr, VerticalAlignment = VerticalAlignment.Top, HorizontalAlignment = HorizontalAlignment.Left }; sheet.SetCellValue(2, "B", row, "RptHeader"); sheet.CreateRow(iRow + 5); BACellStyle.WrapText = true; sheet.SetCellValue(iRow + 5, "B", row, "NREItemLabel").SetCellStyle(BACellStyle); sheet.SetCellValue(iRow + 5, "C", row, "NREItemComments").SetCellStyle(BACellStyle); BACellStyle.CellFormat = "#,###.00"; sheet.SetCellValue(iRow + 5, "D", row, "NREItemBookVal").SetCellStyle(BACellStyle); BACellStyle.CellFormat = "0.0%"; sheet.SetCellValue(iRow + 5, "E", row, "NREItemCollPcnt").SetCellStyle(BACellStyle); BACellStyle.CellFormat = "#,###.00"; sheet.SetCellValue(iRow + 5, "F", row, "NRESIM").SetCellStyle(BACellStyle); if (iNRECnt == (int)row["CollateralNRECnt"]) { //sheet.CreateRow(18 + iRow); //sheet.SetCellValue(18 + iRow, "C", 0.0).SetCellFormat(formatStr).SetCellFormula(string.Format("SUM(C18:C{0})", (18 + iRow - 2))); sheet.CreateRow(iRow + 7); BACellStyle.IsBold = true; sheet.SetCellValue(iRow + 6, "C", "Totals:").SetCellStyle(BACellStyle); BACellStyle.CellFormat = "#,###.00"; sheet.SetCellValue(iRow + 6, "D", 0.0).SetCellStyle(BACellStyle).SetCellFormula(string.Format("SUM(D6:D{0})", (6 + iRow))); sheet.SetCellValue(iRow + 6, "F", 0.0).SetCellStyle(BACellStyle).SetCellFormula(string.Format("SUM(F6:F{0})", (6 + iRow))); BACellStyle.IsBold = false; } iRow++; iNRECnt++; } SaveToFile(this.GeneratedFileName); return(this.GeneratedFileName); } catch (Exception) { throw; } }
public ParentForeignKeyConstraintEnumerator(DataSet?dataSet, DataTable inTable) : base(dataSet) { _table = inTable; }
public ConstraintEnumerator(DataSet?dataSet) { _tables = dataSet?.Tables.GetEnumerator(); _currentObject = null; }
public DataViewManager(DataSet?dataSet) : this(dataSet, false) { }
public ForeignKeyConstraintEnumerator(DataSet?dataSet) : base(dataSet) { }
private int ReadOldRowData(DataSet?ds, ref DataTable?table, ref int pos, XmlReader row) { // read table information if (ds != null) { table = ds.Tables.GetTable(XmlConvert.DecodeName(row.LocalName), row.NamespaceURI); } else { table = GetTable(XmlConvert.DecodeName(row.LocalName), row.NamespaceURI); } if (table == null) { row.Skip(); // need to skip this element if we dont know about it, before returning -1 return(-1); } int iRowDepth = row.Depth; string?value; value = row.GetAttribute(Keywords.ROWORDER, Keywords.MSDNS); if (!string.IsNullOrEmpty(value)) { pos = (int)Convert.ChangeType(value, typeof(int), null); } int record = table.NewRecord(); foreach (DataColumn col in table.Columns) { col[record] = DBNull.Value; } foreach (DataColumn col in table.Columns) { if ((col.ColumnMapping == MappingType.Element) || (col.ColumnMapping == MappingType.SimpleContent)) { continue; } if (col.ColumnMapping == MappingType.Hidden) { value = row.GetAttribute("hidden" + col.EncodedColumnName, Keywords.MSDNS); } else { value = row.GetAttribute(col.EncodedColumnName, col.Namespace); } if (value == null) { continue; } col[record] = col.ConvertXmlToObject(value); } row.Read(); SkipWhitespaces(row); int currentDepth = row.Depth; if (currentDepth <= iRowDepth) { // the node is empty if (currentDepth == iRowDepth && row.NodeType == XmlNodeType.EndElement) { // read past the EndElement of the current row // note: (currentDepth == iRowDepth) check is needed so we do not skip elements on parent rows. row.Read(); SkipWhitespaces(row); } return(record); } if (table.XmlText != null) { DataColumn col = table.XmlText; col[record] = col.ConvertXmlToObject(row.ReadString()); } else { while (row.Depth > iRowDepth) { string ln = XmlConvert.DecodeName(row.LocalName); string ns = row.NamespaceURI; DataColumn?column = table.Columns[ln, ns]; if (column == null) { while ((row.NodeType != XmlNodeType.EndElement) && (row.LocalName != ln) && (row.NamespaceURI != ns)) { row.Read(); // consume the current node } row.Read(); // now points to the next column //SkipWhitespaces(row); seems no need, just in case if we see other issue , this will be here as hint continue; // add a read here! } if (column.IsCustomType) { // if column's type is object or column type does not implement IXmlSerializable bool isPolymorphism = (column.DataType == typeof(object) || (row.GetAttribute(Keywords.MSD_INSTANCETYPE, Keywords.MSDNS) != null) || (row.GetAttribute(Keywords.TYPE, Keywords.XSINS) != null)); bool skipped = false; if (column.Table !.DataSet != null && column.Table.DataSet._udtIsWrapped) { row.Read(); // if UDT is wrapped, skip the wrapper skipped = true; } XmlRootAttribute?xmlAttrib = null; if (!isPolymorphism && !column.ImplementsIXMLSerializable) { // THIS CHECK MAY BE IS WRONG think more // if does not implement IXLSerializable, need to go with XmlSerializer: pass XmlRootAttribute if (skipped) { xmlAttrib = new XmlRootAttribute(row.LocalName); xmlAttrib.Namespace = row.NamespaceURI; } else { xmlAttrib = new XmlRootAttribute(column.EncodedColumnName); xmlAttrib.Namespace = column.Namespace; } } // for else case xmlAttrib MUST be null column[record] = column.ConvertXmlToObject(row, xmlAttrib); // you need to pass null XmlAttib here if (skipped) { row.Read(); // if Wrapper is skipped, skip its end tag } } else { int iColumnDepth = row.Depth; row.Read(); // SkipWhitespaces(row);seems no need, just in case if we see other issue , this will be here as hint if (row.Depth > iColumnDepth) { //we are inside the column if (row.NodeType == XmlNodeType.Text || row.NodeType == XmlNodeType.Whitespace || row.NodeType == XmlNodeType.SignificantWhitespace) { string text = row.ReadString(); column[record] = column.ConvertXmlToObject(text); row.Read(); // now points to the next column } } else { // <element></element> case if (column.DataType == typeof(string)) { column[record] = string.Empty; } } } } } row.Read(); //now it should point to next row SkipWhitespaces(row); return(record); }
internal int FillFromReader(DataSet?dataset, DataTable?datatable, string?srcTable, DataReaderContainer dataReader, int startRecord, int maxRecords) { return(FillFromReader(dataset, datatable, srcTable, dataReader, startRecord, maxRecords, null, null)); }
protected virtual int Fill(DataTable[] dataTables, IDataReader dataReader, int startRecord, int maxRecords) { long logScopeId = DataCommonEventSource.Log.EnterScope("<comm.DataAdapter.Fill|API> {0}, dataTables[], dataReader, startRecord, maxRecords", ObjectID); try { ADP.CheckArgumentLength(dataTables, nameof(dataTables)); if ((null == dataTables) || (0 == dataTables.Length) || (null == dataTables[0])) { throw ADP.FillRequires("dataTable"); } if (null == dataReader) { throw ADP.FillRequires(nameof(dataReader)); } if ((1 < dataTables.Length) && ((0 != startRecord) || (0 != maxRecords))) { throw ADP.NotSupported(); // FillChildren is not supported with FillPage } int result = 0; bool enforceContraints = false; DataSet?commonDataSet = dataTables[0].DataSet; try { if (null != commonDataSet) { enforceContraints = commonDataSet.EnforceConstraints; commonDataSet.EnforceConstraints = false; } for (int i = 0; i < dataTables.Length; ++i) { Debug.Assert(null != dataTables[i], "null DataTable Fill"); if (dataReader.IsClosed) { break; } DataReaderContainer readerHandler = DataReaderContainer.Create(dataReader, ReturnProviderSpecificTypes); AssertReaderHandleFieldCount(readerHandler); if (readerHandler.FieldCount <= 0) { if (i == 0) { bool lastFillNextResult; do { lastFillNextResult = FillNextResult(readerHandler); }while (lastFillNextResult && readerHandler.FieldCount <= 0); if (!lastFillNextResult) { break; } } else { continue; } } if ((0 < i) && !FillNextResult(readerHandler)) { break; } // user must Close/Dispose of the dataReader // user will have to call NextResult to access remaining results int count = FillFromReader(null, dataTables[i], null, readerHandler, startRecord, maxRecords, null, null); if (0 == i) { result = count; } } } catch (ConstraintException) { enforceContraints = false; throw; } finally { if (enforceContraints) { commonDataSet !.EnforceConstraints = true; } } return(result); } finally { DataCommonEventSource.Log.ExitScope(logScopeId); } }
public ConstraintEnumerator(DataSet?dataSet) { _tables = (dataSet != null) ? dataSet.Tables.GetEnumerator() : null; _currentObject = null; }
/// <summary> /// Sets the constraint's <see cref='System.Data.DataSet'/>. /// </summary> protected internal void SetDataSet(DataSet dataSet) => _dataSet = dataSet;