-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Fix prepared statement #734
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
julienschmidt
merged 5 commits into
go-sql-driver:master
from
methane:fix-zerobyte-longdata
Jan 13, 2018
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
40352b0
Fix prepared statement
methane 2954ddc
Change minimum size of LONG_DATA to 64byte
methane 475ca26
Add test which reproduce issue 730
methane 2661e90
TestPreparedManyCols test only numParams = 65535 case
methane d08f145
s/as possible//
methane File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -912,6 +912,12 @@ func (stmt *mysqlStmt) writeExecutePacket(args []driver.Value) error { | |
const minPktLen = 4 + 1 + 4 + 1 + 4 | ||
mc := stmt.mc | ||
|
||
// Determine threshould dynamically to avoid packet size shortage as possible. | ||
longDataSize := mc.maxAllowedPacket / (stmt.paramCount + 1) | ||
if longDataSize < 64 { | ||
longDataSize = 64 | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe, 16byte is too short? |
||
|
||
// Reset packet-sequence | ||
mc.sequence = 0 | ||
|
||
|
@@ -1039,7 +1045,7 @@ func (stmt *mysqlStmt) writeExecutePacket(args []driver.Value) error { | |
paramTypes[i+i] = byte(fieldTypeString) | ||
paramTypes[i+i+1] = 0x00 | ||
|
||
if len(v) < mc.maxAllowedPacket-pos-len(paramValues)-(len(args)-(i+1))*64 { | ||
if len(v) < longDataSize { | ||
paramValues = appendLengthEncodedInteger(paramValues, | ||
uint64(len(v)), | ||
) | ||
|
@@ -1061,7 +1067,7 @@ func (stmt *mysqlStmt) writeExecutePacket(args []driver.Value) error { | |
paramTypes[i+i] = byte(fieldTypeString) | ||
paramTypes[i+i+1] = 0x00 | ||
|
||
if len(v) < mc.maxAllowedPacket-pos-len(paramValues)-(len(args)-(i+1))*64 { | ||
if len(v) < longDataSize { | ||
paramValues = appendLengthEncodedInteger(paramValues, | ||
uint64(len(v)), | ||
) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/threshould/threshold/
What do you mean by the "as possible"? When possible? As much as possible?
Are there still cases where the driver sends too short packets?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I'm not English speaker. I meant it's OK for most realistic use cases,
although there can be edge cases.
No, always send more than 64 bytes.
"shortage" meant there is chance which stmt_exec packet is bigger than
max_allowed_packet.
For example, user can set very small max_allowed_packet. In such case,
packet can be bigger than max_allowed_packet even when all data is sent
with STMT_LONG_DATA.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not good English writer. Could you rewrite this comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just remove the "as possible"