Exemplo n.º 1
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
            }
        }
Exemplo n.º 2
0
        void RecvPacket_A(Action whenRecv)
        {
            _recvComplete = false;
            bool isFirstRecv = true;

            //before start recv
            _conn.StartReceive(result =>
            {
                if (result == null)
                {
                    throw new NotSupportedException();
                }
                else
                {
                    switch (result.Kind)
                    {
                    default: throw new NotSupportedException();    //unknown

                    case MySqlResultKind.Ok:
                        {
                            OkPacket = (result as MySqlOkResult).okpacket;
                            RecvComplete();
                        }
                        break;

                    case MySqlResultKind.Error:
                        {
                            MySqlErrorResult error = result as MySqlErrorResult;
                            Error = error.errPacket;
                            RecvComplete();
                            if (_errorListener != null)
                            {
                                _errorListener(error);
                            }
                            else
                            {
                                //ERROR
                                throw new MySqlExecException(error);
                            }
                        }
                        break;

                    case MySqlResultKind.PrepareResponse:
                        {
                            //The server will send a OK_Packet if the statement could be reset, a ERR_Packet if not.
                            //on prepare
                            MySqlPrepareResponseResult response = result as MySqlPrepareResponseResult;
                            _prepareContext = new PreparedContext(
                                response.okPacket.statement_id,
                                _sqlStrTemplate,
                                response.tableHeader);
                            RecvComplete();
                        }
                        break;

                    case MySqlResultKind.TableResult:
                        {
                            //support partial table mode
                            //last sub table is not partial table
                            //and must notify reader first***
                            //before call  RecvComplete();

                            //-----------------------------------------
                            MySqlTableResult tableResult = result as MySqlTableResult;
                            //***
                            _recvComplete = !tableResult.HasFollower;
                            //the _tableResultListener may modifid by other state (Close)
                            //if don't lock we need to store it to local var
                            _tableResultListener?.Invoke(tableResult);
                            //-----------------------------------------
                            if (!tableResult.HasFollower)
                            {
                                RecvComplete();
                            }
                        }
                        break;

                    case MySqlResultKind.MultiTableResult:
                        {
                            MySqlMultiTableResult multiTables = result as MySqlMultiTableResult;
                            List <MySqlTableResult> subTables = multiTables.subTables;
                            int j = subTables.Count;
                            for (int i = 0; i < j; ++i)
                            {
                                MySqlTableResult table = subTables[i];
                                if (i < j - 1)
                                {
                                    //not the last one
                                    //(the last one may complete or not complete)
                                    table.HasFollower = true;

                                    //the _tableResultListener may modifid by other state (Close)
                                    //if don't lock we need to store it to local var
                                    _tableResultListener?.Invoke(table);
                                }
                                else
                                {
                                    //this is the last one in the series
                                    //support partial table mode
                                    //last sub table is not partial table
                                    //and must notify reader first***
                                    //before call  RecvComplete();

                                    _recvComplete = !table.HasFollower;

                                    //the _tableResultListener may modifid by other state (Close)
                                    //if don't lock we need to store it to local var
                                    _tableResultListener?.Invoke(table);

                                    if (!table.HasFollower)
                                    {
                                        RecvComplete();
                                    }
                                }
                            }
                        }
                        break;
                    }
                }
                //-----------------
                //exec once
                if (isFirstRecv)
                {
                    isFirstRecv = false;
                    whenRecv();
                    whenRecv = null;
                }
                //-----------------
            });
        }
Exemplo n.º 3
0
 public void AddTableResult(MySqlTableResult table)
 {
     subTables.Add(table);
 }
 public void AddTableResult(MySqlTableResult table)
 {
     subTables.Add(table);
 }
 internal MySqlSubTable(MySqlTableResult tableResult)
 {
     this.tableResult = tableResult;
 }
        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
            }
        }