using System; using System.Collections.Generic; using System.Linq; using System.Text; using FireBirdUtil.SqlUtils; namespace FireBirdUtil.DataTypes { public class FieldInfo { private bool _IsKey = false; public bool IsKey { get { return _IsKey; } set { _IsKey = value; } } private bool _IsNotNull = false; public bool IsNotNull { get { return _IsNotNull; } set { _IsNotNull = value; } } private bool _IsAutoIncrease = false; public bool IsAutoIncrease { get { return _IsAutoIncrease; } set { _IsAutoIncrease = value; } } /// /// 字段名称 /// public string FieldName { get; set; } /// /// 字段类型 /// //TODO:学习FireBird的数据类型,然后重写该类相关方法或重新设计该类 public FBType FieldType { get; set; }//TODO:把类型改为与C#的类型对应起来.可用一个单独的类实现 /// /// 字段类型参数。如:“varchar(20)”中的“(20)” /// public string FieldTypeParams { get; set; }//TODO:是否可考虑将括号去掉,在本程序中实现? //TODO:是否考虑支持数组。firebird支持数组 /// /// 获取字段信息 /// public string GetSQL() { #if DEBUG if (string.IsNullOrEmpty(FieldName)) throw new ArgumentException("FieldName参数没有赋值"); if (FieldType == 0) throw new ArgumentException("FieldType参数没有赋值。该参数表示数据库中字段的类型"); #endif string sql = FieldName + " " + FieldType.ToTypeString(); if (!string.IsNullOrEmpty(FieldTypeParams)) sql += FieldTypeParams; if (_IsNotNull) sql += " not null"; if (_IsKey) sql += " primary key"; return sql; } /// /// 创建自增变量的SQL语句 /// public string GetSql_AddGenerator(string tableName) { return SqlUtil.GetSql_AddGenerator(tableName); } /// /// 查找指定自增变量的数量(用于判断是否存在指定自增变量) /// public string GetSql_SelectGeneratorCount(string tableName) { return SqlUtil.GetSql_SelectGeneratorCount(tableName); } /// /// 删除自增变量的SQL语句 /// public string GetSql_DropGenerator(string tableName) { return SqlUtil.GetSql_DropGenerator(tableName); } public string GetSql_AddAutoIncreaseTrigger(string tableName) { return GetSql_AddAutoIncreaseTrigger(tableName, null); } public string GetSql_AddAutoIncreaseTrigger(string tableName, string AutoIncreasedFieldTypeIfNotNum) {//TODO:未测试AutoIncreasedFieldTypeIfNotNum不为空的情况 return SqlUtil.GetSql_AddAutoIncreaseTrigger(tableName, FieldName, AutoIncreasedFieldTypeIfNotNum); } } }