bool Parse_Field_Content(MySqlStreamReader reader) { if (!reader.Ensure(_currentHeader.ContentLength)) //check if length is enough to parse { #if DEBUG reader.dbugMonitorData1 = true; #endif return(_needMoreData = true); } var fieldPacket = new FieldPacket(_currentHeader, this._isProtocol41); fieldPacket.ParsePacketContent(reader); fieldPacket.FieldIndex = _tableHeader.ColumnCount; //set this before add to field list _tableHeader.AddField(fieldPacket); #if DEBUG //TODO:review here if (fieldPacket.dbugFailure) { throw new NotSupportedException(); } #endif //next state => field header of next field _parsingState = ResultPacketState.Field_Header; return(false); }
bool Parse_Field_Header(MySqlStreamReader reader) { if (!reader.Ensure(PACKET_HEADER_LENGTH + 1)) //check if length is enough to parse { return(_needMoreData = true); } _currentHeader = reader.ReadPacketHeader(); byte packetType = reader.PeekByte(); switch (packetType) { case ERROR_CODE: _parsingState = ResultPacketState.Error_Content; break; case EOF_CODE: case OK_CODE: _parsingState = ResultPacketState.Field_EOF; break; default: //next state => field content of this field _parsingState = ResultPacketState.Field_Content; break; } return(false); }
bool Parse_PrepareOk_Header(MySqlStreamReader reader) { //this is first step *** if (!reader.Ensure(PACKET_HEADER_LENGTH + 1)) { return(_needMoreData = true); } _currentHeader = reader.ReadPacketHeader(); byte type = reader.PeekByte(); switch (type) { case ERROR_CODE: _parsingState = PrepareResponseParseState.Error_Content; break; case EOF_CODE: case OK_CODE: _parsingState = PrepareResponseParseState.OkPrepare_Content; break; default: throw new NotSupportedException("Packet type don't match!!"); } return(false); }
//---------------------------------------------------- bool Parse_ColumnField_Header(MySqlStreamReader reader) { if (!reader.Ensure(PACKET_HEADER_LENGTH + 1)) { return(_needMoreData = true); } _currentHeader = reader.ReadPacketHeader(); byte type = reader.PeekByte();//1 switch (type) { case ERROR_CODE: _parsingState = PrepareResponseParseState.Error_Content; break; case EOF_CODE: //? _parsingState = PrepareResponseParseState.ColumnField_EOF; break; default: _parsingState = PrepareResponseParseState.ColumnField_Content; break; } return(false); }
bool Parse_Ok_Content(MySqlStreamReader reader) { if (!reader.Ensure(_currentHeader.ContentLength)) //check if length is enough to parse { return(_needMoreData = true); } if (this._currentMultResultSet != null) { //in multiple result set mode *** //see https://dev.mysql.com/doc/internals/en/multi-resultset.html // var okPacket = new OkPacket(_currentHeader, this._isProtocol41); okPacket.ParsePacketContent(reader); _parseResult = _currentMultResultSet; _parsingState = ResultPacketState.ShouldEnd; //* // _currentMultResultSet = null; //reset } else { var okPacket = new OkPacket(_currentHeader, this._isProtocol41); okPacket.ParsePacketContent(reader); _parseResult = new MySqlOkResult(okPacket); _parsingState = ResultPacketState.ShouldEnd; //* } return(true); }
bool Parse_Field_EOF(MySqlStreamReader reader) { if (!reader.Ensure(_currentHeader.ContentLength)) //check if length is enough to parse { return(_needMoreData = true); } var eofPacket = new EofPacket(_currentHeader, this._isProtocol41); eofPacket.ParsePacketContent(reader); _parsingState = ResultPacketState.Row_Header; return(false); }
bool Parse_Error_Content(MySqlStreamReader reader) { if (!reader.Ensure(_currentHeader.ContentLength)) //check if length is enough to parse { return(_needMoreData = true); } var errPacket = new ErrPacket(_currentHeader); errPacket.ParsePacketContent(reader); //------------------------ _parseResult = new MySqlErrorResult(errPacket); _parsingState = ResultPacketState.ShouldEnd; return(true);//finished }
bool Parse_ColumnField_Content(MySqlStreamReader reader) { if (!reader.Ensure(_currentHeader.ContentLength)) { return(_needMoreData = true); } var field = new FieldPacket(_currentHeader, _isProtocol41); field.ParsePacketContent(reader); field.FieldIndex = _tableHeader.ColumnCount; //set this before add to field list _tableHeader.AddField(field); //back to field header _parsingState = PrepareResponseParseState.ColumnField_Header; return(false); }
//---------------------------------------------------- bool ParseErrorPacket(MySqlStreamReader reader) { if (!reader.Ensure(_currentHeader.ContentLength)) { return(_needMoreData = true); } var errPacket = new ErrPacket(_currentHeader); errPacket.ParsePacketContent(reader); // _finalResult = new MySqlErrorResult(errPacket); _parsingState = PrepareResponseParseState.ShouldEnd; reader.Reset(); return(true); }
/// <summary> /// parse header part of the result set /// </summary> bool Parse_Header_Content(MySqlStreamReader reader) { if (!reader.Ensure(_currentHeader.ContentLength)) { return(_needMoreData = true); } //can parse var resultSetHeaderPacket = new ResultSetHeaderPacket(_currentHeader); resultSetHeaderPacket.ParsePacketContent(reader); _tableHeader = new TableHeader(this.ForPrepareResult); _parsingState = ResultPacketState.Field_Header; _rows = new List <DataRowPacket>(); return(false); }
bool Parse_ColumnField_EOF(MySqlStreamReader reader) { if (!reader.Ensure(_currentHeader.ContentLength)) { return(_needMoreData = true); } var eofPacket = new EofPacket(_currentHeader, this._isProtocol41); eofPacket.ParsePacketContent(reader); // _finalResult = new MySqlPrepareResponseResult(_okPrepare, _tableHeader); _parsingState = PrepareResponseParseState.ShouldEnd; reader.Reset(); return(true);//finish }
bool Parse_Row_EOF(MySqlStreamReader reader) { if (!reader.Ensure(_currentHeader.ContentLength)) //check if length is enough to parse { return(_needMoreData = true); } //finish all of each row var eofPacket = new EofPacket(_currentHeader, this._isProtocol41); eofPacket.ParsePacketContent(reader); if (((eofPacket.serverStatus & (int)MySqlServerStatus.SERVER_MORE_RESULTS_EXISTS)) != 0) { var tableResult = new MySqlTableResult(_tableHeader, _rows); _rows = null;//reset //more than one result table //mu if (_currentMultResultSet != null) { _currentMultResultSet.AddTableResult(tableResult); } else { //first time _currentMultResultSet = new MySqlMultiTableResult(); _currentMultResultSet.AddTableResult(tableResult);; //not set _parseResult*** because this not finish } //-------------------- //see: https://dev.mysql.com/doc/internals/en/multi-resultset.html //may has more than 1 result _parsingState = ResultPacketState.Header_Header; return(false); } else { //after finish we create a result table //the move rows into the table _parseResult = new MySqlTableResult(_tableHeader, _rows); //not link to the rows anymore _rows = null; _currentMultResultSet = null; _parsingState = ResultPacketState.ShouldEnd; //*** return(true); //end } }
bool Parse_Row_Header(MySqlStreamReader reader) { if (!reader.Ensure(PACKET_HEADER_LENGTH + 1)) { return(_needMoreData = true); } _currentHeader = reader.ReadPacketHeader(); if (_currentHeader.ContentLength == Packet.MAX_PACKET_LENGTH) { //need more than 1 packet for row content _needMoreThan1Packet = true; _parsingState = ResultPacketState.Row_Content; return(false); } else if (_currentHeader.ContentLength > Packet.MAX_PACKET_LENGTH) { throw new NotSupportedException("???"); } if (_needMoreThan1Packet) { //switch to row content _parsingState = ResultPacketState.Row_Content; } else { byte packetType = reader.PeekByte(); switch (packetType) { case ERROR_CODE: _parsingState = ResultPacketState.Error_Content; break; case EOF_CODE: //0x00 or 0xfe the OK packet header _parsingState = ResultPacketState.Row_EOF; break; default: _parsingState = ResultPacketState.Row_Content; break; } } return(false); }
bool Parse_PrepareOk_Content(MySqlStreamReader reader) { if (!reader.Ensure(_currentHeader.ContentLength)) { return(_needMoreData = true); } var okPrepare = new OkPrepareStmtPacket(_currentHeader); okPrepare.ParsePacketContent(reader); _okPrepare = okPrepare; //---------------------------------------------------- _tableHeader = new TableHeader(true); //---------------------------------------------------- //*** 3 possible way after read prepare ok header*** if (okPrepare.num_params == 0) { //if prepare stmt dosn't have binding parameters if (okPrepare.num_columns > 0) { //has some column _parsingState = PrepareResponseParseState.ColumnField_Header; } else { _finalResult = new MySqlPrepareResponseResult(okPrepare, _tableHeader); _parsingState = PrepareResponseParseState.ShouldEnd; reader.Reset(); return(true); //finish } } else { _parsingState = PrepareResponseParseState.BindingField_Header; } return(false); }
bool Parse_BindingField_EOF(MySqlStreamReader reader) { if (!reader.Ensure(_currentHeader.ContentLength)) { return(_needMoreData = true); } var eofPacket = new EofPacket(_currentHeader, _isProtocol41); eofPacket.ParsePacketContent(reader); if (_okPrepare.num_columns > 0) { _parsingState = PrepareResponseParseState.ColumnField_Header; return(false); } else { _finalResult = new MySqlPrepareResponseResult(_okPrepare, _tableHeader); _parsingState = PrepareResponseParseState.ShouldEnd; reader.Reset(); return(true); } }
bool Parse_Field_Content(MySqlStreamReader reader) { if (!reader.Ensure(_currentHeader.ContentLength)) //check if length is enough to parse { #if DEBUG reader.dbugMonitorData1 = true; #endif return _needMoreData = true; } var fieldPacket = new FieldPacket(_currentHeader, this._isProtocol41); fieldPacket.ParsePacketContent(reader); fieldPacket.FieldIndex = _tableHeader.ColumnCount; //set this before add to field list _tableHeader.AddField(fieldPacket); #if DEBUG //TODO:review here if (fieldPacket.dbugFailure) { throw new NotSupportedException(); } #endif //next state => field header of next field _parsingState = ResultPacketState.Field_Header; return false; }
bool Parse_Field_EOF(MySqlStreamReader reader) { if (!reader.Ensure(_currentHeader.ContentLength)) //check if length is enough to parse { return _needMoreData = true; } var eofPacket = new EofPacket(_currentHeader, this._isProtocol41); eofPacket.ParsePacketContent(reader); _parsingState = ResultPacketState.Row_Header; return false; }
bool Parse_Row_Header(MySqlStreamReader reader) { if (!reader.Ensure(PACKET_HEADER_LENGTH + 1)) { return _needMoreData = true; } _currentHeader = reader.ReadPacketHeader(); if (_currentHeader.ContentLength == Packet.MAX_PACKET_LENGTH) { //need more than 1 packet for row content _parsingState = ResultPacketState.Row_Content; return false; } else if (_currentHeader.ContentLength > Packet.MAX_PACKET_LENGTH) { throw new NotSupportedException("???"); } byte packetType = reader.PeekByte(); switch (packetType) { case ERROR_CODE: _parsingState = ResultPacketState.Error_Content; break; case EOF_CODE://0x00 or 0xfe the OK packet header _parsingState = ResultPacketState.Row_EOF; break; default: _parsingState = ResultPacketState.Row_Content; break; } return false; }
bool Parse_Row_Content(MySqlStreamReader reader) { if (!reader.Ensure(_currentHeader.ContentLength)) { return _needMoreData = true; } if (_currentHeader.ContentLength > Packet.MAX_PACKET_LENGTH) { throw new NotSupportedException("???"); } else if (_currentHeader.ContentLength >= Packet.MAX_PACKET_LENGTH) { //can't complete in this round //so store data into temp extra large buffer //and set isLargeData= true StoreBuffer(reader, (int)_currentHeader.ContentLength); isLargeData = true; //we still in the row content state _parsingState = ResultPacketState.Row_Header; return false; } //-------------------------------- if (_generateResultMode) { //this is normal mode (opposite to JustFlushOutMode) //in this mode we parse packet content //and add it to the output rows //---------------------------------- //in this version row buffer len must < int.MaxLength if (_currentHeader.ContentLength > int.MaxValue) { throw new NotSupportedException("not support this length"); } //------------------------------------ if (isLargeData) { if (ms == null) { //it should not be null here throw new NotSupportedException();//? } ms.Write(reader.ReadBuffer((int)_currentHeader.ContentLength), 0, (int)_currentHeader.ContentLength); _rows.Add(new DataRowPacket(_currentHeader, ms.ToArray())); ms.Close(); ms.Dispose(); ms = null; isLargeData = false; //reset } else { _rows.Add(new DataRowPacket(_currentHeader, reader.ReadBuffer((int)_currentHeader.ContentLength))); } } else { //just flush data*** //not create data row if (_currentHeader.ContentLength > int.MaxValue) { throw new Exception("not support content length> int.MaxValue"); } reader.SkipForward((int)_currentHeader.ContentLength); } //----------------------------------------------------------------------- //after this row, next state = next row header _parsingState = ResultPacketState.Row_Header; return false; }
bool Parse_Row_EOF(MySqlStreamReader reader) { if (!reader.Ensure(_currentHeader.ContentLength)) //check if length is enough to parse { return _needMoreData = true; } //finish all of each row var eofPacket = new EofPacket(_currentHeader, this._isProtocol41); eofPacket.ParsePacketContent(reader); if (((eofPacket.serverStatus & (int)MySqlServerStatus.SERVER_MORE_RESULTS_EXISTS)) != 0) { var tableResult = new MySqlTableResult(_tableHeader, _rows); _rows = null;//reset //more than one result table //mu if (_currentMultResultSet != null) { _currentMultResultSet.AddTableResult(tableResult); } else { //first time _currentMultResultSet = new MySqlMultiTableResult(); _currentMultResultSet.AddTableResult(tableResult); ; //not set _parseResult*** because this not finish } //-------------------- //see: https://dev.mysql.com/doc/internals/en/multi-resultset.html //may has more than 1 result _parsingState = ResultPacketState.Header_Header; return false; } else { //after finish we create a result table //the move rows into the table _parseResult = new MySqlTableResult(_tableHeader, _rows); //not link to the rows anymore _rows = null; _currentMultResultSet = null; _parsingState = ResultPacketState.ShouldEnd;//*** return true;//end } }
//---------------------------------------------------- bool ParseErrorPacket(MySqlStreamReader reader) { if (!reader.Ensure(_currentHeader.ContentLength)) { return _needMoreData = true; } var errPacket = new ErrPacket(_currentHeader); errPacket.ParsePacketContent(reader); // _finalResult = new MySqlErrorResult(errPacket); _parsingState = PrepareResponseParseState.ShouldEnd; reader.Reset(); return true; }
bool Parse_Error_Content(MySqlStreamReader reader) { if (!reader.Ensure(_currentHeader.ContentLength)) //check if length is enough to parse { return _needMoreData = true; } var errPacket = new ErrPacket(_currentHeader); errPacket.ParsePacketContent(reader); //------------------------ _parseResult = new MySqlErrorResult(errPacket); _parsingState = ResultPacketState.ShouldEnd; return true;//finished }
bool Parse_PrepareOk_Header(MySqlStreamReader reader) { //this is first step *** if (!reader.Ensure(PACKET_HEADER_LENGTH + 1)) { return _needMoreData = true; } _currentHeader = reader.ReadPacketHeader(); byte type = reader.PeekByte(); switch (type) { case ERROR_CODE: _parsingState = PrepareResponseParseState.Error_Content; break; case EOF_CODE: case OK_CODE: _parsingState = PrepareResponseParseState.OkPrepare_Content; break; default: throw new NotSupportedException("Packet type don't match!!"); } return false; }
bool Parse_PrepareOk_Content(MySqlStreamReader reader) { if (!reader.Ensure(_currentHeader.ContentLength)) { return _needMoreData = true; } var okPrepare = new OkPrepareStmtPacket(_currentHeader); okPrepare.ParsePacketContent(reader); _okPrepare = okPrepare; //---------------------------------------------------- _tableHeader = new TableHeader(true); //---------------------------------------------------- //*** 3 possible way after read prepare ok header*** if (okPrepare.num_params == 0) { //if prepare stmt dosn't have binding parameters if (okPrepare.num_columns > 0) { //has some column _parsingState = PrepareResponseParseState.ColumnField_Header; } else { _finalResult = new MySqlPrepareResponseResult(okPrepare, _tableHeader); _parsingState = PrepareResponseParseState.ShouldEnd; reader.Reset(); return true; //finish } } else { _parsingState = PrepareResponseParseState.BindingField_Header; } return false; }
//---------------------------------------------------- bool Parse_ColumnField_Header(MySqlStreamReader reader) { if (!reader.Ensure(PACKET_HEADER_LENGTH + 1)) { return _needMoreData = true; } _currentHeader = reader.ReadPacketHeader(); byte type = reader.PeekByte();//1 switch (type) { case ERROR_CODE: _parsingState = PrepareResponseParseState.Error_Content; break; case EOF_CODE: //? _parsingState = PrepareResponseParseState.ColumnField_EOF; break; default: _parsingState = PrepareResponseParseState.ColumnField_Content; break; } return false; }
bool Parse_ColumnField_Content(MySqlStreamReader reader) { if (!reader.Ensure(_currentHeader.ContentLength)) { return _needMoreData = true; } var field = new FieldPacket(_currentHeader, _isProtocol41); field.ParsePacketContent(reader); field.FieldIndex = _tableHeader.ColumnCount; //set this before add to field list _tableHeader.AddField(field); //back to field header _parsingState = PrepareResponseParseState.ColumnField_Header; return false; }
/// <summary> /// parse header part of the result set /// </summary> bool Parse_Header_Content(MySqlStreamReader reader) { if (!reader.Ensure(_currentHeader.ContentLength)) { return _needMoreData = true; } //can parse var resultSetHeaderPacket = new ResultSetHeaderPacket(_currentHeader); resultSetHeaderPacket.ParsePacketContent(reader); _tableHeader = new TableHeader(this.ForPrepareResult); _parsingState = ResultPacketState.Field_Header; _rows = new List<DataRowPacket>(); return false; }
bool Parse_Field_Header(MySqlStreamReader reader) { if (!reader.Ensure(PACKET_HEADER_LENGTH + 1)) //check if length is enough to parse { return _needMoreData = true; } _currentHeader = reader.ReadPacketHeader(); byte packetType = reader.PeekByte(); switch (packetType) { case ERROR_CODE: _parsingState = ResultPacketState.Error_Content; break; case EOF_CODE: case OK_CODE: _parsingState = ResultPacketState.Field_EOF; break; default: //next state => field content of this field _parsingState = ResultPacketState.Field_Content; break; } return false; }
bool Parse_Row_Content(MySqlStreamReader reader) { if (!reader.Ensure(_currentHeader.ContentLength)) { return(_needMoreData = true); } if (_currentHeader.ContentLength > Packet.MAX_PACKET_LENGTH) { throw new NotSupportedException("???"); } else if (_currentHeader.ContentLength >= Packet.MAX_PACKET_LENGTH) { //can't complete in this round //so store data into temp extra large buffer //and set isLargeData= true StoreBuffer(reader, (int)_currentHeader.ContentLength); isLargeData = true; //we still in the row content state _parsingState = ResultPacketState.Row_Header; return(false); } //-------------------------------- if (_generateResultMode) { //this is normal mode (opposite to JustFlushOutMode) //in this mode we parse packet content //and add it to the output rows //---------------------------------- //in this version row buffer len must < int.MaxLength if (_currentHeader.ContentLength > int.MaxValue) { throw new NotSupportedException("not support this length"); } //------------------------------------ if (isLargeData) { if (ms == null) { //it should not be null here throw new NotSupportedException(); //? } ms.Write(reader.ReadBuffer((int)_currentHeader.ContentLength), 0, (int)_currentHeader.ContentLength); _rows.Add(new DataRowPacket(_currentHeader, ms.ToArray())); #if NET20 ms.Close(); #endif ms.Dispose(); ms = null; isLargeData = false; //reset } else { _rows.Add(new DataRowPacket(_currentHeader, reader.ReadBuffer((int)_currentHeader.ContentLength))); } } else { //just flush data*** //not create data row if (_currentHeader.ContentLength > int.MaxValue) { throw new Exception("not support content length> int.MaxValue"); } reader.SkipForward((int)_currentHeader.ContentLength); } //----------------------------------------------------------------------- //after this row, next state = next row header _parsingState = ResultPacketState.Row_Header; return(false); }
bool Parse_Ok_Content(MySqlStreamReader reader) { if (!reader.Ensure(_currentHeader.ContentLength)) //check if length is enough to parse { return _needMoreData = true; } if (this._currentMultResultSet != null) { //in multiple result set mode *** //see https://dev.mysql.com/doc/internals/en/multi-resultset.html // var okPacket = new OkPacket(_currentHeader, this._isProtocol41); okPacket.ParsePacketContent(reader); _parseResult = _currentMultResultSet; _parsingState = ResultPacketState.ShouldEnd; //* // _currentMultResultSet = null;//reset } else { var okPacket = new OkPacket(_currentHeader, this._isProtocol41); okPacket.ParsePacketContent(reader); _parseResult = new MySqlOkResult(okPacket); _parsingState = ResultPacketState.ShouldEnd; //* } return true; }
bool Parse_ColumnField_EOF(MySqlStreamReader reader) { if (!reader.Ensure(_currentHeader.ContentLength)) { return _needMoreData = true; } var eofPacket = new EofPacket(_currentHeader, this._isProtocol41); eofPacket.ParsePacketContent(reader); // _finalResult = new MySqlPrepareResponseResult(_okPrepare, _tableHeader); _parsingState = PrepareResponseParseState.ShouldEnd; reader.Reset(); return true;//finish }