https://dev.mysql.com/doc/dev/mysql-server/latest/page_protocol_com_stmt_send_long_data.html
(paramID int, arg []byte)
| 996 | |
| 997 | // https://dev.mysql.com/doc/dev/mysql-server/latest/page_protocol_com_stmt_send_long_data.html |
| 998 | func (stmt *mysqlStmt) writeCommandLongData(paramID int, arg []byte) error { |
| 999 | maxLen := stmt.mc.maxAllowedPacket - 1 |
| 1000 | pktLen := maxLen |
| 1001 | |
| 1002 | // After the header (bytes 0-3) follows before the data: |
| 1003 | // 1 byte command |
| 1004 | // 4 bytes stmtID |
| 1005 | // 2 bytes paramID |
| 1006 | const dataOffset = 1 + 4 + 2 |
| 1007 | |
| 1008 | // Cannot use the write buffer since |
| 1009 | // a) the buffer is too small |
| 1010 | // b) it is in use |
| 1011 | data := make([]byte, 4+1+4+2+len(arg)) |
| 1012 | |
| 1013 | copy(data[4+dataOffset:], arg) |
| 1014 | |
| 1015 | for argLen := len(arg); argLen > 0; argLen -= pktLen - dataOffset { |
| 1016 | if dataOffset+argLen < maxLen { |
| 1017 | pktLen = dataOffset + argLen |
| 1018 | } |
| 1019 | |
| 1020 | // Add command byte [1 byte] |
| 1021 | data[4] = comStmtSendLongData |
| 1022 | |
| 1023 | // Add stmtID [32 bit] |
| 1024 | binary.LittleEndian.PutUint32(data[5:], stmt.id) |
| 1025 | |
| 1026 | // Add paramID [16 bit] |
| 1027 | binary.LittleEndian.PutUint16(data[9:], uint16(paramID)) |
| 1028 | |
| 1029 | // Send CMD packet |
| 1030 | err := stmt.mc.writePacket(data[:4+pktLen]) |
| 1031 | // Every COM_LONG_DATA packet reset Packet Sequence |
| 1032 | stmt.mc.resetSequence() |
| 1033 | if err == nil { |
| 1034 | data = data[pktLen-dataOffset:] |
| 1035 | continue |
| 1036 | } |
| 1037 | return err |
| 1038 | } |
| 1039 | |
| 1040 | return nil |
| 1041 | } |
| 1042 | |
| 1043 | // Execute Prepared Statement |
| 1044 | // https://dev.mysql.com/doc/dev/mysql-server/latest/page_protocol_com_stmt_execute.html |
no test coverage detected