Пример #1
0
        public DataTable CreateTable(IDataReader reader, LoadOption overwriteChanges)
        {
            var table = new DataTable();

            table.Load(reader, LoadOption.OverwriteChanges);
            return(table);
        }
Пример #2
0
        /// <summary>
        /// Fills the given datatable using values from reader. if a value
        /// for a column is  null, that will be filled with default value.
        /// </summary>
        /// <returns>No. of rows affected </returns>
        internal static int FillFromReader(DataTable table,
                                           IDataReader reader,
                                           int start,
                                           int length,
                                           int [] mapping,
                                           LoadOption loadOption
                                           )
        {
            if (reader.FieldCount == 0)
            {
                return(0);
            }

            for (int i = 0; i < start; i++)
            {
                reader.Read();
            }

            int counter = 0;

            object [] values = new object [mapping.Length];
            while (reader.Read() && (length == 0 || counter < length))
            {
                for (int i = 0; i < mapping.Length; i++)
                {
                    values [i] = mapping [i] < 0 ? null : reader [mapping [i]];
                }
                table.BeginLoadData();
                table.LoadDataRow(values, loadOption);
                table.EndLoadData();
                counter++;
            }
            return(counter);
        }
        /// <summary>
        ///
        /// </summary>
        private void DocumentApplications(LoadOption loadOption)
        {
            this.applications.Clear();

            foreach (BizTalkCore.Application application in this.explorer.Applications)
            {
                if (this.requestedApplications == null ||
                    this.requestedApplications.Count == 0 ||
                    this.Contains(this.requestedApplications, application.Name, true))
                //this.requestedApplications.Contains(application.Name))
                {
                    BizTalkApplication app = new BizTalkApplication(application.Name);
                    app.Assemblies.OnObjectAdded     += new ObjectAddedEvent(Assemblies_OnObjectAdded);
                    app.Maps.OnObjectAdded           += new ObjectAddedEvent(Maps_OnObjectAdded);
                    app.Orchestrations.OnObjectAdded += new ObjectAddedEvent(Orchestrations_OnObjectAdded);
                    app.Pipelines.OnObjectAdded      += new ObjectAddedEvent(Pipelines_OnObjectAdded);
                    app.ReceivePorts.OnObjectAdded   += new ObjectAddedEvent(ReceivePorts_OnObjectAdded);
                    app.Schemas.OnObjectAdded        += new ObjectAddedEvent(Schemas_OnObjectAdded);
                    app.SendPortGroups.OnObjectAdded += new ObjectAddedEvent(SendPortGroups_OnObjectAdded);
                    app.SendPorts.OnObjectAdded      += new ObjectAddedEvent(SendPorts_OnObjectAdded);
                    app.RoleLinks.OnObjectAdded      += new ObjectAddedEvent(RoleLinks_OnObjectAdded);

                    app.ParentInstallation = this;
                    app.Load(this.explorer, application);
                    this.applications.Add(app);
                }
            }

            return;
        }
Пример #4
0
        public DataTable CreateTable(IDataAdapter reader, LoadOption overwriteChanges)
        {
            var ds = new DataSet(); //conn is opened by dataadapter

            reader.Fill(ds);
            return(ds.Tables[0]);
        }
Пример #5
0
        public Loader(Image image, LoadOption load)
        {
            this.Image      = image;
            this.loadOption = load;
            isPrevious      = false;

            if (load.CurrentFile != null)
            {
                try
                {
                    if (File.Exists(loadOption.CurrentFile))
                    {
                        Load(loadOption.CurrentFile);
                    }
                    else
                    {
                        loadOption.CurrentFile = null;
                    }
                }
                catch (Exception e)
                {
                    LogWriter.write(e.ToString());
                    loadOption.CurrentFile = null;
                }
            }
        }
Пример #6
0
        public static DataTable ExecuteDataTableAuto(IDbCommand command, LoadOption loadOption)
        {
            var table = new DataTable();

            ExecuteDataTableAuto(command, table, loadOption);
            return(table);
        }
        /// <summary>
        /// Get a value from the dataset.
        /// </summary>
        /// <param name="ds">The dataset.</param>
        /// <param name="filterExpression">Example: columnName: Size, expectedValue: >= 230, then the value on the filter: columnName >= expectedValue</param>
        /// <param name="columnsOnFilter">Fill this with the column names used at filterExpressions</param>
        /// <returns></returns>
        public static DataSet Where(this DataSet ds, string filterExpression, LoadOption loadOptions, params string[] columnsOnFilter)
        {
            Contract.Requires(ds != null);
            Contract.Requires(columnsOnFilter != null);

            Contract.Ensures(Contract.Result <DataSet>() != null);

            var toReturn = ds.Clone();

            toReturn.Tables.Clear();

            foreach (DataTable table in ds.Tables)
            {
                if (!columnsOnFilter.Any(n => table.Columns.Contains(n)))
                {
                    continue;
                }

                var filteredRows = table.Select(filterExpression);

                if (!filteredRows.Any())
                {
                    continue;
                }

                filteredRows.CopyToDataTable(table, loadOptions);
                toReturn.Tables.Add(table);
            }

            return(toReturn);
        }
Пример #8
0
        /// <summary>
        /// pDtRight parametresi ile gelen veri kaynağındaki veriler, pDtLeft parametresi ile gelen veri kaynağındaki verilere eklenir.
        /// Bu ekleme sırasında, verilen pLoadOption parametresine göre;
        /// pDtLeft veri kaynağında zaten var olan veriler aynen korunur ya da pDtRight veri kaynağındaki veri ile değiştirilir.
        /// Zaten var olan verinin korunması isteniyor ise, pLoadOption parametresi "PreserveChanges" verilmelidir.
        /// Güncellenmesi isteniyor ise pLoadOption parametresi "Upsert" veya "OverwriteChanges" olarak verilmelidir.
        /// </summary>
        /// <param name="pDtLeft">Verilerin ekleneceği ana veri kaynağı</param>
        /// <param name="pDtRight">Verilerin alınacağı ikinci veri kaynağı</param>
        /// <param name="pLoadOption">Veri ekleme (yükleme) seçeneği</param>
        /// <param name="pDtLeftPKColumnName">pDtLeft için tanımlanacak olan PrimaryKey kolon adı.
        /// pDtLeft'de zaten var olan bir verinin pDtRight'deki veri ile güncellenmesi için pDtLeft için bir PrimaryKey tanımlanmalıdır.
        /// PK değeri boş verilirse iki tablo olduğu gibi birleştirilir (UnionAll yapar). </param>
        public static void Union(DataTable pDtLeft, DataTable pDtRight, LoadOption pLoadOption, string pDtLeftPKColumnName, bool pAcceptChanges)
        {
            if (pDtLeft == null || pDtRight == null)
            {
                return;
            }

            lock (pDtLeft)
            {
                if (!String.IsNullOrEmpty(pDtLeftPKColumnName))
                {
                    pDtLeft.SetPrimaryKey(pDtLeftPKColumnName);
                }

                pDtLeft.BeginLoadData();
                foreach (DataRow row in pDtRight.Rows)
                {
                    pDtLeft.LoadDataRow(row.ItemArray, pLoadOption);
                }
                if (pAcceptChanges)
                {
                    pDtLeft.AcceptChanges();
                }
                pDtLeft.EndLoadData();
            }
        }
Пример #9
0
 /// <summary>
 /// Populates the specified DataSet with the results of the query using the specified load option.
 /// Multiple results sets from the query will be populated in the order of the tables in the DataSet.
 /// </summary>
 /// <param name="ds">The DataSet to Populate</param>
 /// <param name="option">Specifies the manner in which imported rows are handled</param>
 /// <param name="cmd">The DbCommand to use to populate the data</param>
 /// <param name="tables">The array of table names that are to be populated by the results of the query</param>
 public void PopulateDataSet(DataSet ds, DbCommand cmd, LoadOption option, params string[] tables)
 {
     this.ExecuteRead(cmd, delegate(DbDataReader reader)
     {
         ds.Load(reader, option, tables);
         return(null);
     });
 }
Пример #10
0
        protected PersistentManager(string filePath, LoadOption loadOption)
        {
            Ensure.IsValidPath(filePath);
            _filePath = filePath;

            if (loadOption == LoadOption.Automatic)
            {
                this.Load();
            }
        }
Пример #11
0
        protected PersistentManager(string filePath, LoadOption loadOption)
        {
            Ensure.IsValidPath(filePath);
            _filePath = filePath;

            if (loadOption == LoadOption.Automatic)
            {
                this.Load();
            }
        }
Пример #12
0
		protected DataAdapter () 
		{
			acceptChangesDuringFill = true;
			continueUpdateOnError = false;
			missingMappingAction = MissingMappingAction.Passthrough;
			missingSchemaAction = MissingSchemaAction.Add;
			tableMappings = new DataTableMappingCollection ();
			acceptChangesDuringUpdate = true;
			fillLoadOption = LoadOption.OverwriteChanges;
			returnProviderSpecificTypes = false;
		}
Пример #13
0
 protected DataAdapter()
 {
     acceptChangesDuringFill     = true;
     continueUpdateOnError       = false;
     missingMappingAction        = MissingMappingAction.Passthrough;
     missingSchemaAction         = MissingSchemaAction.Add;
     tableMappings               = new DataTableMappingCollection();
     acceptChangesDuringUpdate   = true;
     fillLoadOption              = LoadOption.OverwriteChanges;
     returnProviderSpecificTypes = false;
 }
Пример #14
0
        public DataTable CreateTable(IDataAdapter reader, LoadOption overwriteChanges)
        {
            DataSet ds = new DataSet(); //conn is opened by dataadapter

            reader.Fill(ds);
            return(ds.Tables[0]);

//            var table = new DataTable();
//            table.Load(reader, LoadOption.OverwriteChanges);
//            return table;
        }
Пример #15
0
        public DataTable CreateTable(IDataAdapter reader, LoadOption overwriteChanges)
        {
            DataSet ds = new DataSet(); //conn is opened by dataadapter

            reader.Fill(ds);
            if (ds.Tables.Count > 0)
            {
                return(ds.Tables[0]);
            }
            return(new DataTable());
        }
        /// <summary>
        /// LoadConfigInternal
        /// </summary>
        private void LoadConfigInternal(LoadOption loadOption)
        {
            this.InitExplorer(this.server, this.mgmtDatabaseName);

            this.DocumentHosts();
            this.DocumentParties();
            this.DocumentProtocolTypes();
            this.DocumentApplications(loadOption);

            this.FixReferences(this.explorer);
        }
Пример #17
0
 public static void LoadDataTable(DataTable table, LoadOption loadOption,
                                  CommandType commandType, string commandText,
                                  params DbParameter[] parameters)
 {
     using (var command = GetCommand(commandType, commandText, parameters))
     {
         var reader = GetDatabase().ExecuteReader(command);
         using (reader)
         {
             table.Load(reader, loadOption);
         }
     }
 }
Пример #18
0
        public DataTable CreateTable(IDataReader reader, LoadOption overwriteChanges)
        {
            var table = new DataTable();

            table.Load(reader, LoadOption.OverwriteChanges);
            var retrieveStatistics = _sqlConnection.RetrieveStatistics();

            foreach (DictionaryEntry retrieveStatistic in retrieveStatistics)
            {
                Dev2Logger.Log.Debug("Sql Stat:" + retrieveStatistic.Key + ": " + retrieveStatistic.Value);
            }
            return(table);
        }
Пример #19
0
        /// <summary>
        /// Loads the contents returned by the given reader into the DataTable.
        /// </summary>
        /// <param name="table">The table to load the file contents into.</param>
        /// <param name="reader">The reader to use to extract the file schema and data.</param>
        /// <param name="loadOption">Controls how values from the flat file will be applied to existing rows.</param>
        /// <param name="errorHandler">A <see cref="FillErrorEventHandler"/> delegate to call when an error occurs while loading data.</param>
        /// <exception cref="ArgumentNullException">The table is null.</exception>
        /// <exception cref="ArgumentNullException">The reader is null.</exception>
        public static void ReadFlatFile(this DataTable table, IReader reader, LoadOption loadOption = LoadOption.PreserveChanges, FillErrorEventHandler errorHandler = null)
        {
            if (table == null)
            {
                throw new ArgumentNullException(nameof(table));
            }
            if (reader == null)
            {
                throw new ArgumentNullException(nameof(reader));
            }
            var fileReader = new FlatFileDataReader(reader);

            table.Load(fileReader, loadOption, errorHandler);
        }
Пример #20
0
    static internal ArgumentOutOfRangeException InvalidLoadOption(LoadOption value)
    {
#if DEBUG
        switch (value)
        {
        case LoadOption.OverwriteChanges:
        case LoadOption.PreserveChanges:
        case LoadOption.Upsert:
            Debug.Fail("valid LoadOption " + value.ToString());
            break;
        }
#endif
        return(InvalidEnumerationValue(typeof(LoadOption), (int)value));
    }
Пример #21
0
 public static void ExecuteDataTableAuto(IDbCommand command, DataTable table, LoadOption loadOption)
 {
     try
     {
         table.BeginLoadData();
         using (var reader = ExecuteReaderAuto(command))
         {
             table.Load(reader, loadOption);
         }
     }
     finally
     {
         table.EndLoadData();
     }
 }
Пример #22
0
        internal static int FillFromReader(DataTable table,
                                           IDataReader reader,
                                           int start,
                                           int length,
                                           int [] mapping,
                                           LoadOption loadOption,
                                           FillErrorEventHandler errorHandler)
        {
            if (reader.FieldCount == 0)
            {
                return(0);
            }

            for (int i = 0; i < start; i++)
            {
                reader.Read();
            }

            int counter = 0;

            object [] values = new object [mapping.Length];
            while (reader.Read() &&
                   (length == 0 || counter < length))
            {
                for (int i = 0; i < mapping.Length; i++)
                {
                    values [i] = mapping [i] < 0 ? null : reader [mapping [i]];
                }

                table.BeginLoadData();
                try {
                    table.LoadDataRow(values, loadOption);
                } catch (Exception e) {
                    FillErrorEventArgs args = new FillErrorEventArgs(table, values);
                    args.Errors   = e;
                    args.Continue = false;
                    errorHandler(table, args);
                    // if args.Continue is not set to true or if a handler is not set, rethrow the error..
                    if (!args.Continue)
                    {
                        throw e;
                    }
                }
                table.EndLoadData();
                counter++;
            }
            return(counter);
        }
Пример #23
0
        /// <summary>
        /// Populates the specified DataSet with the results of the command text using the specified load option.
        /// Multiple results sets from the command text will be populated in the order of the specified table names.
        /// </summary>
        /// <param name="ds">The DataSet to Populate</param>
        /// <param name="option">Specifies the manner in which imported rows are handled</param>
        /// <param name="text">The command text to use to populate the data</param>
        /// <param name="type">The type of the command text</param>
        /// <param name="tables">The array of table names that are to be populated by the results of the query</param>
        public void PopulateDataSet(DataSet ds, string text, CommandType type, LoadOption option, string[] tables)
        {
            if (null == ds)
            {
                throw new ArgumentNullException("ds");
            }
            if (string.IsNullOrEmpty(text))
            {
                throw new ArgumentNullException("text");
            }

            using (DbCommand cmd = this.CreateCommand(text, type))
            {
                this.PopulateDataSet(ds, cmd, option, tables);
            }
        }
Пример #24
0
        public Loader(string imagePath, Image image, LoadOption load)
        {
            this.Image       = image;
            this.loadOption  = load;
            isPrevious       = false;
            SetTitleCallback = this.DefaltSetTitle;

            if (imagePath != null)
            {
                Load(imagePath);
            }
            else if (loadOption.CurrentFile != null)
            {
                imagePath = loadOption.CurrentFile;
                Load(imagePath);
            }
        }
Пример #25
0
        /// <summary>
        /// Populates the specified DataSet with the results of the query using the specified load option.
        /// Multiple results sets from the query will be populated in the order of the tables specified.
        /// </summary>
        /// <param name="ds">The DataSet to Populate</param>
        /// <param name="option">Specifies the manner in which imported rows are handled</param>
        /// <param name="query">The Query to use to populate the data</param>
        /// <param name="tables">The array of table names that are to be populated by the results of the query</param>
        public void PopulateDataSet(DataSet ds, DBQuery query, LoadOption option, params string[] tables)
        {
            if (null == ds)
            {
                throw new ArgumentNullException("ds");
            }
            if (null == query)
            {
                throw new ArgumentNullException("query");
            }

            this.ExecuteRead(query, delegate(DbDataReader reader)
            {
                ds.Load(reader, option, tables);
                return(null);
            });
        }
Пример #26
0
        public override void Load(IDataReader _IDataReader, LoadOption _LoadOption, FillErrorEventHandler _FillErrorEventHandler, params DataTable[] Tables)
        {
            HZYDataAdapter _HZYDataAdapter = new HZYDataAdapter
            {
                FillLoadOption      = _LoadOption,
                MissingSchemaAction = MissingSchemaAction.AddWithKey
            };

            if (_FillErrorEventHandler != null)
            {
                _HZYDataAdapter.FillError += _FillErrorEventHandler;
            }
            _HZYDataAdapter.FillFromReader(this, _IDataReader, 0, 0);
            if (!_IDataReader.IsClosed && !_IDataReader.NextResult())
            {
                _IDataReader.Close();
            }
        }
Пример #27
0
        protected DataAdapter(DataAdapter from)
        {
            AcceptChangesDuringFill = from.AcceptChangesDuringFill;
            ContinueUpdateOnError   = from.ContinueUpdateOnError;
            MissingMappingAction    = from.MissingMappingAction;
            MissingSchemaAction     = from.MissingSchemaAction;

            if (from.tableMappings != null)
            {
                foreach (ICloneable cloneable in from.TableMappings)
                {
                    TableMappings.Add(cloneable.Clone());
                }
            }
            acceptChangesDuringUpdate   = from.AcceptChangesDuringUpdate;
            fillLoadOption              = from.FillLoadOption;
            returnProviderSpecificTypes = from.ReturnProviderSpecificTypes;
        }
Пример #28
0
            public override void Load(IDataReader reader, LoadOption loadOption, FillErrorEventHandler handler, params DataTable[] tables)
            {
                XLoadAdapter adapter = new XLoadAdapter
                {
                    FillLoadOption      = loadOption,
                    MissingSchemaAction = MissingSchemaAction.AddWithKey
                };

                if (handler != null)
                {
                    adapter.FillError += handler;
                }
                adapter.FillFromReader(this, reader, 0, 0);
                if (!reader.IsClosed && !reader.NextResult())
                {
                    reader.Close();
                }
            }
Пример #29
0
    private static void PerformDemo(LoadOption optionForLoad)
    {
        // Load data into a DataTable, retrieve a DataTableReader containing
        // different data, and call the Load method. Depending on the
        // LoadOption value passed as a parameter, this procedure displays
        // different results in the DataTable.
        Console.WriteLine(" ============================= ");
        Console.WriteLine("table.Load(reader, {0})", optionForLoad);
        Console.WriteLine(" ============================= ");

        DataTable       table  = SetupModifiedRows();
        DataTableReader reader = new DataTableReader(GetChangedCustomers());

        table.RowChanging += new DataRowChangeEventHandler(HandleRowChanging);

        table.Load(reader, optionForLoad);
        Console.WriteLine();
        DisplayRowState(table);
    }
Пример #30
0
 private void CloneFrom(DataAdapter from)
 {
     this._acceptChangesDuringUpdate            = from._acceptChangesDuringUpdate;
     this._acceptChangesDuringUpdateAfterInsert = from._acceptChangesDuringUpdateAfterInsert;
     this._continueUpdateOnError       = from._continueUpdateOnError;
     this._returnProviderSpecificTypes = from._returnProviderSpecificTypes;
     this._acceptChangesDuringFill     = from._acceptChangesDuringFill;
     this._fillLoadOption       = from._fillLoadOption;
     this._missingMappingAction = from._missingMappingAction;
     this._missingSchemaAction  = from._missingSchemaAction;
     if ((from._tableMappings != null) && (0 < from.TableMappings.Count))
     {
         DataTableMappingCollection tableMappings = this.TableMappings;
         foreach (object obj2 in from.TableMappings)
         {
             tableMappings.Add((obj2 is ICloneable) ? ((ICloneable)obj2).Clone() : obj2);
         }
     }
 }
Пример #31
0
        private void CloneFrom(DataAdapter from)
        {
            _acceptChangesDuringUpdate            = from._acceptChangesDuringUpdate;
            _acceptChangesDuringUpdateAfterInsert = from._acceptChangesDuringUpdateAfterInsert;
            _continueUpdateOnError       = from._continueUpdateOnError;
            _returnProviderSpecificTypes = from._returnProviderSpecificTypes; // WebData 101795
            _acceptChangesDuringFill     = from._acceptChangesDuringFill;
            _fillLoadOption       = from._fillLoadOption;
            _missingMappingAction = from._missingMappingAction;
            _missingSchemaAction  = from._missingSchemaAction;

            if ((null != from._tableMappings) && (0 < from.TableMappings.Count))
            {
                DataTableMappingCollection parameters = this.TableMappings;
                foreach (object parameter in from.TableMappings)
                {
                    parameters.Add((parameter is ICloneable) ? ((ICloneable)parameter).Clone() : parameter);
                }
            }
        }
        protected DataAdapter(DataAdapter adapter)
        {
            AcceptChangesDuringFill = adapter.AcceptChangesDuringFill;
            ContinueUpdateOnError   = adapter.ContinueUpdateOnError;
            MissingMappingAction    = adapter.MissingMappingAction;
            MissingSchemaAction     = adapter.MissingSchemaAction;

            if (adapter.tableMappings != null)
            {
                foreach (ICloneable cloneable in adapter.TableMappings)
                {
                    TableMappings.Add(cloneable.Clone());
                }
            }
#if NET_2_0
            acceptChangesDuringUpdate   = adapter.AcceptChangesDuringUpdate;
            fillLoadOption              = adapter.FillLoadOption;
            returnProviderSpecificTypes = adapter.ReturnProviderSpecificTypes;
#endif
        }
Пример #33
0
		public static int FillDataTable (IDataReader dataReader, LoadOption fillLoadOption, DataTable[] dataTables)
		{
			throw new NotImplementedException ();
		}
        internal SchemaMapping(DataAdapter adapter, DataSet dataset, System.Data.DataTable datatable, DataReaderContainer dataReader, bool keyInfo, SchemaType schemaType, string sourceTableName, bool gettingData, DataColumn parentChapterColumn, object parentChapterValue)
        {
            MissingMappingAction missingMappingAction;
            MissingSchemaAction missingSchemaAction;
            this._dataSet = dataset;
            this._dataTable = datatable;
            this._adapter = adapter;
            this._dataReader = dataReader;
            if (keyInfo)
            {
                this._schemaTable = dataReader.GetSchemaTable();
            }
            if (adapter.ShouldSerializeFillLoadOption())
            {
                this._loadOption = adapter.FillLoadOption;
            }
            else if (adapter.AcceptChangesDuringFill)
            {
                this._loadOption = (LoadOption) 4;
            }
            else
            {
                this._loadOption = (LoadOption) 5;
            }
            if (SchemaType.Mapped == schemaType)
            {
                missingMappingAction = this._adapter.MissingMappingAction;
                missingSchemaAction = this._adapter.MissingSchemaAction;
                if (ADP.IsEmpty(sourceTableName))
                {
                    if (this._dataTable != null)
                    {
                        int num2 = this._adapter.IndexOfDataSetTable(this._dataTable.TableName);
                        if (-1 == num2)
                        {
                            switch (missingMappingAction)
                            {
                                case MissingMappingAction.Passthrough:
                                    this._tableMapping = new DataTableMapping(this._dataTable.TableName, this._dataTable.TableName);
                                    goto Label_01DB;

                                case MissingMappingAction.Ignore:
                                    this._tableMapping = null;
                                    goto Label_01DB;

                                case MissingMappingAction.Error:
                                    throw ADP.MissingTableMappingDestination(this._dataTable.TableName);
                            }
                            throw ADP.InvalidMissingMappingAction(missingMappingAction);
                        }
                        this._tableMapping = this._adapter.TableMappings[num2];
                    }
                }
                else
                {
                    this._tableMapping = this._adapter.GetTableMappingBySchemaAction(sourceTableName, sourceTableName, missingMappingAction);
                }
            }
            else
            {
                if (SchemaType.Source != schemaType)
                {
                    throw ADP.InvalidSchemaType(schemaType);
                }
                missingMappingAction = MissingMappingAction.Passthrough;
                missingSchemaAction = MissingSchemaAction.Add;
                if (!ADP.IsEmpty(sourceTableName))
                {
                    this._tableMapping = DataTableMappingCollection.GetTableMappingBySchemaAction(null, sourceTableName, sourceTableName, missingMappingAction);
                }
                else if (this._dataTable != null)
                {
                    int num = this._adapter.IndexOfDataSetTable(this._dataTable.TableName);
                    if (-1 != num)
                    {
                        this._tableMapping = this._adapter.TableMappings[num];
                    }
                    else
                    {
                        this._tableMapping = new DataTableMapping(this._dataTable.TableName, this._dataTable.TableName);
                    }
                }
            }
        Label_01DB:
            if (this._tableMapping != null)
            {
                if (this._dataTable == null)
                {
                    this._dataTable = this._tableMapping.GetDataTableBySchemaAction(this._dataSet, missingSchemaAction);
                }
                if (this._dataTable != null)
                {
                    this._fieldNames = GenerateFieldNames(dataReader);
                    if (this._schemaTable == null)
                    {
                        this._readerDataValues = this.SetupSchemaWithoutKeyInfo(missingMappingAction, missingSchemaAction, gettingData, parentChapterColumn, parentChapterValue);
                        return;
                    }
                    this._readerDataValues = this.SetupSchemaWithKeyInfo(missingMappingAction, missingSchemaAction, gettingData, parentChapterColumn, parentChapterValue);
                }
            }
        }
Пример #35
0
		protected DataAdapter (DataAdapter from)
		{
			AcceptChangesDuringFill = from.AcceptChangesDuringFill;
			ContinueUpdateOnError = from.ContinueUpdateOnError;
			MissingMappingAction = from.MissingMappingAction;
			MissingSchemaAction = from.MissingSchemaAction;

			if (from.tableMappings != null)
				foreach (ICloneable cloneable in from.TableMappings)
					TableMappings.Add (cloneable.Clone ());
#if NET_2_0
			acceptChangesDuringUpdate = from.AcceptChangesDuringUpdate;
			fillLoadOption = from.FillLoadOption;
			returnProviderSpecificTypes = from.ReturnProviderSpecificTypes;
#endif 
		}
Пример #36
0
 public void Load(IDataReader reader, LoadOption loadOption, params string[] tables) {
     Common.ADP.CheckArgumentNull(tables, "tables");
     DataTable[] dataTables = new DataTable[tables.Length];
     for (int i = 0; i < tables.Length; i++) {
         DataTable tempDT = this.Tables[tables[i]];
         if (null == tempDT) {
             tempDT = new DataTable(tables[i]);
             // fxcop: new DataTable should inherit the CaseSensitive, Locale, Namespace from DataSet
             Tables.Add(tempDT);
         }
         dataTables[i] = tempDT;
     }
     Load(reader, loadOption, null, dataTables);
 }
Пример #37
0
 public void Load (IDataReader reader, LoadOption loadOption) {
     Load(reader, loadOption, null);
 }
 public virtual void Load(IDataReader reader, LoadOption loadOption, FillErrorEventHandler errorHandler, params DataTable[] tables)
 {
     IntPtr ptr;
     Bid.ScopeEnter(out ptr, "<ds.DataSet.Load|API> reader, loadOption=%d{ds.LoadOption}", (int) loadOption);
     try
     {
         foreach (DataTable table in tables)
         {
             ADP.CheckArgumentNull(table, "tables");
             if (table.DataSet != this)
             {
                 throw ExceptionBuilder.TableNotInTheDataSet(table.TableName);
             }
         }
         LoadAdapter adapter = new LoadAdapter {
             FillLoadOption = loadOption,
             MissingSchemaAction = MissingSchemaAction.AddWithKey
         };
         if (errorHandler != null)
         {
             adapter.FillError += errorHandler;
         }
         adapter.FillFromReader(tables, reader, 0, 0);
         if (!reader.IsClosed && !reader.NextResult())
         {
             reader.Close();
         }
     }
     finally
     {
         Bid.ScopeLeave(ref ptr);
     }
 }
Пример #39
0
        private DataRow LoadRow(object[] values, LoadOption loadOption, Index searchIndex) {
            int recordNo;
            DataRow dataRow = null;

            if (searchIndex != null) {
                int[] primaryKeyIndex = new int[0];
                if (this.primaryKey != null) { // I do check above for PK, but in case if someone else gives me some index unrelated to PK
                    primaryKeyIndex = new int[this.primaryKey.ColumnsReference.Length];
                    for(int i = 0; i < this.primaryKey.ColumnsReference.Length; i++) {
                        primaryKeyIndex[i] = this.primaryKey.ColumnsReference[i].Ordinal;
                    }
                }

                object[] keys = new object[primaryKeyIndex.Length];
                for(int i = 0; i < primaryKeyIndex.Length; i++) {
                    keys[i] = values[primaryKeyIndex[i]];
                }

                Range result = searchIndex.FindRecords(keys);

                if (!result.IsNull) {
                    int deletedRowUpsertCount = 0;
                    for(int i = result.Min; i <= result.Max; i++) {
                        int resultRecord = searchIndex.GetRecord(i);
                        dataRow = this.recordManager[resultRecord];
                        recordNo = NewRecordFromArray(values);

                        //SQLBU DT 33648
                        // values array is being reused by DataAdapter, do not modify the values array
                        for(int count = 0; count < values.Length; count++) {
                            if (null == values[count]) {
                                columnCollection[count].Copy(resultRecord, recordNo);
                            }
                        }
                        for(int count = values.Length; count < columnCollection.Count ; count++) {
                            columnCollection[count].Copy(resultRecord, recordNo); // if there are missing values
                        }

                        if (loadOption != LoadOption.Upsert || dataRow.RowState != DataRowState.Deleted) {
                            SetDataRowWithLoadOption(dataRow , recordNo, loadOption, true);
                        }
                        else {
                            deletedRowUpsertCount++;
                        }
                    }
                    if (0 == deletedRowUpsertCount) {
                        return dataRow;
                    }
                }
            }

            recordNo = NewRecordFromArray(values);
            dataRow = NewRow(recordNo);
            // fire rowChanging event here
            DataRowAction action;
            DataRowChangeEventArgs drcevent = null;
            switch(loadOption) {
                case LoadOption.OverwriteChanges:
                case LoadOption.PreserveChanges:
                    action = DataRowAction.ChangeCurrentAndOriginal;
                    break;
                case LoadOption.Upsert:
                    action = DataRowAction.Add;
                    break;
                default:
                    throw ExceptionBuilder.ArgumentOutOfRange("LoadOption");
            }

            drcevent = RaiseRowChanging(null, dataRow, action);

            this.InsertRow (dataRow, -1, -1, false);
            switch(loadOption) {
                case LoadOption.OverwriteChanges:
                case LoadOption.PreserveChanges:
                    this.SetOldRecord(dataRow,  recordNo);
                    break;
                case LoadOption.Upsert:
                    break;
                default:
                    throw ExceptionBuilder.ArgumentOutOfRange("LoadOption");
            }
            RaiseRowChanged(drcevent, dataRow, action);

            return dataRow;
        }
Пример #40
0
		public void Load (IDataReader reader, LoadOption loadOption, string[] tables)
		{
			throw new NotImplementedException ();
		}
Пример #41
0
		/// <summary>
		/// Fills the given datatable using values from reader. if a value 
		/// for a column is  null, that will be filled with default value. 
		/// </summary>
		/// <returns>No. of rows affected </returns>
		internal static int FillFromReader (DataTable table,
                                                    IDataReader reader,
                                                    int start,
                                                    int length,
                                                    int [] mapping,
                                                    LoadOption loadOption
                                                    )
		{
			if (reader.FieldCount == 0)
				return 0 ;

			for (int i = 0; i < start; i++)
				reader.Read ();

			int counter = 0;
			object [] values = new object [mapping.Length];
			while (reader.Read () && (length == 0 || counter < length)) {
				for (int i = 0 ; i < mapping.Length; i++)
					values [i] = mapping [i] < 0 ? null : reader [mapping [i]];
				table.BeginLoadData ();
				table.LoadDataRow (values, loadOption);
				table.EndLoadData ();
				counter++;
			}
			return counter;
		}
Пример #42
0
		internal static int FillFromReader (DataTable table,
                                                    IDataReader reader,
                                                    int start,
                                                    int length,
                                                    int [] mapping,
                                                    LoadOption loadOption,
                                                    FillErrorEventHandler errorHandler)
		{
			if (reader.FieldCount == 0)
				return 0 ;

			for (int i = 0; i < start; i++)
				reader.Read ();

			int counter = 0;
			object [] values = new object [mapping.Length];
			while (reader.Read () && (length == 0 || counter < length)) {
				for (int i = 0 ; i < mapping.Length; i++)
					values [i] = mapping [i] < 0 ? null : reader [mapping [i]];
				table.BeginLoadData ();
				try {
					table.LoadDataRow (values, loadOption);
				} catch (Exception e) {
					FillErrorEventArgs args = new FillErrorEventArgs (table, values);
					args.Errors = e;
					args.Continue = false;
					errorHandler (table, args);
					// if args.Continue is not set to true or if a handler is not set, rethrow the error..
					if(!args.Continue)
						throw e;
				}
				table.EndLoadData ();
				counter++;
			}
			return counter;
		}
Пример #43
0
		/// <summary>
		///    This method loads a given value into the existing row affecting versions,
		///    state based on the LoadOption.  The matrix of changes for this method are as
		///    mentioned in the DataTable.Load (IDataReader, LoadOption) method.
		/// </summary>
		internal void Load (object [] values, LoadOption loadOption)
		{
			int temp = -1;

			if (loadOption == LoadOption.OverwriteChanges ||
			    (loadOption == LoadOption.PreserveChanges && RowState == DataRowState.Unchanged)) {
				Table.ChangingDataRow (this, DataRowAction.ChangeCurrentAndOriginal);
				temp = Table.CreateRecord (values);
				Table.DeleteRowFromIndexes(this);
				if (HasVersion (DataRowVersion.Original) && Current != Original)
					Table.RecordCache.DisposeRecord (Original);
				Original = temp;

				if (HasVersion (DataRowVersion.Current))
					Table.RecordCache.DisposeRecord (Current);
				Current = temp;
				Table.AddRowToIndexes(this);
				Table.ChangedDataRow (this, DataRowAction.ChangeCurrentAndOriginal);
				return;
			}

			if (loadOption == LoadOption.PreserveChanges) {
				Table.ChangingDataRow (this, DataRowAction.ChangeOriginal);
				temp = Table.CreateRecord (values);
				if (HasVersion (DataRowVersion.Original) && Current != Original)
					Table.RecordCache.DisposeRecord (Original);
				Original = temp;
				Table.ChangedDataRow (this, DataRowAction.ChangeOriginal);
				return;
			}

			// Upsert
			if (RowState != DataRowState.Deleted) {
				int rindex = HasVersion (DataRowVersion.Proposed) ? Proposed : Current;
				temp = Table.CreateRecord (values);
				if (RowState == DataRowState.Added || Table.CompareRecords (rindex, temp) != 0) {
					Table.ChangingDataRow (this, DataRowAction.Change);
					Table.DeleteRowFromIndexes(this);
					if (HasVersion (DataRowVersion.Proposed)) {
						Table.RecordCache.DisposeRecord (Proposed);
						Proposed = -1;
					}

					if (Original != Current)
						Table.RecordCache.DisposeRecord (Current);
					Current = temp;
					Table.AddRowToIndexes(this);
					Table.ChangedDataRow (this, DataRowAction.Change);
				} else {
					Table.ChangingDataRow (this, DataRowAction.Nothing);
					Table.RecordCache.DisposeRecord (temp);
					Table.ChangedDataRow (this, DataRowAction.Nothing);
				}
			}
		}
Пример #44
0
 public void ResetFillLoadOption() {
     _fillLoadOption = 0;
 }
Пример #45
0
        private void CloneFrom(DataAdapter from) {
            _acceptChangesDuringUpdate = from._acceptChangesDuringUpdate;
            _acceptChangesDuringUpdateAfterInsert = from._acceptChangesDuringUpdateAfterInsert;
            _continueUpdateOnError = from._continueUpdateOnError;
            _returnProviderSpecificTypes = from._returnProviderSpecificTypes; // WebData 101795
            _acceptChangesDuringFill = from._acceptChangesDuringFill;
            _fillLoadOption = from._fillLoadOption;
            _missingMappingAction = from._missingMappingAction;
            _missingSchemaAction = from._missingSchemaAction;

            if ((null != from._tableMappings) && (0 < from.TableMappings.Count)) {
                DataTableMappingCollection parameters = this.TableMappings;
                foreach(object parameter in from.TableMappings) {
                    parameters.Add((parameter is ICloneable) ? ((ICloneable)parameter).Clone() : parameter);
                }
            }
        }
Пример #46
0
 public DataTable CreateTable(IDataReader reader, LoadOption overwriteChanges)
 {
     var table = new DataTable();
     table.Load(reader, LoadOption.OverwriteChanges);
     var retrieveStatistics = _sqlConnection.RetrieveStatistics();
     foreach (DictionaryEntry retrieveStatistic in retrieveStatistics)
     {
         Dev2Logger.Log.Debug("Sql Stat:"+retrieveStatistic.Key+": "+retrieveStatistic.Value);
     }
     return table;
 }
Пример #47
0
		public static int FillDataSet (IDataReader dataReader, LoadOption fillLoadOption, DataSet dataSet)
		{
			throw new NotImplementedException ();
		}
Пример #48
0
        public virtual void Load(IDataReader reader, LoadOption loadOption, FillErrorEventHandler errorHandler)
        {
            long logScopeId = DataCommonEventSource.Log.EnterScope("<ds.DataTable.Load|API> {0}, loadOption={1}", ObjectID, loadOption);
            try
            {
                if (PrimaryKey.Length == 0)
                {
                    DataTableReader dtReader = reader as DataTableReader;
                    if (dtReader != null && dtReader.CurrentDataTable == this)
                    {
                        return; // if not return, it will go to infinite loop
                    }
                }
                Common.LoadAdapter adapter = new Common.LoadAdapter();
                adapter.FillLoadOption = loadOption;
                adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;
                if (null != errorHandler)
                {
                    adapter.FillError += errorHandler;
                }
                adapter.FillFromReader(new DataTable[] { this }, reader, 0, 0);

                if (!reader.IsClosed && !reader.NextResult())
                {
                    reader.Close();
                }
            }
            finally
            {
                DataCommonEventSource.Log.ExitScope(logScopeId);
            }
        }
Пример #49
0
 /// <summary>
 ///     Fills a <see cref="T:System.Data.DataTable"/> with values from a data source using the supplied <see cref="T:System.Data.IDataReader"/>. 
 ///     If the DataTable already contains rows, the incoming data from the data source is merged with the existing rows according to the value of 
 ///     the <paramref name="loadOption"/> parameter.
 /// </summary>
 /// <param name="reader">
 ///     An <see cref="T:System.Data.IDataReader"/> that provides one or more result sets.
 /// </param>
 /// <param name="loadOption">
 ///     A value from the <see cref="T:System.Data.LoadOption"/> enumeration that indicates how rows already in the 
 ///     <see cref="T:System.Data.DataTable"/> are combined with incoming rows that share the same primary key.
 /// </param>
 public void Load(IDataReader reader,
                  LoadOption loadOption)
 {
     this.DataTableInstance.Load(reader, loadOption);
 }
 public void Load(IDataReader reader, LoadOption loadOption, params string[] tables)
 {
     ADP.CheckArgumentNull(tables, "tables");
     DataTable[] tableArray = new DataTable[tables.Length];
     for (int i = 0; i < tables.Length; i++)
     {
         DataTable table = this.Tables[tables[i]];
         if (table == null)
         {
             table = new DataTable(tables[i]);
             this.Tables.Add(table);
         }
         tableArray[i] = table;
     }
     this.Load(reader, loadOption, null, tableArray);
 }
 internal static ArgumentOutOfRangeException InvalidLoadOption(LoadOption value)
 {
     return InvalidEnumerationValue(typeof(LoadOption), (int) value);
 }
Пример #52
0
 /// <summary>
 ///     Fills a <see cref="T:System.Data.DataTable"/> with values from a data source using the supplied <see cref="T:System.Data.IDataReader"/> 
 ///     using an error-handling delegate.
 /// </summary>
 /// <param name="reader">
 ///     A <see cref="T:System.Data.IDataReader"/> that provides a result set.
 /// </param>
 /// <param name="loadOption">
 ///     A value from the <see cref="T:System.Data.LoadOption"/> enumeration that indicates how rows already in the 
 ///     <see cref="T:System.Data.DataTable"/> are combined with incoming rows that share the same primary key.
 /// </param>
 /// <param name="errorHandler">
 ///     A <see cref="T:System.Data.FillErrorEventHandler"/> delegate to call when an error occurs while loading data.
 /// </param>
 public void Load(IDataReader reader,
                  LoadOption loadOption,
                  FillErrorEventHandler errorHandler)
 {
     this.DataTableInstance.Load(reader, loadOption, errorHandler);
 }
Пример #53
0
        internal SchemaMapping(DataAdapter adapter, DataSet dataset, DataTable datatable, DataReaderContainer dataReader, bool keyInfo,
                                    SchemaType schemaType, string sourceTableName, bool gettingData,
                                    DataColumn parentChapterColumn, object parentChapterValue) {
            Debug.Assert(null != adapter, "adapter");
            Debug.Assert(null != dataReader, "dataReader");
            Debug.Assert(0 < dataReader.FieldCount, "FieldCount");
            Debug.Assert(null != dataset || null != datatable, "SchemaMapping - null dataSet");
            Debug.Assert(SchemaType.Mapped == schemaType || SchemaType.Source == schemaType, "SetupSchema - invalid schemaType");

            _dataSet = dataset;     // setting DataSet implies chapters are supported
            _dataTable = datatable; // setting only DataTable, not DataSet implies chapters are not supported
            _adapter = adapter;
            _dataReader = dataReader;

            if (keyInfo) {
                _schemaTable = dataReader.GetSchemaTable();
            }

            if (adapter.ShouldSerializeFillLoadOption()) {
                _loadOption = adapter.FillLoadOption;
            }
            else if (adapter.AcceptChangesDuringFill) {
                _loadOption = (LoadOption)4; // true
            }
            else {
                _loadOption = (LoadOption)5; //false
            }

            MissingMappingAction mappingAction;
            MissingSchemaAction schemaAction;
            if (SchemaType.Mapped == schemaType) {
                mappingAction = _adapter.MissingMappingAction;
                schemaAction = _adapter.MissingSchemaAction;
                if (!ADP.IsEmpty(sourceTableName)) { // MDAC 66034
                    _tableMapping = _adapter.GetTableMappingBySchemaAction(sourceTableName, sourceTableName, mappingAction);
                }
                else if (null != _dataTable) {
                    int index = _adapter.IndexOfDataSetTable(_dataTable.TableName);
                    if (-1 != index) {
                        _tableMapping = _adapter.TableMappings[index];
                    }
                    else {
                        switch (mappingAction) {
                        case MissingMappingAction.Passthrough:
                            _tableMapping = new DataTableMapping(_dataTable.TableName, _dataTable.TableName);
                            break;
                        case MissingMappingAction.Ignore:
                            _tableMapping = null;
                            break;
                        case MissingMappingAction.Error:
                            throw ADP.MissingTableMappingDestination(_dataTable.TableName);
                        default:
                            throw ADP.InvalidMissingMappingAction(mappingAction);
                        }
                    }
                }
            }
            else if (SchemaType.Source == schemaType) {
                mappingAction = System.Data.MissingMappingAction.Passthrough;
                schemaAction = Data.MissingSchemaAction.Add;
                if (!ADP.IsEmpty(sourceTableName)) { // MDAC 66034
                    _tableMapping = DataTableMappingCollection.GetTableMappingBySchemaAction(null, sourceTableName, sourceTableName, mappingAction);
                }
                else if (null != _dataTable) {
                    int index = _adapter.IndexOfDataSetTable(_dataTable.TableName); // MDAC 66034
                    if (-1 != index) {
                        _tableMapping = _adapter.TableMappings[index];
                    }
                    else {
                        _tableMapping = new DataTableMapping(_dataTable.TableName, _dataTable.TableName);
                    }
                }
            }
            else {
                throw ADP.InvalidSchemaType(schemaType);
            }

            if (null != _tableMapping) {
                if (null == _dataTable) {
                    _dataTable = _tableMapping.GetDataTableBySchemaAction(_dataSet, schemaAction);
                }
                if (null != _dataTable) {
                    _fieldNames = GenerateFieldNames(dataReader);

                    if (null == _schemaTable) {
                        _readerDataValues = SetupSchemaWithoutKeyInfo(mappingAction, schemaAction, gettingData, parentChapterColumn, parentChapterValue);
                    }
                    else {
                        _readerDataValues = SetupSchemaWithKeyInfo(mappingAction, schemaAction, gettingData, parentChapterColumn, parentChapterValue);
                    }
                }
                // else (null == _dataTable) which means ignore (mapped to nothing)
            }
        }
Пример #54
0
 /// <summary>
 ///     Finds and updates a specific row. If no matching row is found, a new row is created using the given values.
 /// </summary>
 /// <returns>
 ///     The new <see cref="T:System.Data.DataRow"/>.
 /// </returns>
 /// <param name="values">
 ///     An array of values used to create the new row.
 /// </param>
 /// <param name="loadOption">
 ///     Used to determine how the array values are applied to the corresponding values in an existing row.
 /// </param>
 public DataRow LoadDataRow(object[] values,
                            LoadOption loadOption)
 {
     return this.DataTableInstance.LoadDataRow(values, loadOption);
 }
Пример #55
0
        /// <devdoc>
        ///    <para>Finds and updates a specific row. If no matching
        ///       row is found, a new row is created using the given values.</para>
        /// </devdoc>
        public DataRow LoadDataRow(object[] values, LoadOption loadOption) {
            IntPtr hscp;
            Bid.ScopeEnter(out hscp, "<ds.DataTable.LoadDataRow|API> %d#, loadOption=%d{ds.LoadOption}\n", ObjectID,  (int)loadOption);
            try {
                Index indextoUse = null;
                if (this.primaryKey != null) {
                    if (loadOption == LoadOption.Upsert) { // CurrentVersion, and Deleted
                        if (loadIndexwithCurrentDeleted == null) {
                            loadIndexwithCurrentDeleted = this.primaryKey.Key.GetSortIndex(DataViewRowState.CurrentRows |DataViewRowState.Deleted);
                            Debug.Assert(loadIndexwithCurrentDeleted != null, "loadIndexwithCurrentDeleted should not be null" );
                            if (loadIndexwithCurrentDeleted != null) {
                                loadIndexwithCurrentDeleted.AddRef();
                            }
                        }
                        indextoUse = loadIndexwithCurrentDeleted;
                    }
                    else {// CurrentVersion, and Deleted : OverwriteRow, PreserveCurrentValues
                        if (loadIndexwithOriginalAdded == null) {
                            loadIndexwithOriginalAdded  = this.primaryKey.Key.GetSortIndex(DataViewRowState.OriginalRows |DataViewRowState.Added);
                            Debug.Assert(loadIndexwithOriginalAdded != null, "loadIndexwithOriginalAdded should not be null");
                            if (loadIndexwithOriginalAdded != null) {
                                loadIndexwithOriginalAdded.AddRef();
                            }
                        }
                        indextoUse = loadIndexwithOriginalAdded;
                    }
                    // not expecting LiveIndexes to clear the index we use between calls to LoadDataRow
                    Debug.Assert(2 <= indextoUse.RefCount, "bad indextoUse.RefCount");
                }
                if(inDataLoad && !AreIndexEventsSuspended) { // we do not want to fire any listchanged in new Load/Fill
                    SuspendIndexEvents();// so suspend events here(not suspended == table already has some rows initially)
                }

                DataRow dataRow = LoadRow(values, loadOption, indextoUse);// if indextoUse == null, it means we dont have PK,
                                                                          // so LoadRow will take care of just adding the row to end

                return dataRow;
            }
            finally {
                Bid.ScopeLeave(ref hscp);
            }
        }
Пример #56
0
                internal void Load (object [] values, LoadOption loadOption)
                {
                        Index index = null;
                        DataRowAction action = DataRowAction.Change;

                        int temp = -1;

                        if (loadOption == LoadOption.OverwriteChanges 
                            || (loadOption == LoadOption.PreserveChanges
                                && RowState == DataRowState.Unchanged)) {
				temp = Table.CreateRecord (values);
                                if (HasVersion (DataRowVersion.Original) && Current != Original)
                                        Table.RecordCache.DisposeRecord (Original);
                                Original = temp;
                                // update the pk index
                                index = Table.GetIndex(Table.PrimaryKey,null,DataViewRowState.None,null,false);
                                if (index != null)
                                        index.Update (this, temp);

                                if (HasVersion (DataRowVersion.Current))
                                        Table.RecordCache.DisposeRecord (Current);
                                Current = temp;
                                action = DataRowAction.ChangeCurrentAndOriginal;
                                return;
                        }

                        if (loadOption == LoadOption.PreserveChanges) {
				if (RowState == DataRowState.Deleted)
					return;
				temp = Table.CreateRecord (values);
				if (HasVersion (DataRowVersion.Original) && Current != Original)
					Table.RecordCache.DisposeRecord (Original);
				Original = temp;
				action   = DataRowAction.ChangeOriginal;
                                return;
                        }
                                
                        // Upsert
                        if (RowState != DataRowState.Deleted) {
                                int rindex = HasVersion (DataRowVersion.Proposed) ? Proposed : Current;
				temp = Table.CreateRecord (values);
				if (Table.CompareRecords (rindex, temp) != 0) {
                                        if (HasVersion (DataRowVersion.Proposed)) {
                                                Table.RecordCache.DisposeRecord (Proposed);
                                                Proposed = -1;
                                        }
                                        
                                        // update the pk index
                                        index = Table.GetIndex(Table.PrimaryKey,null,DataViewRowState.None,null,false);
                                        if (index != null)
                                                index.Update (this, temp);

                                        if (Original != Current)
                                                Table.RecordCache.DisposeRecord (Current);
                                        Current = temp;
                                } else
					Table.RecordCache.DisposeRecord (temp);
                        }

                }
Пример #57
0
        public virtual void Load (IDataReader reader, LoadOption loadOption, FillErrorEventHandler errorHandler){
            IntPtr hscp;
            Bid.ScopeEnter(out hscp, "<ds.DataTable.Load|API> %d#, loadOption=%d{ds.LoadOption}\n", ObjectID, (int)loadOption);
            try {
                if (this.PrimaryKey.Length == 0) {
                    DataTableReader dtReader = reader as DataTableReader;
                    if (dtReader != null && dtReader.CurrentDataTable == this)
                        return; // if not return, it will go to infinite loop
                }
                Common.LoadAdapter adapter = new Common.LoadAdapter();
                adapter.FillLoadOption = loadOption;
                adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;
                if (null != errorHandler) {
                    adapter.FillError += errorHandler;
                }
                adapter.FillFromReader(new DataTable[] { this }, reader, 0, 0);

                if (!reader.IsClosed && !reader.NextResult()) { // 
                    reader.Close();
                }
            }
            finally {
                Bid.ScopeLeave(ref hscp);
            }
        }
Пример #58
0
        public virtual void Load(IDataReader reader, LoadOption loadOption, FillErrorEventHandler errorHandler, params DataTable[] tables) {
            IntPtr hscp;
            Bid.ScopeEnter(out hscp, "<ds.DataSet.Load|API> reader, loadOption=%d{ds.LoadOption}", (int)loadOption);
            try {
                foreach (DataTable dt in tables) {
                    Common.ADP.CheckArgumentNull(dt, "tables");
                    if (dt.DataSet != this) {
                        throw ExceptionBuilder.TableNotInTheDataSet(dt.TableName);
                    }
                }
                Common.LoadAdapter adapter = new Common.LoadAdapter();
                adapter.FillLoadOption = loadOption;
                adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;
                if (null != errorHandler) {
                    adapter.FillError += errorHandler;
                }
                adapter.FillFromReader(tables, reader, 0, 0);

                if (!reader.IsClosed && !reader.NextResult()) { // 
                    reader.Close();
                }
            }
            finally {
                Bid.ScopeLeave(ref hscp);
            }
        }
Пример #59
0
        private void SetDataRowWithLoadOption (DataRow dataRow, int recordNo, LoadOption loadOption, bool checkReadOnly) {
            bool hasError = false;
            if (checkReadOnly) {
                foreach(DataColumn dc in this.Columns) {
                    if (dc.ReadOnly && !dc.Computed) {
                        switch(loadOption) {
                            case LoadOption.OverwriteChanges:
                                if ((dataRow[dc, DataRowVersion.Current] != dc[recordNo]) ||(dataRow[dc, DataRowVersion.Original] != dc[recordNo]))
                                    hasError = true;
                                break;
                            case LoadOption.Upsert:
                                if (dataRow[dc, DataRowVersion.Current] != dc[recordNo])
                                    hasError = true;
                                break;
                            case LoadOption.PreserveChanges:
                                if (dataRow[dc, DataRowVersion.Original] != dc[recordNo])
                                    hasError = true;
                                break;
                        }
                    }
                }
            } // No Event should be fired  in SenNewRecord and SetOldRecord
            // fire rowChanging event here

            DataRowChangeEventArgs drcevent = null;
            DataRowAction action = DataRowAction.Nothing;
            int cacheTempRecord = dataRow.tempRecord;
            dataRow.tempRecord = recordNo;

            switch(loadOption) {
                case LoadOption.OverwriteChanges:
                    action = DataRowAction.ChangeCurrentAndOriginal;
                    break;
                case LoadOption.Upsert:
                    switch(dataRow.RowState) {
                        case DataRowState.Unchanged:
                            // let see if the incomming value has the same values as existing row, so compare records
                            foreach(DataColumn dc in dataRow.Table.Columns) {
                                if (0 != dc.Compare(dataRow.newRecord, recordNo)) {
                                    action = DataRowAction.Change;
                                    break;
                                }
                            }
                            break;
                        case DataRowState.Deleted:
                            Debug.Assert(false, "LoadOption.Upsert with deleted row, should not be here");
                            break;
                        default :
                            action = DataRowAction.Change;
                            break;
                    }
                    break;
                case LoadOption.PreserveChanges:
                    switch(dataRow.RowState) {
                        case DataRowState.Unchanged:
                            action = DataRowAction.ChangeCurrentAndOriginal;
                            break;
                        default:
                            action = DataRowAction.ChangeOriginal;
                            break;
                    }
                    break;
                default:
                    throw ExceptionBuilder.ArgumentOutOfRange("LoadOption");
            }

            try {
                drcevent = RaiseRowChanging(null, dataRow, action);
                if (action == DataRowAction.Nothing) { // RaiseRowChanging does not fire for DataRowAction.Nothing
                    dataRow.inChangingEvent = true;
                    try {
                        drcevent = OnRowChanging(drcevent, dataRow, action);
                    }
                    finally {
                        dataRow.inChangingEvent = false;
                    }
                }
            }
            finally {
                Debug.Assert(dataRow.tempRecord == recordNo, "tempRecord has been changed in event handler");
                if (DataRowState.Detached == dataRow.RowState) {
                    // 'row.Table.Remove(row);'
                    if (-1 != cacheTempRecord) {
                        FreeRecord(ref cacheTempRecord);
                    }
                }
                else {
                    if (dataRow.tempRecord != recordNo) {
                        // 'row.EndEdit(); row.BeginEdit(); '
                        if (-1 != cacheTempRecord) {
                            FreeRecord(ref cacheTempRecord);
                        }
                        if (-1 != recordNo) {
                            FreeRecord(ref recordNo);
                        }
                        recordNo = dataRow.tempRecord;
                    }
                    else {
                        dataRow.tempRecord = cacheTempRecord;
                    }
                }
            }
            if (dataRow.tempRecord != -1) {
                dataRow.CancelEdit();
            }

            switch(loadOption) {
                case LoadOption.OverwriteChanges:
                     this.SetNewRecord(dataRow,  recordNo, DataRowAction.Change, false, false);
                     this.SetOldRecord(dataRow,  recordNo);
                     break;
                case LoadOption.Upsert:
                     if (dataRow.RowState == DataRowState.Unchanged) {
                         this.SetNewRecord(dataRow,  recordNo, DataRowAction.Change, false, false);
                         if (!dataRow.HasChanges()) {
                             this.SetOldRecord(dataRow, recordNo);
                         }
                     }
                     else {
                         if (dataRow.RowState == DataRowState.Deleted)
                             dataRow.RejectChanges();
                         this.SetNewRecord(dataRow,  recordNo, DataRowAction.Change, false, false);
                     }
                     break;
                case LoadOption.PreserveChanges:
                     if (dataRow.RowState == DataRowState.Unchanged) {
                         // SQLBU 500706: DataTable internal index is corrupted: '8'
                         // if ListChanged event deletes dataRow
                         this.SetOldRecord(dataRow,  recordNo); // do not fire event
                         this.SetNewRecord(dataRow, recordNo, DataRowAction.Change, false, false);
                     }
                     else { // if modified/ added / deleted we want this operation to fire event (just for LoadOption.PreserveCurrentValues)
                        this.SetOldRecord(dataRow,  recordNo);
                     }
                     break;
                default:
                    throw ExceptionBuilder.ArgumentOutOfRange("LoadOption");
            }

            if (hasError) {
                string error = Res.GetString(Res.Load_ReadOnlyDataModified);
                if (dataRow.RowError.Length == 0) { // WebData 112272, append the row error
                    dataRow.RowError = error;
                }
                else {
                    dataRow.RowError += " ]:[ " + error ;
                }

                foreach(DataColumn dc in this.Columns) {
                    if (dc.ReadOnly && !dc.Computed)
                        dataRow.SetColumnError(dc, error);
                }
            }

            drcevent = RaiseRowChanged(drcevent, dataRow, action);
            if (action == DataRowAction.Nothing) { // RaiseRowChanged does not fire for DataRowAction.Nothing
                dataRow.inChangingEvent = true;
                try {
                    OnRowChanged(drcevent, dataRow, action);
                }
                finally {
                    dataRow.inChangingEvent = false;
                }
            }

        }
 public void Load(IDataReader reader, LoadOption loadOption, params DataTable[] tables)
 {
     this.Load(reader, loadOption, null, tables);
 }