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); } }
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; } //------------------------------------------------------------- // 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; } }
MyStructData ReadCurrentRowBinaryProtocol(MySqlFieldDefinition f) { MySqlDataType fieldType = (MySqlDataType)f.FieldType; MyStructData myData = new MyStructData(); BufferReader r = this.bufferReader; switch (fieldType) { case MySqlDataType.TIMESTAMP: // case MySqlDataType.DATE: // case MySqlDataType.DATETIME: // case MySqlDataType.NEWDATE: // r.ReadLengthCodedDateTime(out myData.myDateTime); myData.type = fieldType; return(myData); case MySqlDataType.TINY: //length = 1; myData.myInt32 = r.U1(); myData.type = fieldType; return(myData); case MySqlDataType.SHORT: //length = 2; case MySqlDataType.YEAR: //length = 2; myData.myInt32 = (int)r.U2(); myData.type = fieldType; return(myData); case MySqlDataType.INT24: case MySqlDataType.LONG: //length = 4; myData.myInt32 = (int)r.U4(); myData.type = fieldType; return(myData); case MySqlDataType.FLOAT: myData.myDouble = r.ReadFloat(); myData.type = fieldType; return(myData); case MySqlDataType.DOUBLE: myData.myDouble = r.ReadDouble(); myData.type = fieldType; return(myData); case MySqlDataType.NEWDECIMAL: myData.myDecimal = r.ReadDecimal(); myData.type = fieldType; return(myData); case MySqlDataType.LONGLONG: myData.myInt64 = r.ReadInt64(); myData.type = fieldType; return(myData); case MySqlDataType.VARCHAR: myData.myString = r.ReadLengthCodedString(this.StringConverter); myData.type = fieldType; return(myData); case MySqlDataType.BIT: myData.myBuffer = r.ReadLengthCodedBuffer(); myData.type = fieldType; return(myData); 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) { myData.myBuffer = r.ReadLengthCodedBuffer(); } else { myData.myString = r.ReadLengthCodedString(this.StringConverter); } myData.type = fieldType; return(myData); case MySqlDataType.GEOMETRY: throw new NotSupportedException(); default: myData.myBuffer = r.ReadLengthCodedBuffer(); myData.type = MySqlDataType.NULL; return(myData); } }
MyStructData ReadCurrentRowBinaryProtocol(MySqlFieldDefinition f) { MySqlDataType fieldType = (MySqlDataType)f.FieldType; MyStructData myData = new MyStructData(); BufferReader r = this.bufferReader; switch (fieldType) { case MySqlDataType.TIMESTAMP:// case MySqlDataType.DATE:// case MySqlDataType.DATETIME:// case MySqlDataType.NEWDATE:// r.ReadLengthCodedDateTime(out myData.myDateTime); myData.type = fieldType; return myData; case MySqlDataType.TINY://length = 1; myData.myInt32 = r.U1(); myData.type = fieldType; return myData; case MySqlDataType.SHORT://length = 2; case MySqlDataType.YEAR://length = 2; myData.myInt32 = (int)r.U2(); myData.type = fieldType; return myData; case MySqlDataType.INT24: case MySqlDataType.LONG://length = 4; myData.myInt32 = (int)r.U4(); myData.type = fieldType; return myData; case MySqlDataType.FLOAT: myData.myDouble = r.ReadFloat(); myData.type = fieldType; return myData; case MySqlDataType.DOUBLE: myData.myDouble = r.ReadDouble(); myData.type = fieldType; return myData; case MySqlDataType.NEWDECIMAL: myData.myDecimal = r.ReadDecimal(); myData.type = fieldType; return myData; case MySqlDataType.LONGLONG: myData.myInt64 = r.ReadInt64(); myData.type = fieldType; return myData; case MySqlDataType.STRING: case MySqlDataType.VARCHAR: case MySqlDataType.VAR_STRING: myData.myString = r.ReadLengthCodedString(this.StringConverter); myData.type = fieldType; return myData; case MySqlDataType.TINY_BLOB: case MySqlDataType.MEDIUM_BLOB: case MySqlDataType.LONG_BLOB: case MySqlDataType.BLOB: case MySqlDataType.BIT: myData.myBuffer = r.ReadLengthCodedBuffer(); myData.type = fieldType; return myData; case MySqlDataType.GEOMETRY: throw new NotSupportedException(); default: myData.myBuffer = r.ReadLengthCodedBuffer(); myData.type = MySqlDataType.NULL; return myData; } }