Merge pull request #8206 from kennyj/fix_7619-2
Fix #7619. 0x prefix must be added when assigning hexadecimal string into bit column in Postgresql, because solving ambiguity.
This commit is contained in:
commit
a1945cb0b9
@ -1,5 +1,9 @@
|
||||
## Rails 4.0.0 (unreleased) ##
|
||||
|
||||
* `0x` prefix must be added when assigning hexadecimal string into `bit` column in PostgreSQL.
|
||||
|
||||
*kennyj*
|
||||
|
||||
* Added Statement Cache to allow the caching of a single statement. The cache works by
|
||||
duping the relation returned from yielding a statement, which allows skipping the AST
|
||||
building phase for following executes. The cache returns results in array format.
|
||||
|
@ -28,8 +28,10 @@ def string_to_time(string)
|
||||
|
||||
def string_to_bit(value)
|
||||
case value
|
||||
when /^[01]*$/ then value # Bit-string notation
|
||||
when /^[0-9A-F]*$/i then value.hex.to_s(2) # Hexadecimal notation
|
||||
when /^0x/i
|
||||
value[2..-1].hex.to_s(2) # Hexadecimal notation
|
||||
else
|
||||
value # Bit-string notation
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -545,7 +545,7 @@ def test_update_network_address
|
||||
|
||||
def test_update_bit_string
|
||||
new_bit_string = '11111111'
|
||||
new_bit_string_varying = 'FF'
|
||||
new_bit_string_varying = '0xFF'
|
||||
assert @first_bit_string.bit_string = new_bit_string
|
||||
assert @first_bit_string.bit_string_varying = new_bit_string_varying
|
||||
assert @first_bit_string.save
|
||||
@ -553,6 +553,12 @@ def test_update_bit_string
|
||||
assert_equal @first_bit_string.bit_string, new_bit_string
|
||||
assert_equal @first_bit_string.bit_string, @first_bit_string.bit_string_varying
|
||||
end
|
||||
|
||||
def test_invalid_hex_string
|
||||
new_bit_string = 'FF'
|
||||
@first_bit_string.bit_string = new_bit_string
|
||||
assert_raise(ActiveRecord::StatementInvalid) { assert @first_bit_string.save }
|
||||
end
|
||||
|
||||
def test_update_oid
|
||||
new_value = 567890
|
||||
|
Loading…
Reference in New Issue
Block a user