Skip to content

Commit

Permalink
Merge pull request #86 from Mytherin/issue65
Browse files Browse the repository at this point in the history
Fix #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
  • Loading branch information
Mytherin authored Sep 5, 2024
2 parents 383f192 + 559e121 commit d0c56ab
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/mysql_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ LogicalType MySQLUtils::FieldToLogicalType(ClientContext &context, MYSQL_FIELD *
break;
case MYSQL_TYPE_DECIMAL:
case MYSQL_TYPE_NEWDECIMAL:
type_data.precision = int64_t(field->max_length) - 2; // -2 for minus sign and dot
type_data.precision = int64_t(field->length) - 2; // -2 for minus sign and dot
type_data.scale = field->decimals;
type_data.type_name = "decimal";
break;
Expand Down
8 changes: 8 additions & 0 deletions test/sql/mysql_query.test
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,11 @@ SELECT * FROM mysql_query('simple', 'SELECT * FROM datetime_tbl')
1000-01-01 1000-01-01 00:00:00 1970-01-01 06:00:01+00 -838:59:59 2155
9999-12-31 9999-12-31 23:59:59 2038-01-19 04:14:07+00 838:59:59 2000
NULL NULL NULL NULL NULL

# issue #65 - Decimal data type conversion issue with mysql_query function
query II
SELECT * FROM mysql_query('simple', 'SELECT * FROM tbl_issue65')
----
1 1.11
2 2.22
3 3.33
3 changes: 3 additions & 0 deletions test/test_data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,6 @@ VALUES (
ST_GeomFromText('MULTIPOLYGON(((0 5, 2 5, 2 7, 0 7, 0 5)))'),
ST_GeomFromText('GEOMETRYCOLLECTION EMPTY')
);

CREATE TABLE tbl_issue65 (col1 int, col2 decimal(5,2));
insert into tbl_issue65 values (1,1.11), (2,2.22), (3,3.33);

0 comments on commit d0c56ab

Please sign in to comment.