Skip to content

Commit

Permalink
support JSON type on MySQL 5.7
Browse files Browse the repository at this point in the history
  • Loading branch information
tmtm committed Dec 30, 2015
1 parent 98a0954 commit 6cf6ee1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions ext/mysql/ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ static VALUE _protocol_net2value(packet_data_t *data, int type, int uflag)
case TYPE_NEWDECIMAL:
case TYPE_BLOB:
case TYPE_BIT:
case TYPE_JSON:
return _packet_lcs(data);
case TYPE_TINY:
n = *data->ptr++;
Expand Down
2 changes: 1 addition & 1 deletion lib/mysql/protocol.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Protocol
# Object :: converted value.
def self.net2value(pkt, type, unsigned)
case type
when Field::TYPE_STRING, Field::TYPE_VAR_STRING, Field::TYPE_NEWDECIMAL, Field::TYPE_BLOB
when Field::TYPE_STRING, Field::TYPE_VAR_STRING, Field::TYPE_NEWDECIMAL, Field::TYPE_BLOB, Field::TYPE_JSON
return pkt.lcs
when Field::TYPE_TINY
v = pkt.utiny
Expand Down
10 changes: 10 additions & 0 deletions test/test_mysql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1564,6 +1564,16 @@ class TestMysql < Test::Unit::TestCase
assert{ @s.entries == [[nil], [''], ['abc'], ['def'], ['abc,def'], ['abc'], ['def'], ['abc,def'], ['']] }
end

test '#fetch json column' do
if @m.server_version >= 50700
@m.query "create temporary table t (i json)"
@m.query "insert into t values ('123'),('{\"a\":1,\"b\":2,\"c\":3}'),('[1,2,3]')"
@s.prepare 'select i from t'
@s.execute
assert{ @s.entries == [['123'], ['{"a": 1, "b": 2, "c": 3}'], ['[1, 2, 3]']] }
end
end

test '#field_count' do
@s.prepare 'select 1,2,3'
assert{ @s.field_count == 3 }
Expand Down

0 comments on commit 6cf6ee1

Please sign in to comment.