/// <summary> /// Invokes to start the execution of the enumerable command and to return the schema /// that describes the structure of the records to be produced by that execution. /// </summary> internal Core.ISchema OnReaderStart() { _Schema = null; Invoke(iterable: true, action: () => { _DataReader = _DbCommand.ExecuteReader(CommandBehavior.KeyInfo); var table = _DataReader.GetSchemaTable(); if (table == null) { var s = "Cannot obtain schema for command '{0}'.".FormatWith(_Command); if (!_DbCommand.CommandText.ToUpper().Contains("OUTPUT")) { s += " Have you used an 'OUTPUT' clause?"; } Dispose(); throw new InvalidOperationException(s); } var name = _Command is Core.ITableNameProvider ? ((Core.ITableNameProvider)_Command).TableName : null; _Schema = new Core.Concrete.Schema(Link.Engine.CaseSensitiveNames); for (int i = 0; i < table.Rows.Count; i++) { DataRow row = table.Rows[i]; string meta = null; object value = null; // Intercepting hidden columns, that have cause random failures... bool hidden = false; if (table.Columns.Contains("IsHidden")) { value = row[table.Columns["IsHidden"]]; if (!(value is DBNull)) { hidden = (bool)value; } } if (hidden) { continue; } var entry = new Core.Concrete.SchemaEntry(); for (int j = 0; j < table.Columns.Count; j++) { meta = table.Columns[j].ColumnName; value = row[j] is DBNull ? null : row[j]; entry.Metadata[meta] = value; } if (entry.TableName == null && name != null) { entry.TableName = name; } _Schema.Add(entry); } table.Dispose(); table = null; if (_Schema.Count == 0) { throw new InvalidOperationException( "Schema is empty after executing command '{0}'".FormatWith(_Command)); } if (_Command is Core.IElementAliasCollectionProvider) { _Schema.Aliases.AddRange( ((Core.IElementAliasCollectionProvider)_Command).Aliases, cloneNotOrphans: true); } }); return(_Schema); }
/// <summary> /// Invokes to start the execution of the enumerable command and to return the schema /// that describes the structure of the records to be produced by that execution. /// </summary> internal Core.ISchema OnReaderStart() { _Schema = null; Invoke(iterable: true, action: () => { _DataReader = _DbCommand.ExecuteReader(CommandBehavior.KeyInfo); var table = _DataReader.GetSchemaTable(); if (table == null) { var s = "Cannot obtain schema for command '{0}'.".FormatWith(_Command); if (!_DbCommand.CommandText.ToUpper().Contains("OUTPUT")) s += " Have you used an 'OUTPUT' clause?"; Dispose(); throw new InvalidOperationException(s); } var name = _Command is Core.ITableNameProvider ? ((Core.ITableNameProvider)_Command).TableName : null; _Schema = new Core.Concrete.Schema(Link.Engine.CaseSensitiveNames); for (int i = 0; i < table.Rows.Count; i++) { DataRow row = table.Rows[i]; string meta = null; object value = null; // Intercepting hidden columns, that have cause random failures... bool hidden = false; if (table.Columns.Contains("IsHidden")) { value = row[table.Columns["IsHidden"]]; if (!(value is DBNull)) hidden = (bool)value; } if (hidden) continue; var entry = new Core.Concrete.SchemaEntry(); for (int j = 0; j < table.Columns.Count; j++) { meta = table.Columns[j].ColumnName; value = row[j] is DBNull ? null : row[j]; entry.Metadata[meta] = value; } if (entry.TableName == null && name != null) entry.TableName = name; _Schema.Add(entry); } table.Dispose(); table = null; if (_Schema.Count == 0) throw new InvalidOperationException( "Schema is empty after executing command '{0}'".FormatWith(_Command)); if (_Command is Core.IElementAliasCollectionProvider) _Schema.Aliases.AddRange( ((Core.IElementAliasCollectionProvider)_Command).Aliases, cloneNotOrphans: true); }); return _Schema; }