View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package org.apache.shardingsphere.db.protocol.mysql.packet.command.query.binary.prepare;
19  
20  import lombok.RequiredArgsConstructor;
21  import org.apache.shardingsphere.db.protocol.mysql.packet.MySQLPacket;
22  import org.apache.shardingsphere.db.protocol.mysql.payload.MySQLPacketPayload;
23  
24  /**
25   * COM_STMT_PREPARE_OK packet for MySQL.
26   * 
27   * @see <a href="https://dev.mysql.com/doc/dev/mysql-server/latest/page_protocol_com_stmt_prepare.html#sect_protocol_com_stmt_prepare_response_ok">COM_STMT_PREPARE_OK</a>
28   */
29  @RequiredArgsConstructor
30  public final class MySQLComStmtPrepareOKPacket extends MySQLPacket {
31      
32      private static final int STATUS = 0x00;
33      
34      private final int statementId;
35      
36      private final int columnCount;
37      
38      private final int parameterCount;
39      
40      private final int warningCount;
41      
42      @Override
43      protected void write(final MySQLPacketPayload payload) {
44          payload.writeInt1(STATUS);
45          payload.writeInt4(statementId);
46          // TODO Column Definition Block should be added in future when the meta data of the columns is cached.
47          payload.writeInt2(columnCount);
48          payload.writeInt2(parameterCount);
49          payload.writeReserved(1);
50          payload.writeInt2(warningCount);
51      }
52  }