예제 #1
0
        /// <summary>
        /// Invoked when disposing or finalizing this instance.
        /// </summary>
        /// <param name="disposing">True if the object is being disposed, false otherwise.</param>
        protected virtual void OnDispose(bool disposing)
        {
            if (disposing)
            {
                if (_DbCommand != null)
                {
                    try { _DbCommand.Cancel(); if (disposing)
                          {
                              _DbCommand.Dispose();
                          }
                    }
                    catch { }
                }
                if (_DataReader != null)
                {
                    try { if (!_DataReader.IsClosed)
                          {
                              _DataReader.Close();
                          }
                          if (disposing)
                          {
                              _DataReader.Dispose();
                          }
                    }
                    catch { }
                }
                if (Link != null)
                {
                    try { if (Link.IsOpen && _LinkOpenedBySurrogate)
                          {
                              Link.Close();
                          }
                    }
                    catch { }
                }
            }

            _DbCommand             = null;
            _DataReader            = null;
            _LinkOpenedBySurrogate = false;

            _Command = null;
            _Schema  = null;

            _IsDisposed = true;
        }
예제 #2
0
		/// <summary>
		/// Invoked when disposing or finalizing this instance.
		/// </summary>
		/// <param name="disposing">True if the object is being disposed, false otherwise.</param>
		protected virtual void OnDispose(bool disposing)
		{
			if (disposing)
			{
				if (_DbCommand != null)
				{
					try { _DbCommand.Cancel(); if (disposing) _DbCommand.Dispose(); }
					catch { }
				}
				if (_DataReader != null)
				{
					try { if (!_DataReader.IsClosed) _DataReader.Close(); if (disposing) _DataReader.Dispose(); }
					catch { }
				}
				if (Link != null)
				{
					try { if (Link.IsOpen && _LinkOpenedBySurrogate) Link.Close(); }
					catch { }
				}
			}

			_DbCommand = null;
			_DataReader = null;
			_LinkOpenedBySurrogate = false;

			_Command = null;
			_Schema = null;

			_IsDisposed = true;
		}
예제 #3
0
        /// <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);
        }
예제 #4
0
		/// <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;
		}