private ColumnModel GetColumnModel(String columnName, String comment, string typeName, int precision, int digit, int length, int autoGen, List <string> pkList) { ColumnModel model = new ColumnModel(); model.ColumnName = columnName.ToUpper(); model.Comment = comment; if (pkList.Contains(columnName)) { model.IsPK = true; } model.Length = length; model.Precision = precision; model.Scale = digit; model.AutoGen = autoGen; model.ColType = this.STRING; if ((typeName.Equals("int") || typeName.Equals("tinyint")) || typeName.Equals("mediumint")) { model.ColType = this.INT; } if (typeName.Equals("bigint")) { model.ColType = this.LONG; } if ((typeName.Equals("float") || typeName.Equals("double")) || typeName.Equals("decimal")) { model.ColType = this.FLOAT; } if ((((typeName.Equals("char") || typeName.Equals("varchar")) || (typeName.Equals("tinytext") || typeName.Equals("text"))) || typeName.Equals("mediumtext")) || typeName.Equals("longtext")) { model.ColType = this.STRING; } if (((typeName.Equals("datetime") || typeName.Equals("timestamp")) || typeName.Equals("datetime")) || typeName.Equals("time")) { model.ColType = this.DATE; } model.ColDbType = typeName; return(model); }
private List <ColumnModel> GetColumn(string tableName, List <string> pkList) { List <ColumnModel> list = new List <ColumnModel>(); string sql = string.Format(sqlColumn, tableName); DataSet ds = this.GetData(sql); DataTable dt = ds.Tables[0]; foreach (DataRow dr in dt.Rows) { string name = dr["NAME"].ToString(); string typename = dr["TYPENAME"].ToString(); int length = int.Parse(dr["LENGTH"].ToString()); int precision = 0; object objPrecision = dr["PRECISION"]; if (objPrecision != null && objPrecision != DBNull.Value) { precision = int.Parse(objPrecision.ToString()); } int scale = 0; object objScale = dr["SCALE"]; if (objScale != null && objScale != DBNull.Value) { scale = int.Parse(objScale.ToString()); } object objDesc = dr["DESCRIPTION"]; string description = name; if (objDesc != null && objDesc != DBNull.Value) { description = objDesc.ToString(); } ColumnModel colModel = GetColumnModel(name, description, typename, precision, scale, length, 0, pkList); list.Add(colModel); } return(list); }
private ColumnModel GetColumnModel(String columnName, String comment, string typeName, int precision, int digit, int length, int autoGen, List <string> pkList) { ColumnModel model = new ColumnModel(); model.ColumnName = columnName.ToUpper(); model.Comment = comment; //设定主键 if (pkList.Contains(columnName)) { model.IsPK = true; } model.Length = length; model.Precision = precision; model.Scale = digit; model.AutoGen = autoGen; model.ColType = this.STRING; if (typeName.Equals("bigint")) { model.ColType = this.LONG; } if (typeName.Equals("bit")) { model.ColType = this.BOOLEAN; } if (typeName.Equals("char") || typeName.Equals("nchar")) { model.ColType = this.STRING; } if ((typeName.Equals("nvarchar") && length == -1) || (typeName.Equals("varchar") && length == -1)) { model.ColType = this.STRING; } if ((typeName.Equals("nvarchar") && length > 0) || (typeName.Equals("varchar") && length > 0)) { model.ColType = this.STRING; } if (typeName.Equals("float")) { model.ColType = this.FLOAT; } if (typeName.Equals("real")) { model.ColType = this.FLOAT; } if (typeName.Equals("smalldatetime") || typeName.Equals("datetime")) { model.ColType = this.DATE; } if (typeName.Equals("smallint")) { model.ColType = this.INT; } if (typeName.Equals("int")) { model.ColType = this.INT; } if (typeName.Equals("numeric") && precision < 11 && digit == 0) { model.ColType = this.INT; } if (typeName.Equals("numeric") && precision > 10 && digit == 0) { model.ColType = this.LONG; } if (typeName.Equals("numeric") && digit > 0) { model.ColType = this.FLOAT; } if (typeName.Equals("decimal") && precision < 11 && digit == 0) { model.ColType = this.INT; } if (typeName.Equals("decimal") && precision > 10 && digit == 0) { model.ColType = this.LONG; } if (typeName.Equals("decimal") && digit > 0) { model.ColType = this.FLOAT; } if (typeName.Equals("uniqueidentifier")) { model.ColType = this.STRING; } if (typeName.Equals("xml")) { model.ColType = this.STRING; } if (typeName.Equals("tinyint")) { model.ColType = this.INT; } if (typeName.Equals("smallmoney") || typeName.Equals("money")) { model.ColType = this.FLOAT; } if (typeName.Equals("timestamp")) { model.ColType = this.STRING; } if (typeName.Equals("text") || typeName.Equals("ntext")) { model.ColType = this.STRING; } model.ColDbType = typeName; return(model); }
private ColumnModel GetColumnModel(String columnName, String comment, string typeName, int precision, int digit, int length, int autoGen, List <string> pkList) { ColumnModel model = new ColumnModel(); model.ColumnName = columnName.ToUpper(); model.Comment = comment; //设定主键 if (pkList.Contains(columnName)) { model.IsPK = true; } model.Length = length; model.Precision = precision; model.Scale = digit; model.AutoGen = autoGen; model.ColType = this.STRING; //ORACLE START //数字类型处理 if (typeName.Equals("NUMBER")) { if (digit > 0) { model.ColType = this.FLOAT; } else if (precision > 10) { model.ColType = this.LONG; } else { model.ColType = this.INT; } } //浮点类型 if (typeName.Equals("FLOAT")) { model.ColType = this.FLOAT; //model.ColDbType = "FLOAT"; } //char类型 if (typeName.Equals("VARCHAR2") || typeName.Equals("NCHAR") || typeName.Equals("CHAR") || typeName.Equals("NVARCHAR2")) { model.ColType = this.STRING; //model.ColDbType = typeName; } if (typeName.Equals("CLOB") || typeName.Equals("NCLOB")) { model.ColType = this.STRING; //model.ColDbType = typeName; } //日期类型处理 if (typeName.Equals("DATE")) { model.ColType = this.DATE; //model.ColDbType = typeName; } //ORACLE END model.ColDbType = typeName; return(model); }
/// <summary> /// 添加列对象 /// </summary> /// <param name="columnModel"></param> public void addColumnModel(ColumnModel columnModel) { columnList.Add(columnModel); }