示例#1
0
        public override bool Equals(object obj)
        {
            ColumnTypeDef foo = obj as ColumnTypeDef;

            return(foo != null && foo.Type.ToString() == Type.ToString() && foo.Size == Size &&
                   foo.defaultValue == defaultValue && foo.isNull == isNull && foo.unsigned == unsigned &&
                   foo.auto_increment == auto_increment);
        }
        public override string GetColumnTypeStringSymbol(ColumnTypeDef coldef)
        {
            string symbol;
            switch (coldef.Type)
            {
                case ColumnType.Blob:
                    symbol = "BLOB";
                    break;
                case ColumnType.LongBlob:
                    symbol = "LONGBLOB";
                    break;
                case ColumnType.Boolean:
                    symbol = "TINYINT(1)";
                    break;
                case ColumnType.Char:
                    symbol = "CHAR(" + coldef.Size + ")";
                    break;
                case ColumnType.Date:
                    symbol = "DATE";
                    break;
                case ColumnType.DateTime:
                    symbol = "DATETIME";
                    break;
                case ColumnType.Double:
                    symbol = "DOUBLE";
                    break;
                case ColumnType.Float:
                    symbol = "FLOAT";
                    break;
                case ColumnType.Integer:
                    symbol = "INT(" + coldef.Size + ")" + (coldef.unsigned ? " unsigned" : "");
                    break;
                case ColumnType.TinyInt:
                    symbol = "TINYINT(" + coldef.Size + ")" + (coldef.unsigned ? " unsigned" : "");
                    break;
                case ColumnType.String:
                    symbol = "VARCHAR(" + coldef.Size + ")";
                    break;
                case ColumnType.Text:
                    symbol = "TEXT";
                    break;
                case ColumnType.MediumText:
                    symbol = "MEDIUMTEXT";
                    break;
                case ColumnType.LongText:
                    symbol = "LONGTEXT";
                    break;
                case ColumnType.UUID:
                    symbol = "VARCHAR(36)";
                    break;
                case ColumnType.Binary:
                    symbol = "BINARY(" + coldef.Size + ")";
                    break;
                default:
                    throw new DataManagerException("Unknown column type.");
            }

            return symbol + (coldef.isNull ? " NULL" : " NOT NULL") +
                   ((coldef.isNull && coldef.defaultValue == null)
                        ? " DEFAULT NULL"
                        : (coldef.defaultValue != null ? " DEFAULT '" + coldef.defaultValue.MySqlEscape() + "'" : "")) +
                   ((coldef.Type == ColumnType.Integer || coldef.Type == ColumnType.TinyInt) && coldef.auto_increment
                        ? " AUTO_INCREMENT"
                        : "");
        }
 public override string GetColumnTypeStringSymbol(ColumnTypeDef coldef)
 {
     string symbol;
     switch (coldef.Type)
     {
         case ColumnType.Blob:
         case ColumnType.LongBlob:
             symbol = "BLOB";
             break;
         case ColumnType.Boolean:
             symbol = "TINYINT(1)";
             break;
         case ColumnType.Char:
             symbol = "CHAR(" + coldef.Size + ")";
             break;
         case ColumnType.Date:
             symbol = "DATE";
             break;
         case ColumnType.DateTime:
             symbol = "DATETIME";
             break;
         case ColumnType.Double:
             symbol = "DOUBLE";
             break;
         case ColumnType.Float:
             symbol = "FLOAT";
             break;
         case ColumnType.Integer:
             if (!coldef.auto_increment)
             {
                 symbol = "INT(" + coldef.Size + ")";
             }
             else
             {
                 symbol = "INTEGER PRIMARY KEY AUTOINCREMENT";
             }
             break;
         case ColumnType.TinyInt:
             symbol = "TINYINT(" + coldef.Size + ")";
             break;
         case ColumnType.String:
             symbol = "VARCHAR(" + coldef.Size + ")";
             break;
         case ColumnType.Text:
         case ColumnType.MediumText:
         case ColumnType.LongText:
             symbol = "TEXT";
             break;
         case ColumnType.UUID:
             symbol = "VARCHAR(36)";
             break;
         case ColumnType.Binary:
             symbol = "BINARY(" + coldef.Size + ")";
             break;
         default:
             throw new DataManagerException("[SQLite]: Unknown column definition - " + coldef);
     }
     return symbol + (coldef.isNull ? " NULL" : " NOT NULL") +
            ((coldef.isNull && coldef.defaultValue == null)
                 ? " DEFAULT NULL"
                 : (coldef.defaultValue != null
                        ? " DEFAULT " +
                          (coldef.defaultValue.StartsWith ("'", StringComparison.Ordinal) && 
                           coldef.defaultValue.EndsWith ("'", StringComparison.Ordinal)
                               ? coldef.defaultValue
                               : "'" + coldef.defaultValue + "'")
                        : ""));
 }
        public ColumnTypeDef ConvertTypeToColumnType(string typeString)
        {
            string tStr = typeString.ToLower();

            ColumnTypeDef typeDef = new ColumnTypeDef();

            switch (tStr)
            {
                case "blob":
                    typeDef.Type = ColumnType.Blob;
                    break;
                case "longblob":
                    typeDef.Type = ColumnType.LongBlob;
                    break;
                case "date":
                    typeDef.Type = ColumnType.Date;
                    break;
                case "datetime":
                    typeDef.Type = ColumnType.DateTime;
                    break;
                case "double":
                    typeDef.Type = ColumnType.Double;
                    break;
                case "float":
                    typeDef.Type = ColumnType.Float;
                    break;
                case "text":
                    typeDef.Type = ColumnType.Text;
                    break;
                case "mediumtext":
                    typeDef.Type = ColumnType.MediumText;
                    break;
                case "longtext":
                    typeDef.Type = ColumnType.LongText;
                    break;
                case "uuid":
                    typeDef.Type = ColumnType.UUID;
                    break;
                case "integer":
                    typeDef.Type = ColumnType.Integer;
                    typeDef.Size = 11;
                    break;
                case "binary":
                    typeDef.Type = ColumnType.Binary;
                    break;
                default:
                    string regexInt = "^int\\((\\d+)\\)( unsigned)?$";
                    string regexTinyint = "^tinyint\\((\\d+)\\)( unsigned)?$";
                    string regexChar = "^char\\((\\d+)\\)$";
                    string regexString = "^varchar\\((\\d+)\\)$";
                    string regexBinary = "^binary\\((\\d+)\\)$";

                    Dictionary<string, ColumnType> regexChecks = new Dictionary<string, ColumnType>(5);
                    regexChecks[regexInt] = ColumnType.Integer;
                    regexChecks[regexTinyint] = ColumnType.TinyInt;
                    regexChecks[regexChar] = ColumnType.Char;
                    regexChecks[regexString] = ColumnType.String;
                    regexChecks[regexBinary] = ColumnType.Binary;

                    Match type = Regex.Match("foo", "^bar$");
                    foreach (KeyValuePair<string, ColumnType> regexCheck in regexChecks)
                    {
                        type = Regex.Match(tStr, regexCheck.Key);
                        if (type.Success)
                        {
                            typeDef.Type = regexCheck.Value;
                            break;
                        }
                    }

                    if (type.Success)
                    {
                        typeDef.Size = uint.Parse(type.Groups[1].Value);
                        typeDef.unsigned = (typeDef.Type == ColumnType.Integer || typeDef.Type == ColumnType.TinyInt)
                                               ? (type.Groups.Count == 3 && type.Groups[2].Value == " unsigned")
                                               : false;
                        break;
                    }

                    throw new Exception(
                            "You've discovered some type that's not recognized by Universe, please place the correct conversion in ConvertTypeToColumnType. Type: " +
                            tStr);
            }

            return typeDef;
        }
 public abstract string GetColumnTypeStringSymbol(ColumnTypeDef coldef);