コード例 #1
0
ファイル: DbEngine.cs プロジェクト: rahulchrty/badr-project
 protected abstract string ToSqlCreateStatement(Field field);
コード例 #2
0
ファイル: Field.cs プロジェクト: rahulchrty/badr-project
 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;
         }
     }
 }
コード例 #3
0
ファイル: DbEngine.cs プロジェクト: rahulchrty/badr-project
 public virtual string ToSqlFormat(Field field)
 {
     if (field != null)
         return ToSqlFormat(field.FieldType, field.Value);
     return "null";
 }
コード例 #4
0
        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;
        }