internal static FieldBase Create(DDLColumn c) { FieldBase fieldBase = new FieldBase(); fieldBase.Name = CodeUtil.GetFieldName(c); fieldBase.Desc = c.Desc; fieldBase.Remark = c.Remark; fieldBase.DDLColumn = c; fieldBase.FieldType = DDLUtil.AnalysisFieldType(c); fieldBase.JDBCType = DBUtil.AnalysisJDBCType(fieldBase.FieldType); fieldBase.IsKeyField = c.IsKeyColumn(); fieldBase.IsPrimaryKeyColumn = c.IsPrimaryKeyColumn(); fieldBase.IsUniqueKeyColumn = c.IsUniqueKeyColumn(); fieldBase.IsParentKey = c.IsParentKey; return(fieldBase); }
public void Prepare() { if (this.prepared == true) { return; } foreach (var table in Tables) { table.DDLConfig = this; table.Columns.ForEach(x => { x.DDLTable = table; }); if (table.Columns.FindAll(x => x.Validate()).ConvertAll <string>(x => x.Name).Distinct <string>().Count <string>() != table.Columns.FindAll(x => x.Validate()).Count) { for (int i = 0; i < table.Columns.Count; i++) { for (int j = i + 1; j < table.Columns.Count; j++) { if (table.Columns[i].Name == table.Columns[j].Name) { throw new Exception(String.Format("表:{0}存在重复列{1}", table.TableName, table.Columns[i].Name)); } } } } if (this.MyDBType == DBType.Oracle) { table.TableNameSQL = table.TableName.ToUpper(); if (table.TableName.Length > 30) { throw new Exception(String.Format("表名称:{0}过长", table.TableName)); } } bool idexists = table.Columns.Exists(x => x.Name.ToLower() == "id"); if (false == idexists) { if (false == table.HasKeyCol()) { table.Columns.Insert(0, new DDLColumn("ID", "id", "bigint(20)", "是", "")); } else { table.Columns.Insert(0, new DDLColumn("ID", "id", "bigint(20)", "", "")); } } table.Columns.ForEach(x => { x.SqlType = GetSqlDBType(x.TypeName, this.MyDBType, x.Length); x.NameSql = DDLUtil.InferColName(x.Name, this.UnifyName, this.DBColSeparator); if (this.MyDBType == DBType.Oracle) { x.NameSql = x.NameSql.ToUpper(); if (x.NameSql.Length > 30) { throw new Exception(String.Format("列名称:{0} {1}过长", table.TableName, x.NameSql)); } } }); } this.prepared = true; }