Beispiel #1
0
        /// <summary>
        /// Returns a prepared list of fields
        /// </summary>
        /// <param name="fields">List of raw fields</param>
        /// <returns>Prepared list of fields</returns>
        private List <DtoFullField> FieldsCollectionPreparation(IEnumerable <SyBaseFieldsModel> fields)
        {
            List <DtoFullField> tempCollection = new List <DtoFullField>();

            foreach (var item in fields)
            {
                DtoFullField field = new DtoFullField()
                {
                    TypeName   = GetType(item.base_type_str),
                    IsNullable = item.nulls,
                    FieldName  = item.column_name,
                    Size       = GetSize(item.base_type_str)
                };

                if (!string.IsNullOrEmpty(item.@default))
                {
                    field.ConstraintType = "DEFAULT";
                    field.ConstraintKeys = item.@default;
                }

                tempCollection.Add(field);
            }

            return(tempCollection);
        }
 /// <summary>
 /// Comparing fields with the return of the comparison result
 /// </summary>
 /// <param name="lsField">Left side field</param>
 /// <param name="rsField">Right side field</param>
 /// <returns>Comparison result</returns>
 private bool FieldsEquals(DtoFullField lsField, DtoFullField rsField)
 {
     return(lsField.FieldName != rsField.FieldName      ? false :
            lsField.TypeName != rsField.TypeName       ? false :
            lsField.Size != rsField.Size           ? false :
            lsField.IsNullable != rsField.IsNullable     ? false :
            lsField.ConstraintType != rsField.ConstraintType ? false :
            lsField.ConstraintName != rsField.ConstraintName ? false :
            lsField.ConstraintKeys != rsField.ConstraintKeys ? false :
            lsField.Referenced != rsField.Referenced     ? false :
            lsField.OnUpdate != rsField.OnUpdate       ? false :
            lsField.OnDelete != rsField.OnDelete       ? false : true);
 }
Beispiel #3
0
        /// <summary>
        /// Returns a list of filtered fields
        /// </summary>
        /// <param name="fields">List of raw fields</param>
        /// <param name="consts">List of raw constraints</param>
        /// <returns>Building Collection Of Fields</returns>
        private List <DtoFullField> BuildingCollectionOfFields(List <DtoFullField> fields, List <DtoFullField> consts)
        {
            List <DtoFullField> tempFullFieldsCollection = new List <DtoFullField>();

            foreach (var field in fields)
            {
                DtoFullField fullField = new DtoFullField()
                {
                    FieldName  = field.FieldName,
                    TypeName   = field.TypeName,
                    Size       = field.Size,
                    IsNullable = field.IsNullable
                };

                bool added = false;
                bool flag  = false;
                foreach (var con in consts)
                {
                    if (con.FieldName == field.FieldName && !flag)
                    {
                        fullField.ConstraintKeys = con.ConstraintKeys;
                        fullField.ConstraintName = con.ConstraintName;
                        fullField.ConstraintType = con.ConstraintType;
                        fullField.Referenced     = con.Referenced;
                        fullField.OnUpdate       = con.OnUpdate;
                        fullField.OnDelete       = con.OnDelete;
                        flag  = true;
                        added = true;
                        tempFullFieldsCollection.Add(fullField);
                    }
                    else if (con.FieldName == field.FieldName && flag)
                    {
                        DtoFullField temp = new DtoFullField()
                        {
                            ConstraintKeys = con.ConstraintKeys,
                            ConstraintName = con.ConstraintName,
                            ConstraintType = con.ConstraintType,
                            OnDelete       = con.OnDelete,
                            OnUpdate       = con.OnUpdate,
                            Referenced     = con.Referenced
                        };
                        tempFullFieldsCollection.Add(temp);
                    }
                }
                if (!added)
                {
                    tempFullFieldsCollection.Add(fullField);
                }
            }
            return(tempFullFieldsCollection);
        }
        /// <summary>
        /// Returns a list of filtered fields
        /// </summary>
        /// <param name="fields">List of raw fields</param>
        /// <param name="consts">List of raw constraints</param>
        /// <returns>Building Collection Of Fields</returns>
        private List <DtoFullField> BuildingCollectionOfFields(IEnumerable <MySqlFields> fields, List <DtoConstraint> consts)
        {
            List <DtoFullField> tempFieldsList = new List <DtoFullField>();

            foreach (var item in fields)
            {
                DtoFullField temp = new DtoFullField
                {
                    FieldName      = item.COLUMN_NAME,
                    TypeName       = item.DATA_TYPE + ' ' + item.EXTRA,
                    IsNullable     = item.IS_NULLABLE,
                    ConstraintKeys = item.COLUMN_DEFAULT,
                    Size           = item.CHARACTER_MAXIMUM_LENGTH
                };

                bool added = false;
                bool flag  = false;

                foreach (var con in consts)
                {
                    if (con.FieldName == item.COLUMN_NAME && !flag)
                    {
                        temp.ConstraintType = con.ConstraintType;
                        temp.ConstraintName = con.ConstraintName;
                        temp.Referenced     = con.Referenced;
                        temp.OnDelete       = con.OnDelete;
                        temp.OnUpdate       = con.OnUpdate;
                        flag  = true;
                        added = true;
                        tempFieldsList.Add(temp);
                    }
                    else if (con.FieldName == item.COLUMN_NAME && flag)
                    {
                        DtoFullField qwe = new DtoFullField()
                        {
                            ConstraintType = con.ConstraintType,
                            ConstraintName = con.ConstraintName,
                            Referenced     = con.Referenced
                        };
                        tempFieldsList.Add(qwe);
                    }
                }
                if (!added)
                {
                    tempFieldsList.Add(temp);
                }
            }

            return(tempFieldsList);
        }
Beispiel #5
0
        /// <summary>
        /// Returns a list of filtered fields
        /// </summary>
        /// <param name="fields">List of raw fields</param>
        /// <param name="consts">List of raw constraints</param>
        /// <returns>Building Collection Of Fields</returns>
        private List <DtoFullField> BuildingCollectionOfFields(IEnumerable <Fields> fields, List <DtoConstraint> consts)
        {
            List <DtoFullField> tempResultCollection = new List <DtoFullField>();

            foreach (var field in fields)
            {
                DtoFullField temp = new DtoFullField()
                {
                    FieldName  = field.COLUMN_NAME,
                    TypeName   = field.TYPE_NAME, //------------------
                    Size       = field.CHAR_OCTET_LENGTH,
                    IsNullable = field.IS_NULLABLE
                };

                bool added = false;
                bool flag  = false;
                foreach (var con in consts)
                {
                    if (con.FieldName == field.COLUMN_NAME && !flag)
                    {
                        temp.ConstraintType = con.ConstraintType;
                        temp.ConstraintName = con.ConstraintName;
                        temp.ConstraintKeys = con.ConstraintKeys;
                        temp.Referenced     = con.Referenced;
                        temp.OnDelete       = con.OnDelete;
                        temp.OnUpdate       = con.OnUpdate;
                        flag  = true;
                        added = true;
                        tempResultCollection.Add(temp);
                    }
                    else if (con.FieldName == field.COLUMN_NAME && flag)
                    {
                        DtoFullField qwe = new DtoFullField()
                        {
                            ConstraintType = con.ConstraintType,
                            ConstraintName = con.ConstraintName,
                            ConstraintKeys = con.ConstraintKeys,
                            Referenced     = con.Referenced
                        };
                        tempResultCollection.Add(qwe);
                    }
                }
                if (!added)
                {
                    tempResultCollection.Add(temp);
                }
            }
            return(tempResultCollection);
        }
Beispiel #6
0
        /// <summary>
        /// Returns a prepared collection of restrictions and fields
        /// </summary>
        /// <param name="fields">List of raw fields</param>
        /// <param name="constraints">List of raw constraints</param>
        /// <returns>The filtered list of constraints and fields of the table</returns>
        private List <DtoFullField> ConstraintsCollectionPreparation(List <DtoFullField> fields, IEnumerable <DtoSyBaseConstaintsModel> constraints)
        {
            List <DtoFullField> tempConstraints = new List <DtoFullField>();

            foreach (var item in constraints)
            {
                DtoFullField field = new DtoFullField();

                if (item.ConstraintType == "Table Constraint")
                {
                    field.ConstraintType = GetConstraintType(item.ConstraintKeys);
                    field.ConstraintKeys = GetConstraintKey(item.ConstraintKeys);
                    field.FieldName      = GetConstraintField(item.ConstraintKeys, fields);
                }
                else
                {
                    field.ConstraintType = GetConstraintType(item.ConstraintType);
                    field.ConstraintKeys = item.ConstraintKeys;
                    field.FieldName      = item.FieldName;
                }

                field.ConstraintName = item.ConstraintName;
                field.OnDelete       = item.OnDelete;
                field.OnUpdate       = item.OnUpdate;
                field.Referenced     = GetReferenced(item.OtherTable, item.OtherColumns);

                tempConstraints.Add(field);
            }

            foreach (var item in fields)
            {
                if (item.ConstraintType == "DEFAULT")
                {
                    DtoFullField field = new DtoFullField();

                    field.ConstraintType = item.ConstraintType;
                    field.ConstraintKeys = item.ConstraintKeys;
                    field.FieldName      = item.FieldName;
                    tempConstraints.Add(field);
                }
            }

            return(tempConstraints);
        }
        /// <summary>
        /// Alignment of the collection
        /// </summary>
        /// <param name="lsCol">Left side collection</param>
        /// <param name="rsCol">Right side collection</param>
        private void Alignment(ObservableCollection <DtoFullField> lsCol, ObservableCollection <DtoFullField> rsCol)
        {
            int size = lsCol.Count - rsCol.Count;

            for (int i = 0; i < size; i++)
            {
                var field = new DtoFullField()
                {
                    ConstraintKeys = "",
                    ConstraintType = "",
                    ConstraintName = "",
                    FieldName      = "",
                    IsNullable     = "",
                    OnDelete       = "",
                    OnUpdate       = "",
                    Referenced     = "",
                    Size           = "",
                    TypeName       = ""
                };
                rsCol.Add(field);
            }
        }