Add DriverError::StmtParamsNumberExceedsLimit
#327
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.
When comparing the number of params in a statement against the number of params supplied, if they do not match, the error is supposed to provide what these two numbers are for users to understand what might have gone wrong. This is achieved via following code path in
ExecRoutine
:The maximum number of bind variables in a statement supported by MySQL is
65,535
and this is guarded at the server side which means the aforementioned comparison inExecRoutine
is hit before that.But at this point, both of these number could go over
65,535
, which is theu16::MAX
. In that case, when the error is constructed, the conversion fromparams.len()
'susize
tou16
would result in a loss of precision, producing a confusing error. Becauseself.stmt.num_params()
returns au16
whileparams.len()
returns ausize
.For example, if both the number of the required params and the supplied params are
65,539
, which is greater thanu16::MAX
,self.stmt.num_params()
would have returned a truncated number3
and even withas usize
would not have recovered the loss precision. Meanwhile,params.len()
still returns65,539
because it is ofusize
. The comparison then produces an incorrect result, saying that they do not match, even though they do. What makes it even more confusing is that in the error message there are two identical numbers becauseparams.len() as u16
converts theusize
tou16
, causing the same loss of precision.Because the
self.stmt.num_params()
returns au16
, which intrinsically prevents the detection of mismatched param numbers if they go overu16::MAX
, and changing that type would be rather intrusive. Therefore, this commit fixes merely the symptom by providing a new error variantStmtParamsNumberExceedsLimit
that represents the case when the number of provided params exceeds the limit.Ref: https://stackoverflow.com/questions/4922345/how-many-bind-variables-can-i-use-in-a-sql-query-in-mysql-5#comment136409462_11131824