Beispiel #1
0
        OkPrepareStmtPacket ParsePrepareResponse()
        {
            _receiveBuffer = new byte[DEFAULT_BUFFER_SIZE];
            var socket  = _conn.socket;
            int receive = socket.Receive(_receiveBuffer);

            if (receive == 0)
            {
                return(null);
            }
            //TODO: review err handling here
            //---------------------------------------------------
            _parser.LoadNewBuffer(_receiveBuffer, receive);
            OkPrepareStmtPacket okPreparePacket = new OkPrepareStmtPacket();

            switch (_receiveBuffer[4])
            {
            case ERROR_CODE:
                LoadError = new ErrPacket();
                LoadError.ParsePacket(_parser);
                okPreparePacket = null;
                break;

            case OK_CODE:
                okPreparePacket.ParsePacket(_parser);
                break;
            }
            return(okPreparePacket);
        }
Beispiel #2
0
        public void Prepare()
        {
            //prepare sql query
            _prepareContext = null;

            if (_cmdParams == null)
            {
                return;
            }

            _writer.Reset();

            string realSql = _sqlStrTemplate.BindValues(_cmdParams, true);
            ComPrepareStatementPacket preparePacket = new ComPrepareStatementPacket(realSql);

            preparePacket.WritePacket(_writer);
            SendPacket(_writer.ToArray());

            OkPrepareStmtPacket okPreparePacket = new OkPrepareStmtPacket();

            okPreparePacket = ParsePrepareResponse();
            if (okPreparePacket != null)
            {
                _prepareContext = new PreparedContext(okPreparePacket.statement_id, _sqlStrTemplate);

                if (okPreparePacket.num_params > 0)
                {
                    var tableHeader = new TableHeader();
                    tableHeader.TypeCast   = typeCast;
                    tableHeader.NestTables = nestTables;
                    tableHeader.ConnConfig = _conn.config;
                    for (int i = 0; i < okPreparePacket.num_params; i++)
                    {
                        //no meaing for each field?
                        FieldPacket field = ParseColumn();
                        tableHeader.AddField(field);
                    }

                    //set table after the table is ready!
                    _prepareContext.Setup(tableHeader);

                    ParseEOF();
                }
                if (okPreparePacket.num_columns > 0)
                {
                    _tableHeader            = new TableHeader();
                    _tableHeader.TypeCast   = typeCast;
                    _tableHeader.NestTables = nestTables;
                    _tableHeader.ConnConfig = _conn.config;

                    for (int i = 0; i < okPreparePacket.num_columns; i++)
                    {
                        FieldPacket field = ParseColumn();
                        _tableHeader.AddField(field);
                    }
                    ParseEOF();
                }
            }
        }
Beispiel #3
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);
        }
 public MySqlPrepareResponseResult(OkPrepareStmtPacket okPrepare, TableHeader tableHeader)
 {
     this.okPacket    = okPrepare;
     this.tableHeader = tableHeader;
 }
 public MySqlPrepareResponseResult(OkPrepareStmtPacket okPrepare, TableHeader tableHeader)
 {
     this.okPacket = okPrepare;
     this.tableHeader = tableHeader;
 }
 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;
 }