From 19ba263158fbd090c5016ab667ba030df3ab575b Mon Sep 17 00:00:00 2001 From: Saif Alharthi Date: Wed, 25 Mar 2020 15:05:40 -0700 Subject: [PATCH 1/3] Fix prepared statements results parsing for signed values Signed-off-by: Saif Alharthi --- go/mysql/query.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/go/mysql/query.go b/go/mysql/query.go index 8d340a1e6cd..ef37f6eb5ae 100644 --- a/go/mysql/query.go +++ b/go/mysql/query.go @@ -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 @@ -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 From 822453824890bf253e2e6c4065617914fb5e235e Mon Sep 17 00:00:00 2001 From: Saif Alharthi Date: Wed, 25 Mar 2020 19:56:01 -0700 Subject: [PATCH 2/3] Modified prepared statement test to support limits of integer variables Signed-off-by: Saif Alharthi --- go/test/endtoend/preparestmt/main_test.go | 20 ++++++++++++++++ .../endtoend/preparestmt/stmt_methods_test.go | 24 ++++++++++++++++--- 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/go/test/endtoend/preparestmt/main_test.go b/go/test/endtoend/preparestmt/main_test.go index 1fa24bf62a3..d00ec84da65 100644 --- a/go/test/endtoend/preparestmt/main_test.go +++ b/go/test/endtoend/preparestmt/main_test.go @@ -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` ) diff --git a/go/test/endtoend/preparestmt/stmt_methods_test.go b/go/test/endtoend/preparestmt/stmt_methods_test.go index 7d4b84e9922..2016293823e 100644 --- a/go/test/endtoend/preparestmt/stmt_methods_test.go +++ b/go/test/endtoend/preparestmt/stmt_methods_test.go @@ -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() @@ -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...) @@ -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, @@ -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(), + -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...) From 41737c693f97a4a2000fa8b9bc553d392de65d75 Mon Sep 17 00:00:00 2001 From: Saif Alharthi Date: Wed, 25 Mar 2020 20:38:11 -0700 Subject: [PATCH 3/3] Modify test for readability Signed-off-by: Saif Alharthi --- go/test/endtoend/preparestmt/stmt_methods_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/go/test/endtoend/preparestmt/stmt_methods_test.go b/go/test/endtoend/preparestmt/stmt_methods_test.go index 2016293823e..b18ea1883a0 100644 --- a/go/test/endtoend/preparestmt/stmt_methods_test.go +++ b/go/test/endtoend/preparestmt/stmt_methods_test.go @@ -142,10 +142,10 @@ 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(), - -128, 127, 1, -1, - -32768, 32767, 1, -1, - -8388608, 8388607, 1, -1, - -2147483648, 2147483647, 1, -1, + -(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, }