protected virtual String ParseType(FieldType type) { List<String> parsed = new List<String>(); Length length = type.FirstOrDefault(attribute => attribute is Length) as Length; if (type is StringType) { parsed.Add(String.Format("VARCHAR({0})", length == null ? 255 : length.Value)); } else if (type is IntegerType) { parsed.Add("INTEGER"); } else if (type is DateTimeType) { parsed.Add("DATETIME"); } // Enforce NOT NULL and inline primary key when AutoIncrement is used. if (type.Any(attribute => attribute is AutoIncrement) == true) { parsed.Add("PRIMARY KEY AUTOINCREMENT NOT NULL"); } else if (type.Any(attribute => attribute is Nullable) == false) { parsed.Add("NOT NULL"); } return String.Join(" ", parsed); }
protected virtual String ParseType(FieldType type) { List<String> parsed = new List<String>(); Length length = type.FirstOrDefault(attribute => attribute is Length) as Length; Unsigned unsigned = type.FirstOrDefault(attribute => attribute is Unsigned) as Unsigned; if (type is StringType) { parsed.Add(String.Format("VARCHAR({0})", length == null ? 255 : length.Value)); } else if (type is IntegerType) { parsed.Add("INT"); if (unsigned != null) { parsed.Add("UNSIGNED"); } } else if (type is DateTimeType) { parsed.Add("DATETIME"); } parsed.Add(type.Any(attribute => attribute is Nullable) == true ? "NULL" : "NOT NULL"); if (type.Any(attribute => attribute is AutoIncrement) == true) { parsed.Add("AUTO_INCREMENT"); } return String.Join(" ", parsed); }