Пример #1
0
 static MySqlDataReader()
 {
     s_defaultConf = new QueryParsingConfig();
     //{
     //    TimeZone = userConfig.timezone,
     //    UseLocalTimeZone = userConfig.timezone.Equals("local"),
     //    BigNumberStrings = userConfig.bigNumberStrings,
     //    DateStrings = userConfig.dateStrings,
     //    SupportBigNumbers = userConfig.supportBigNumbers
     //};
 }
Пример #2
0
        MyStructData ReadCurrentRowTextProtocol(MySqlFieldDefinition f)
        {
            BufferReader  r            = this.bufferReader;
            MyStructData  data         = new MyStructData();
            MySqlDataType type         = (MySqlDataType)f.FieldType;
            string        numberString = null;

            switch (type)
            {
            case MySqlDataType.TIMESTAMP:
            case MySqlDataType.DATE:
            case MySqlDataType.DATETIME:
            case MySqlDataType.NEWDATE:
            {
                QueryParsingConfig qparsingConfig = _queryParsingConf;
                tmpStringBuilder.Length = 0;        //clear
                data.myString           = r.ReadLengthCodedString(this.StringConverter);
                data.type = type;
                if (data.myString == null)
                {
                    data.type = MySqlDataType.NULL;
                    return(data);
                }
                if (qparsingConfig.DateStrings)
                {
                    return(data);
                }
                if (data.myString == "0000-00-00")
                {
                    data.myDateTime = DateTime.MinValue;        //?
                    data.type       = type;
                    return(data);
                }
                //-------------------------------------------------------------
                //    var originalString = dateString;
                //    if (field.type === Types.DATE) {
                //      dateString += ' 00:00:00';
                //    }
                tmpStringBuilder.Append(data.myString);
                //string originalString = dateString;
                if (type == MySqlDataType.DATE)
                {
                    tmpStringBuilder.Append(" 00:00:00");
                }
                //    if (timeZone !== 'local') {
                //      dateString += ' ' + timeZone;
                //    }

                if (!qparsingConfig.UseLocalTimeZone)
                {
                    tmpStringBuilder.Append(' ' + qparsingConfig.TimeZone);
                }
                //var dt;
                //    dt = new Date(dateString);
                //    if (isNaN(dt.getTime())) {
                //      return originalString;
                //    }

                data.myDateTime = DateTime.Parse(tmpStringBuilder.ToString(),
                                                 System.Globalization.CultureInfo.InvariantCulture);
                data.type = type;
                tmpStringBuilder.Length = 0;        //clear
            }
                return(data);

            case MySqlDataType.TINY:
            case MySqlDataType.SHORT:
            case MySqlDataType.LONG:
            case MySqlDataType.INT24:
            case MySqlDataType.YEAR:

                //TODO: review here,
                data.myString = numberString = r.ReadLengthCodedString(this.StringConverter);
                if (numberString == null ||
                    (f.IsZeroFill && numberString[0] == '0') ||
                    numberString.Length == 0)
                {
                    data.type = MySqlDataType.NULL;
                }
                else
                {
                    data.myInt32 = Convert.ToInt32(numberString);
                    data.type    = type;
                }
                return(data);

            case MySqlDataType.FLOAT:
            case MySqlDataType.DOUBLE:
                data.myString = numberString = r.ReadLengthCodedString(this.StringConverter);
                if (numberString == null || (f.IsZeroFill && numberString[0] == '0'))
                {
                    data.type = MySqlDataType.NULL;
                }
                else
                {
                    data.myDouble = Convert.ToDouble(numberString);
                    data.type     = type;
                }
                return(data);

            //    return (numberString === null || (field.zeroFill && numberString[0] == "0"))
            //      ? numberString : Number(numberString);
            case MySqlDataType.NEWDECIMAL:
            case MySqlDataType.LONGLONG:
                //    numberString = parser.parseLengthCodedString();
                //    return (numberString === null || (field.zeroFill && numberString[0] == "0"))
                //      ? numberString
                //      : ((supportBigNumbers && (bigNumberStrings || (Number(numberString) > IEEE_754_BINARY_64_PRECISION)))
                //        ? numberString
                //        : Number(numberString));

                QueryParsingConfig config = _queryParsingConf;
                data.myString = numberString = r.ReadLengthCodedString(this.StringConverter);
                if (numberString == null || (f.IsZeroFill && numberString[0] == '0'))
                {
                    data.type = MySqlDataType.NULL;
                }
                else if (config.SupportBigNumbers &&
                         (config.BigNumberStrings || (Convert.ToInt64(numberString) > Packet.IEEE_754_BINARY_64_PRECISION)))
                {
                    //store as string ?
                    //TODO: review here  again
                    data.myString = numberString;
                    data.type     = type;
                    throw new NotSupportedException();
                }
                else if (type == MySqlDataType.LONGLONG)
                {
                    data.myInt64 = Convert.ToInt64(numberString);
                    data.type    = type;
                }
                else    //decimal
                {
                    data.myDecimal = Convert.ToDecimal(numberString);
                    data.type      = type;
                }
                return(data);

            case MySqlDataType.BIT:

                data.myBuffer = r.ReadLengthCodedBuffer();
                data.type     = type;
                return(data);

            //    return parser.parseLengthCodedBuffer();
            case MySqlDataType.STRING:
            case MySqlDataType.VAR_STRING:

            case MySqlDataType.TINY_BLOB:
            case MySqlDataType.MEDIUM_BLOB:
            case MySqlDataType.LONG_BLOB:
            case MySqlDataType.BLOB:
                if (f.MarkedAsBinary)
                {
                    data.myBuffer = r.ReadLengthCodedBuffer();
                    data.type     = (data.myBuffer != null) ? type : MySqlDataType.NULL;
                }
                else
                {
                    data.myString = r.ReadLengthCodedString(this.StringConverter);
                    data.type     = (data.myString != null) ? type : MySqlDataType.NULL;
                }
                return(data);

            //    return (field.charsetNr === Charsets.BINARY)
            //      ? parser.parseLengthCodedBuffer()
            //      : parser.parseLengthCodedString();
            case MySqlDataType.GEOMETRY:
                //TODO: unfinished
                data.type = MySqlDataType.GEOMETRY;
                return(data);

            default:
                data.myString = r.ReadLengthCodedString(this.StringConverter);
                data.type     = type;
                return(data);
            }
        }
 static MySqlDataReader()
 {
     s_defaultConf = new QueryParsingConfig();
     //{
     //    TimeZone = userConfig.timezone,
     //    UseLocalTimeZone = userConfig.timezone.Equals("local"),
     //    BigNumberStrings = userConfig.bigNumberStrings,
     //    DateStrings = userConfig.dateStrings,
     //    SupportBigNumbers = userConfig.supportBigNumbers
     //};
 }