Skip to content
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

Support handling signed integers in Prepared Statements #5974

Merged
merged 3 commits into from
Mar 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions go/mysql/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ func (c *Conn) parseStmtArgs(data []byte, typ querypb.Type, pos int) (sqltypes.V
return sqltypes.NULL, pos, true
case sqltypes.Int8:
val, pos, ok := readByte(data, pos)
return sqltypes.NewInt64(int64(val)), pos, ok
return sqltypes.NewInt64(int64(int8(val))), pos, ok
case sqltypes.Uint8:
val, pos, ok := readByte(data, pos)
return sqltypes.NewUint64(uint64(val)), pos, ok
Expand All @@ -618,13 +618,13 @@ func (c *Conn) parseStmtArgs(data []byte, typ querypb.Type, pos int) (sqltypes.V
return sqltypes.NewUint64(uint64(val)), pos, ok
case sqltypes.Int16, sqltypes.Year:
val, pos, ok := readUint16(data, pos)
return sqltypes.NewInt64(int64(val)), pos, ok
return sqltypes.NewInt64(int64(int16(val))), pos, ok
case sqltypes.Uint24, sqltypes.Uint32:
val, pos, ok := readUint32(data, pos)
return sqltypes.NewUint64(uint64(val)), pos, ok
case sqltypes.Int24, sqltypes.Int32:
val, pos, ok := readUint32(data, pos)
return sqltypes.NewInt64(int64(val)), pos, ok
return sqltypes.NewInt64(int64(int32(val))), pos, ok
case sqltypes.Float32:
val, pos, ok := readUint32(data, pos)
return sqltypes.NewFloat64(float64(math.Float32frombits(uint32(val)))), pos, ok
Expand Down
20 changes: 20 additions & 0 deletions go/test/endtoend/preparestmt/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,26 @@ var (
json_col JSON,
text_col TEXT,
data longblob,
tinyint_min TINYINT,
tinyint_max TINYINT,
tinyint_pos TINYINT,
tinyint_neg TINYINT,
smallint_min SMALLINT,
smallint_max SMALLINT,
smallint_pos SMALLINT,
smallint_neg SMALLINT,
medint_min MEDIUMINT,
medint_max MEDIUMINT,
medint_pos MEDIUMINT,
medint_neg MEDIUMINT,
int_min INT,
int_max INT,
int_pos INT,
int_neg INT,
bigint_min BIGINT,
bigint_max BIGINT,
bigint_pos BIGINT,
bigint_neg BIGINT,
primary key (id)
) Engine=InnoDB`
)
Expand Down
24 changes: 21 additions & 3 deletions go/test/endtoend/preparestmt/stmt_methods_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ func TestInsertUpdateDelete(t *testing.T) {
defer dbo.Close()
// prepare insert statement
insertStmt := `insert into ` + tableName + ` values( ?, ?, ?, ?, ?, ?, ?, ?,
?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);`
?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);`

textValue := fake.FullName()
largeComment := fake.Paragraph()
Expand All @@ -62,6 +63,11 @@ func TestInsertUpdateDelete(t *testing.T) {
time.Now(),
time.Date(2009, 5, 5, 0, 0, 0, 50000, time.UTC),
1, 1, 1, 1, 1, 1, 1, 1, 1, jsonExample, textValue, largeComment,
-128, 127, 1, -1,
-32768, 32767, 1, -1,
-8388608, 8388607, 1, -1,
-2147483648, 2147483647, 1, -1,
-(1 << 63), (1 << 63) - 1, 1, -1,
}
exec(t, dbo, insertStmt, insertValue...)

Expand Down Expand Up @@ -118,8 +124,15 @@ func TestAutoIncColumns(t *testing.T) {
msg,keyspace_id,tinyint_unsigned,bool_signed,smallint_unsigned,
mediumint_unsigned,int_unsigned,float_unsigned,double_unsigned,
decimal_unsigned,t_date,t_datetime,t_datetime_micros,t_time,t_timestamp,c8,c16,c24,
c32,c40,c48,c56,c63,c64,json_col,text_col,data) VALUES (?, ?, ?, ?, ?, ?,
?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);`
c32,c40,c48,c56,c63,c64,json_col,text_col,data,
tinyint_min,tinyint_max,tinyint_pos,tinyint_neg,
smallint_min,smallint_max,smallint_pos,smallint_neg,
medint_min,medint_max,medint_pos,medint_neg,
int_min,int_max,int_pos,int_neg,
bigint_min,bigint_max,bigint_pos,bigint_neg
) VALUES (?, ?, ?, ?, ?, ?,
?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);`
insertValue := []interface{}{
"21", 0,
127, 1, 32767, 8388607, 2147483647, 2.55, 64.9, 55.5,
Expand All @@ -129,6 +142,11 @@ func TestAutoIncColumns(t *testing.T) {
time.Now(),
time.Date(2009, 5, 5, 0, 0, 0, 50000, time.UTC),
1, 1, 1, 1, 1, 1, 1, 1, 1, jsonExample, fake.DomainName(), fake.Paragraph(),
-(1 << 7), (1 << 7) - 1, 1, -1,
-(1 << 15), (1 << 15) - 1, 1, -1,
-(1 << 23), (1 << 23) - 1, 1, -1,
-(1 << 31), (1 << 31) - 1, 1, -1,
-(1 << 63), (1 << 63) - 1, 1, -1,
}

exec(t, dbo, insertStmt, insertValue...)
Expand Down