public void SetTypeAndFlags()

in MySQL.Data/src/Field.cs [149:254]


    public void SetTypeAndFlags(MySqlDbType type, ColumnFlags flags)
    {
      Flags = flags;
      Type = type;

      if (String.IsNullOrEmpty(TableName) && String.IsNullOrEmpty(RealTableName) &&
        IsBinary && driver.Settings.FunctionsReturnString)
      {
        CharacterSetIndex = driver.ConnectionCharSetIndex;
      }

      // if our type is an unsigned number, then we need
      // to bump it up into our unsigned types
      // we're trusting that the server is not going to set the UNSIGNED
      // flag unless we are a number
      if (IsUnsigned)
      {
        switch (type)
        {
          case MySqlDbType.Byte:
            Type = MySqlDbType.UByte;
            return;
          case MySqlDbType.Int16:
            Type = MySqlDbType.UInt16;
            return;
          case MySqlDbType.Int24:
            Type = MySqlDbType.UInt24;
            return;
          case MySqlDbType.Int32:
            Type = MySqlDbType.UInt32;
            return;
          case MySqlDbType.Int64:
            Type = MySqlDbType.UInt64;
            return;
        }
      }

      if (IsBlob)
      {
        // handle blob to UTF8 conversion if requested.  This is only activated
        // on binary blobs
        if (IsBinary && driver.Settings.TreatBlobsAsUTF8)
        {
          bool convertBlob = false;
          Regex includeRegex = driver.Settings.GetBlobAsUTF8IncludeRegex();
          Regex excludeRegex = driver.Settings.GetBlobAsUTF8ExcludeRegex();
          if (includeRegex != null && includeRegex.IsMatch(ColumnName))
            convertBlob = true;
          else if (includeRegex == null && excludeRegex != null &&
            !excludeRegex.IsMatch(ColumnName))
            convertBlob = true;

          if (convertBlob)
          {
            binaryOk = false;
            Encoding = Encoding.GetEncoding("UTF-8");
            charSetIndex = -1;  // lets driver know we are in charge of encoding
            MaxLength = 4;
          }
        }

        if (!IsBinary)
        {
          if (type == MySqlDbType.TinyBlob)
            Type = MySqlDbType.TinyText;
          else if (type == MySqlDbType.MediumBlob)
            Type = MySqlDbType.MediumText;
          else if (type == MySqlDbType.Blob)
            Type = MySqlDbType.Text;
          else if (type == MySqlDbType.LongBlob)
            Type = MySqlDbType.LongText;
        }

        if (type == MySqlDbType.JSON)
        {
          binaryOk = false;
          Encoding = Encoding.GetEncoding("UTF-8");
          charSetIndex = -1;  // lets driver know we are in charge of encoding
          MaxLength = 4;
        }
      }

      // now determine if we really should be binary
      if (driver.Settings.RespectBinaryFlags)
        CheckForExceptions();

      if (Type == MySqlDbType.String && CharacterLength == 36 && !driver.Settings.OldGuids)
        Type = MySqlDbType.Guid;

      if (!IsBinary) return;

      if (driver.Settings.RespectBinaryFlags)
      {
        if (type == MySqlDbType.String)
          Type = MySqlDbType.Binary;
        else if (type == MySqlDbType.VarChar ||
             type == MySqlDbType.VarString)
          Type = MySqlDbType.VarBinary;
      }

      if (CharacterSetIndex == 63)
        CharacterSetIndex = driver.ConnectionCharSetIndex;

      if (Type == MySqlDbType.Binary && ColumnLength == 16 && driver.Settings.OldGuids)
        Type = MySqlDbType.Guid;
    }