Exemplo n.º 1
0
 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);
 }
Exemplo n.º 2
0
 public override void Parse(MySqlStreamReader reader)
 {
     _finalResult = null;
     while (!StepParse(reader))
     {
         ;
     }
     //StepParse() return true if
     //1. need more data or
     //2. finish
 }
Exemplo n.º 3
0
        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
        }
Exemplo n.º 4
0
        //----------------------------------------------------
        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);
        }
Exemplo n.º 5
0
        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
        }
Exemplo n.º 6
0
        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
            }
        }
        public override void Parse(MySqlStreamReader reader)
        {
            //reset final result
            _parseResult = null;
            while (!StepParse(reader))
            {
                ;
            }
            //StepParse() return true if
            //1. need more data or
            //2. finish

            reader.ClearReadBuffer();

            if (_needMoreData)
            {
                //at any state if need more buffer
                //then stop parsing and return
                if (_supportPartialRelease)
                {
                    if (_rows != null && _rows.Count > 0)
                    {
                        _parseResult = new MySqlTableResult(_tableHeader, _rows.ToArray())
                        {
                            HasFollower = true
                        };
                    }
                    if (_generateResultMode)
                    {
                        //generate new result
#if DEBUG
                        if (_rows != null)
                        {
                        }
#endif
                        _rows.Clear();
                    }
                }
            }
            else if (_parsingState == ResultPacketState.ShouldEnd)
            {
                //reset
                reader.Reset();
                _parsingState = ResultPacketState.Header_Header;
            }
        }
 /// <summary>
 /// return true if not complete
 /// </summary>
 /// <param name="recvIO"></param>
 /// <returns></returns>
 public bool ParseData(RecvIO recvIO)
 {
     //we need to parse some data here
     //load incomming data into ms
     //load data from recv buffer into the ms
     //---------------
     //copy all to stream
     //may not complete in first round ***
     _mysqlStreamReader.AppendBuffer(recvIO, recvIO.BytesTransferred);
     _currentPacketParser.Parse(_mysqlStreamReader);
     //-----------------------------------------------
     //some large table may not complete in first round
     ParseResult = _currentPacketParser.ParseResult;
     return(!(_isCompleted = !_currentPacketParser.NeedMoreData));
     //--------------------
     //not need to wait here
     //just return ***
     //--------------------
 }
Exemplo n.º 9
0
        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);
        }
Exemplo n.º 10
0
        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);
            }
        }
Exemplo n.º 11
0
        void HandleReceive(RecvEventCode recvEventCode)
        {
            switch (recvEventCode)
            {
            default: throw new NotSupportedException();

            case RecvEventCode.SocketError:
            {
                UnBindSocket(true);
            }
            break;

            case RecvEventCode.NoMoreReceiveData:
            {
            }
            break;

            case RecvEventCode.HasSomeData:
            {
                //process some data
                //there some data to process
                //parse the data
#if DEBUG
                if (dbugPleaseBreak)
                {
                }
#endif

                bool needMoreData = _mysqlParserMx.ParseData(recvIO);
                //please note that: result packet may not ready in first round
                //but parser mx may 'release' some part of the result (eg. large table)
                MySqlResult result = _mysqlParserMx.ParseResult;         //'release' result
                //---------------------------------------------------------------
                if (result != null)
                {
                    //if we has some 'release' result from parser mx
                    if (needMoreData)
                    {
                        //this is 'partial result'
                        if (whenRecvData == null)
                        {
                            //?
                        }
                        //-------------------------
                        //partial release data here
                        //before recv next
                        //because we want to 'sync'
                        //the series of result
                        whenRecvData(result);
                        //-------------------------
                    }
                    else
                    {
                        //when recv complete***
                        Action <MySqlResult> tmpWhenRecvData = whenRecvData;
                        //delete recv handle **before** invoke it, and
                        //reset state to 'rest' state
                        this.whenRecvData  = null;
                        this._workingState = WorkingState.Rest;
                        tmpWhenRecvData(result);
                    }
                }
                //--------------------------
                if (needMoreData)
                {
                    //so if it need more data then start receive next
                    recvIO.StartReceive();        //***
                }
                else
                {
                }
                //--------------------------
            }
            break;
            }
        }
        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_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
 }
 public override void Parse(MySqlStreamReader reader)
 {
     //reset final result 
     _parseResult = null;
     while (!StepParse(reader)) ;
     //StepParse() return true if 
     //1. need more data or
     //2. finish
     if (_needMoreData)
     {
         //at any state if need more buffer 
         //then stop parsing and return 
         if (_supportPartialRelease)
         {
             if (_rows != null && _rows.Count > 0)
             {
                 _parseResult = new MySqlTableResult(_tableHeader, _rows) { HasFollower = true };
             }
             if (_generateResultMode)
             {
                 //generate new result
                 _rows = new List<DataRowPacket>();
             }
         }
     }
     else if (_parsingState == ResultPacketState.ShouldEnd)
     {
         //reset
         reader.Reset();
         _parsingState = ResultPacketState.Header_Header;
     }
 }
 public override void Parse(MySqlStreamReader reader)
 {
     _finalResult = null;
     while (!StepParse(reader)) ;
     //StepParse() return true if 
     //1. need more data or
     //2. finish
 }
 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_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 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_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
        }