protected abstract string ToSqlCreateStatement(Field field);
public FieldInfo(Field field) { _field = field; if (field != null) { if (field.FieldType == Fields.FieldType.ForeignKey) ReferencedType =((ForeignKeyField)_field).Reference; else if (field.FieldType == Fields.FieldType.ManyToMany) { ManyToManyField m2mField = (ManyToManyField)_field; ReferencedType = m2mField.ReferencedType; IntermediaryModel = m2mField.IntermediaryModel; } } }
public virtual string ToSqlFormat(Field field) { if (field != null) return ToSqlFormat(field.FieldType, field.Value); return "null"; }
protected override string ToSqlCreateStatement(Field field) { if (field != null) { string colSpecific = null; switch (field.FieldType) { case FieldType.Char: case FieldType.Email: colSpecific = string.Format("nvarchar({0})", ((CharField)field).MaxLength); break; case FieldType.Text: colSpecific = "nvarchar(max)"; break; case FieldType.Date: colSpecific = "date"; break; case FieldType.DateTime: colSpecific = "datetime2"; break; case FieldType.Integer: colSpecific = string.Format("int{0}", ((IntegerField)field).AutoIncrement ? " IDENTITY PRIMARY KEY" : ""); break; case FieldType.Decimal: colSpecific = "numeric"; break; case FieldType.ForeignKey: IModel referencedModel = OrmManager.GetModelInfo(((ForeignKeyField)field).Reference); if (referencedModel != null) colSpecific = string.Format("int REFERENCES {0}({1})", referencedModel.ModelDbName, referencedModel.ModelPKName); break; case FieldType.ManyToMany: break; case FieldType.Custom: break; default: break; } if (colSpecific != null) { return string.Format("{0} {1} {2} {3}", field.DbName, field.Null ? "NULL" : "NOT NULL", colSpecific, field.Default != null ? "DEFAULT " + ToSqlFormat(field.FieldType, field.Default) : ""); } } return null; }