Skip to content

Commit 559e121

Browse files
committed
Fix duckdb#65: use length instead of max_length when computing decimal width - as when using mysql_query max_length corresponds to the max length in the result set, as opposed to the max length of the field type
1 parent 64cb6ae commit 559e121

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

src/mysql_utils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ LogicalType MySQLUtils::FieldToLogicalType(ClientContext &context, MYSQL_FIELD *
332332
break;
333333
case MYSQL_TYPE_DECIMAL:
334334
case MYSQL_TYPE_NEWDECIMAL:
335-
type_data.precision = int64_t(field->max_length) - 2; // -2 for minus sign and dot
335+
type_data.precision = int64_t(field->length) - 2; // -2 for minus sign and dot
336336
type_data.scale = field->decimals;
337337
type_data.type_name = "decimal";
338338
break;

test/sql/mysql_query.test

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,3 +165,11 @@ SELECT * FROM mysql_query('simple', 'SELECT * FROM datetime_tbl')
165165
1000-01-01 1000-01-01 00:00:00 1970-01-01 06:00:01+00 -838:59:59 2155
166166
9999-12-31 9999-12-31 23:59:59 2038-01-19 04:14:07+00 838:59:59 2000
167167
NULL NULL NULL NULL NULL
168+
169+
# issue #65 - Decimal data type conversion issue with mysql_query function
170+
query II
171+
SELECT * FROM mysql_query('simple', 'SELECT * FROM tbl_issue65')
172+
----
173+
1 1.11
174+
2 2.22
175+
3 3.33

test/test_data.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,3 +149,6 @@ VALUES (
149149
ST_GeomFromText('MULTIPOLYGON(((0 5, 2 5, 2 7, 0 7, 0 5)))'),
150150
ST_GeomFromText('GEOMETRYCOLLECTION EMPTY')
151151
);
152+
153+
CREATE TABLE tbl_issue65 (col1 int, col2 decimal(5,2));
154+
insert into tbl_issue65 values (1,1.11), (2,2.22), (3,3.33);

0 commit comments

Comments
 (0)