コード例 #1
0
        /// <summary>
        /// Copy table
        /// </summary>
        /// <param name="toTable">Destination table</param>
        protected void Copy(TableBase toTable)
        {
            using (this.Connection.OpenWrapper())
            {
                CopyTableCommand copyTableCommand = new CopyTableCommand(
                    this.Connection,
                    this.TableDefinition,
                    toTable.TableDefinition
                    );

                copyTableCommand.SetFieldDefinitions(
                    QueryDefinition.GetMinimumDefinitions(
                        (definition, fieldDefinition) => definition.CanFill(fieldDefinition),
                        this.TableDefinition,
                        toTable.TableDefinition
                        )
                    );

                copyTableCommand.Execute(100);
            }
        }
コード例 #2
0
        /// <summary>
        /// Upgrade table accroding definition
        /// </summary>
        /// <param name="tableDefinition">New table definition</param>
        /// <returns></returns>
        public void UpdateScheme()
        {
            int  intColumnIndex = 0;
            bool forceUpgrade   = false;

            // var forceUpgrade = ServiceInfoTable.ReadDbVesion(this.Connection).MinorChangedOver(DatabaseVersion.Current);
            // Log.DebugFormat("forceUpgrade:'{0}'", forceUpgrade);

            lock (this._globalLock)
            {
                using (this.Connection.OpenWrapper())
                {
                    // Log.DebugFormat(
                    //    @"this.TableDefinition.Name:'{0}'",
                    //    this.TableDefinition.Name
                    // );

                    Table existingTable = GetTable(
                        this.Connection,
                        this.TableDefinition.Name
                        );

                    // Log.DebugFormat(
                    //    @"Connection:'{0}';ExistingTable:'{1}'",
                    //    this.Connection.DataSource,
                    //    existingTable.TableDefinition.Name
                    // );

                    if (existingTable == null)
                    {
                        this.CreateTable();

                        return;
                    }

                    IEnumerable <FieldDefinition> fields = QueryDefinition.GetMinimumDefinitions(
                        (definition, fieldDefinition) => definition.Equals(fieldDefinition),
                        existingTable.TableDefinition,
                        this.TableDefinition
                        );

                    // Log.DebugFormat(
                    //    @"this.TableDefinition.Fields.Count:'{0}';Existing fields.Count:'{1}'",
                    //    this.TableDefinition.Fields.Count,
                    //    fields.Count()
                    // );

                    intColumnIndex = 0;

                    foreach (FieldDefinition fieldInTableDefinition in this.TableDefinition.Fields.Values)
                    {
                        // Log.DebugFormat(
                        //    @"index:{0};Column:'{1}'",
                        //    intColumnIndex,
                        //    fieldInTableDefinition.Name
                        // );

                        intColumnIndex++;
                    }

                    intColumnIndex = 0;

                    foreach (FieldDefinition fieldInExistingTable in fields)
                    {
                        // Log.DebugFormat(
                        //    @"index:{0};Column:'{1}'",
                        //    intColumnIndex,
                        //    fieldInExistingTable.Name
                        // );

                        intColumnIndex++;
                    }

                    if (forceUpgrade || fields.Count() < this.TableDefinition.Fields.Count)
                    {
                        string tmpName     = existingTable.TableDefinition.Name + "_tmp";
                        Table  tmpExisting = GetTable(this.Connection, tmpName);

                        if (tmpExisting != null)
                        {
                            tmpExisting.Drop();
                        }

                        existingTable.Rename(tmpName);

                        this.CreateTable();

                        existingTable.Copy(this);

                        existingTable.Drop();
                    }
                }
            }
        }