Skip to content
This repository was archived by the owner on Nov 1, 2018. It is now read-only.

Ensure decimal point in decimal parameters #381

Merged
merged 1 commit into from
Jun 30, 2017
Merged

Ensure decimal point in decimal parameters #381

merged 1 commit into from
Jun 30, 2017

Conversation

bricelam
Copy link
Contributor

@bricelam bricelam commented Jun 30, 2017

This prevents integer results when performing arithmetic operations on decimal parameters. For example, consider the following query.

SELECT 1 / $value;

Where value is the following in C#.

decimal value = 2m;

Here is a table illustrating the improved result.

Microsoft.Data.Sqlite Result
1.x 0
2.0.0 0.5

Breaking change

You may encounter a breaking change if you previously saved integral decimal values into a column using version 1.x and try to query for equality in version 2.0.0.

For example, if you previously saved the value 3m into DecimalColumn and try the following query in version 2.0 (where $value is also 3m) it will return no results.

SELECT *
FROM MyTable
WHERE DecimalColumn = $value;
--              '3' = '3.0'   (False)

To upgrade your database to be fully compatible with decimal parameters in version 2.0.0, you'll need to use UPDATE statements like the following.

UPDATE MyTable
SET DecimalColumn = DecimalColumn + '.0'
WHERE instr(DecimalColumn, '.') = 0;

Note, reading decimal columns with SqliteDataReader will yield the same values as before. It's only SQL equality comparisons that are affected.

Copy link
Contributor

@smitpatel smitpatel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hopefully it has exact number of #

@bricelam
Copy link
Contributor Author

I double-checked everything. It's the same precision as before, just with a guaranteed decimal place.

@bricelam bricelam merged commit d3d119f into aspnet:dev Jun 30, 2017
@bricelam bricelam deleted the ten branch June 30, 2017 17:26
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants