Beispiel #1
0
        public void AddColumn(string tableName, DbColumnInfo columnInfo)
        {
            #region QUERY
            const string query = "ALTER TABLE {0} ADD {1}";
            #endregion

            StringBuilder inserting = new StringBuilder("");

            inserting.Append(columnInfo.Name);
            inserting.Append(" ");
            inserting.Append(columnInfo.Type);
            inserting.Append(" ");
            if (!columnInfo.Nullable)
            {
                inserting.Append("NOT NULL ");
            }
            if (columnInfo.PrimaryKey)
            {
                inserting.Append("PRIMARY KEY ");
            }
            if (columnInfo.Reference != null && columnInfo.Reference != "")
            {
                DbColumnReference reference = DbColumnReference.TryParse(columnInfo.Reference);
                inserting.Append(string.Format("REFERENCES {0}({1})", reference.TableName, reference.ColumnName));
                inserting.Append(" ");
            }

            while (inserting.Length > 0 && inserting[inserting.Length - 1] == ' ')
            {
                inserting.Remove(inserting.Length - 1, 1);
            }

            ExecuteCommandReader(string.Format(query, tableName, inserting.ToString()));
        }
Beispiel #2
0
        public string CreateString()
        {
            StringBuilder res = new StringBuilder("");

            res.Append(Name);
            res.Append(" ");
            res.Append(Type);
            res.Append(" ");
            if (Reference != "" && Reference != null)
            {
                DbColumnReference reference = DbColumnReference.TryParse(Reference);
                res.Append(string.Format("REFERENCES {0}({1})", reference.TableName, reference.ColumnName));
                res.Append(" ");
            }
            if (!Nullable)
            {
                res.Append("NOT NULL ");
            }

            return(res.ToString());
        }