public void SInTests_SInEnum_FlagsDefault() { CrudSpecialColType specialType = CrudSpecialColType.None; int specialTypeInt = (int)specialType; Assert.AreEqual(specialType, SIn.Enum(specialTypeInt, defaultEnumOption: CrudSpecialColType.TextIsClob)); }
public void SInTests_SInEnum_Flags() { CrudSpecialColType specialType = CrudSpecialColType.CleanText | CrudSpecialColType.EnumAsString; int specialTypeInt = (int)specialType; Assert.AreEqual(specialType, SIn.Enum <CrudSpecialColType>(specialTypeInt)); }
public CrudColumnAttribute() { this.isPriKey=false; this.specialType=CrudSpecialColType.None; this.isNotDbColumn=false; this.isPriKeyMobile1=false; this.isPriKeyMobile2=false; }
public static OdDbType GetOdDbTypeFromColType(Type fieldType,CrudSpecialColType specialType) { if(specialType==CrudSpecialColType.DateEntry || specialType==CrudSpecialColType.DateEntryEditable) { return OdDbType.Date; } if(specialType==CrudSpecialColType.TimeStamp) { return OdDbType.DateTimeStamp; } if(specialType==CrudSpecialColType.DateT || specialType==CrudSpecialColType.DateTEntry || specialType==CrudSpecialColType.DateTEntryEditable) { return OdDbType.DateTime; } if(specialType==CrudSpecialColType.EnumAsString) { return OdDbType.VarChar255; } if(specialType==CrudSpecialColType.TimeSpanNeg) { return OdDbType.TimeSpan; } if(specialType==CrudSpecialColType.TextIsClob) { return OdDbType.Text; } if(fieldType.IsEnum) { return OdDbType.Enum; } switch(fieldType.Name) { default: throw new ApplicationException("Type not yet supported: "+fieldType.Name); case "Bitmap": return OdDbType.Text; case "Boolean": return OdDbType.Bool; case "Byte": return OdDbType.Byte; case "Color": return OdDbType.Int; case "DateTime"://This is only for date, not dateT return OdDbType.Date; case "Double": return OdDbType.Currency; case "Interval": return OdDbType.Int; case "Int64": return OdDbType.Long; case "Int32": return OdDbType.Int; case "Single": return OdDbType.Float; case "String": return OdDbType.VarChar255;//or text case "TimeSpan": return OdDbType.TimeOfDay; } }
public static OdDbType GetOdDbTypeFromColType(Type fieldType, CrudSpecialColType specialType) { if (specialType.HasFlag(CrudSpecialColType.DateEntry) || specialType.HasFlag(CrudSpecialColType.DateEntryEditable)) { return(OdDbType.Date); } if (specialType.HasFlag(CrudSpecialColType.TimeStamp)) { return(OdDbType.DateTimeStamp); } if (specialType.HasFlag(CrudSpecialColType.DateT) || specialType.HasFlag(CrudSpecialColType.DateTEntry) || specialType.HasFlag(CrudSpecialColType.DateTEntryEditable)) { return(OdDbType.DateTime); } if (specialType.HasFlag(CrudSpecialColType.EnumAsString)) { return(OdDbType.VarChar255); } if (specialType.HasFlag(CrudSpecialColType.TimeSpanNeg)) { return(OdDbType.TimeSpan); } if (specialType.HasFlag(CrudSpecialColType.TimeSpanLong)) { return(OdDbType.Long); } if (specialType.HasFlag(CrudSpecialColType.TextIsClob)) { return(OdDbType.Text); } if (fieldType.IsEnum) { return(OdDbType.Enum); } switch (fieldType.Name) { default: throw new ApplicationException("Type not yet supported: " + fieldType.Name); case "Bitmap": return(OdDbType.Text); case "Boolean": return(OdDbType.Bool); case "Byte": return(OdDbType.Byte); case "Color": return(OdDbType.Int); case "DateTime": //This is only for date, not dateT return(OdDbType.Date); case "Double": return(OdDbType.Currency); case "Interval": return(OdDbType.Int); case "Int64": return(OdDbType.Long); case "Int32": return(OdDbType.Int); case "Single": return(OdDbType.Float); case "String": return(OdDbType.VarChar255); //or text case "TimeSpan": return(OdDbType.TimeOfDay); } }
public static void ValidateColumn(string dbName, string tablename, FieldInfo field, DataTable table) { //make sure the column exists string dataTypeInDb = ""; for (int i = 0; i < table.Rows.Count; i++) { if (table.Rows[i]["COLUMN_NAME"].ToString().ToLower() == field.Name.ToLower()) { dataTypeInDb = table.Rows[i]["DATA_TYPE"].ToString(); } } if (dataTypeInDb == "") { return; //can't validate } CrudSpecialColType specialColType = GetSpecialType(field); string dataTypeExpected = ""; string dataTypeExpected2 = "";//if an alternate datatype is allowed string dataTypeExpected3 = ""; string dataTypeExpected4 = ""; string dataTypeExpected5 = ""; if (specialColType == CrudSpecialColType.TimeStamp) { dataTypeExpected = "timestamp"; } else if (specialColType == CrudSpecialColType.DateEntry) { dataTypeExpected = "date"; } else if (specialColType == CrudSpecialColType.DateEntryEditable) { dataTypeExpected = "date"; } else if (specialColType == CrudSpecialColType.DateT) { dataTypeExpected = "datetime"; } else if (specialColType == CrudSpecialColType.DateTEntry) { dataTypeExpected = "datetime"; } else if (specialColType == CrudSpecialColType.DateTEntryEditable) { dataTypeExpected = "datetime"; } else if (specialColType == CrudSpecialColType.TinyIntSigned) { dataTypeExpected = "tinyint"; } else if (specialColType == CrudSpecialColType.EnumAsString) { dataTypeExpected = "varchar"; } else if (field.FieldType.IsEnum) { dataTypeExpected = "tinyint"; dataTypeExpected2 = "int"; dataTypeExpected3 = "smallint"; } else { switch (field.FieldType.Name) { default: throw new ApplicationException("Type not yet supported: " + field.FieldType.Name); case "Bitmap": dataTypeExpected = "mediumtext"; dataTypeExpected2 = "text"; //only for very small images break; case "Boolean": dataTypeExpected = "tinyint"; break; case "Byte": dataTypeExpected = "tinyint"; break; case "Color": dataTypeExpected = "int"; break; case "DateTime": dataTypeExpected = "date"; //If the mysql field is datetime, then the C# field should have an [attribute] describing the type. break; case "Double": dataTypeExpected = "double"; break; case "Interval": dataTypeExpected = "int"; break; case "Int64": dataTypeExpected = "bigint"; break; case "Int32": //use C# int for ItemOrder style fields. We know they will not use random keys. dataTypeExpected = "int"; dataTypeExpected2 = "smallint"; //ok as long as the coding is careful. Less than ideal. //tinyint not allowed. Possibly change C# type to byte if values can be between 0 and 255 with no negatives. //We might some day use SByte for values that can be -127 to 127. Example, perio depths, percentages that allow -1, etc. For now, those are smallint. break; case "Single": dataTypeExpected = "float"; //not 1:1, but we never use the full range anyway. dataTypeExpected2 = "float unsigned"; break; case "String": dataTypeExpected = "varchar"; dataTypeExpected2 = "text"; dataTypeExpected3 = "char"; dataTypeExpected4 = "mediumtext"; dataTypeExpected5 = "longtext"; break; case "TimeSpan": dataTypeExpected = "time"; break; } } if (dataTypeInDb != dataTypeExpected && dataTypeInDb != dataTypeExpected2 && dataTypeInDb != dataTypeExpected3 && dataTypeInDb != dataTypeExpected4 && dataTypeInDb != dataTypeExpected5) { throw new Exception(tablename + "." + field.Name + " type mismatch. Look in the lines of code above for case \"" + field.FieldType.Name + "\". The types listed are what is allowed in the mysql database. " + dataTypeInDb + " is not one of the allowed mysql types."); } }
public static void ValidateColumn(string dbName, string tablename, FieldInfo field, DataTable table) { #region Oracle Removed //if(!tablename.In(//The ehrlab tables have already been released with long column names. We might fix later. // "ehrlab","ehrlabresult","ehrlabresultscopyto","ehrlabspecimencondition","ehrlabspecimenrejectreason", // "triagemetric"))//Hq only table //{ // if(field.Name.Length>30) { // throw new ApplicationException("Column name longer than 30 characters. Invalid for Oracle. Shorten the column name. See "+tablename+"."+field.Name); // } //} #endregion //make sure the column exists string dataTypeInDb = ""; for (int i = 0; i < table.Rows.Count; i++) { if (table.Rows[i]["COLUMN_NAME"].ToString().ToLower() == field.Name.ToLower()) { dataTypeInDb = table.Rows[i]["DATA_TYPE"].ToString(); } } if (dataTypeInDb == "") { return; //can't validate } CrudSpecialColType specialColType = GetSpecialType(field); string dataTypeExpected = ""; string dataTypeExpected2 = "";//if an alternate datatype is allowed string dataTypeExpected3 = ""; if (specialColType.HasFlag(CrudSpecialColType.TimeStamp)) { dataTypeExpected = "timestamp"; } else if (specialColType.HasFlag(CrudSpecialColType.TimeSpanLong)) { dataTypeExpected = "bigint"; } else if (specialColType.HasFlag(CrudSpecialColType.DateEntry)) { dataTypeExpected = "date"; } else if (specialColType.HasFlag(CrudSpecialColType.DateEntryEditable)) { dataTypeExpected = "date"; } else if (specialColType.HasFlag(CrudSpecialColType.DateT)) { dataTypeExpected = "datetime"; } else if (specialColType.HasFlag(CrudSpecialColType.DateTEntry)) { dataTypeExpected = "datetime"; } else if (specialColType.HasFlag(CrudSpecialColType.DateTEntryEditable)) { dataTypeExpected = "datetime"; } else if (specialColType.HasFlag(CrudSpecialColType.TinyIntSigned)) { dataTypeExpected = "tinyint"; } else if (specialColType.HasFlag(CrudSpecialColType.EnumAsString)) { dataTypeExpected = "varchar"; } else if (specialColType.HasFlag(CrudSpecialColType.TextIsClob)) { dataTypeExpected = "text"; dataTypeExpected2 = "mediumtext"; dataTypeExpected3 = "longtext"; } else if (field.FieldType.IsEnum) { dataTypeExpected = "tinyint"; dataTypeExpected2 = "int"; dataTypeExpected3 = "smallint"; } else { switch (field.FieldType.Name) { default: throw new ApplicationException("Type not yet supported: " + field.FieldType.Name); case "Bitmap": dataTypeExpected = "mediumtext"; dataTypeExpected2 = "text"; //only for very small images break; case "Boolean": dataTypeExpected = "tinyint"; break; case "Byte": dataTypeExpected = "tinyint"; break; case "Color": dataTypeExpected = "int"; break; case "DateTime": dataTypeExpected = "date"; //If the mysql field is datetime, then the C# field should have an [attribute] describing the type. break; case "Double": dataTypeExpected = "double"; break; case "Interval": dataTypeExpected = "int"; break; case "Int64": dataTypeExpected = "bigint"; break; case "Int32": //use C# int for ItemOrder style fields. We know they will not use random keys. dataTypeExpected = "int"; dataTypeExpected2 = "smallint"; //ok as long as the coding is careful. Less than ideal. //tinyint not allowed. Possibly change C# type to byte if values can be between 0 and 255 with no negatives. //We might some day use SByte for values that can be -127 to 127. Example, perio depths, percentages that allow -1, etc. For now, those are smallint. break; case "Single": dataTypeExpected = "float"; //not 1:1, but we never use the full range anyway. dataTypeExpected2 = "float unsigned"; break; case "String": dataTypeExpected = "varchar"; dataTypeExpected3 = "char"; //text, mediumtext, or longtext should be marked TextIsClob break; case "TimeSpan": dataTypeExpected = "time"; break; } } if (!dataTypeInDb.In(dataTypeExpected, dataTypeExpected2, dataTypeExpected3)) { throw new Exception(tablename + "." + field.Name + " type mismatch. Look in the lines of code above for case \"" + field.FieldType.Name + "\". The types listed are what is allowed in the mysql database. " + dataTypeInDb + " is not one of the allowed mysql types."); } }