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

handle atttypmod being correct for decimals from v22.1 #240

Merged
merged 1 commit into from
Feb 2, 2022
Merged
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
12 changes: 11 additions & 1 deletion lib/active_record/connection_adapters/cockroachdb_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,19 @@ def initialize_type_map(m = type_map)
precision = extract_precision(sql_type)
scale = extract_scale(sql_type)


# The type for the numeric depends on the width of the field,
# so we'll do something special here.
#
# When dealing with decimal columns:
#
# places after decimal = fmod - 4 & 0xffff
# places before decimal = (fmod - 4) >> 16 & 0xffff
#
# For older versions of CockroachDB (<v22.1), fmod is -1 for 0 width.
# If fmod is -1, that means that precision is defined but not
# scale, or neither is defined.
if fmod && fmod == -1 && !precision.nil?
if fmod && ((fmod == -1 && !precision.nil?) || (fmod - 4 & 0xffff).zero?)
# Below comment is from ActiveRecord
# FIXME: Remove this class, and the second argument to
# lookups on PG
Expand Down