diff options
author | Dan Gudmundsson <[email protected]> | 2016-05-24 16:17:51 +0200 |
---|---|---|
committer | Dan Gudmundsson <[email protected]> | 2016-05-24 16:17:51 +0200 |
commit | cba63cdb2c236c7e0a90070bb10217d5297f9dd7 (patch) | |
tree | 9fe9a457d85b0a0942dbecac36333885d39e0ebf /lib | |
parent | 83b3007c6776be6e35ad8909af1a9d0707baa4d9 (diff) | |
download | otp-cba63cdb2c236c7e0a90070bb10217d5297f9dd7.tar.gz otp-cba63cdb2c236c7e0a90070bb10217d5297f9dd7.tar.bz2 otp-cba63cdb2c236c7e0a90070bb10217d5297f9dd7.zip |
mnesia: Fix index match return patterns
When building match result patterns the tuples they must qouted
with { }, which causes a problem with variable patterns.
Use element(1, Match) instead of trying to build the two tuple.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/mnesia/src/mnesia_index.erl | 4 | ||||
-rw-r--r-- | lib/mnesia/test/mnesia_dirty_access_test.erl | 56 |
2 files changed, 32 insertions, 28 deletions
diff --git a/lib/mnesia/src/mnesia_index.erl b/lib/mnesia/src/mnesia_index.erl index 73d170d1fa..c79f790973 100644 --- a/lib/mnesia/src/mnesia_index.erl +++ b/lib/mnesia/src/mnesia_index.erl @@ -513,11 +513,11 @@ db_put({dets, Ixt}, V) -> ok = dets:insert(Ixt, V). db_get({ram, _}=Ixt, IxKey) -> - Pat = [{{{IxKey, '$1'}}, [], [{{IxKey,'$1'}}]}], + Pat = [{{{IxKey, '$1'}}, [], [{element, 1, '$_'}]}], db_select(Ixt, Pat); db_get({{ext,_,_} = _Storage, {_,_,{_,Type}}} = Ixt, IxKey) -> Pat = case Type of - ordered -> [{{{IxKey, '$1'}}, [], [{{IxKey,'$1'}}]}]; + ordered -> [{{{IxKey, '$1'}}, [], [{element, 1, '$_'}]}]; bag -> [{{IxKey, '_'}, [], ['$_']}] end, db_select(Ixt, Pat); diff --git a/lib/mnesia/test/mnesia_dirty_access_test.erl b/lib/mnesia/test/mnesia_dirty_access_test.erl index c9df8ed353..6d970ac990 100644 --- a/lib/mnesia/test/mnesia_dirty_access_test.erl +++ b/lib/mnesia/test/mnesia_dirty_access_test.erl @@ -461,77 +461,81 @@ dirty_index_update_set_xets(Config) when is_list(Config) -> dirty_index_update_set(Config, ext_ets). dirty_index_update_set(Config, Storage) -> - [Node1] = Nodes = ?acquire_nodes(1, Config), - Tab = index_test, - ValPos = v1, + [Node1] = Nodes = ?acquire_nodes(1, Config), + Tab = index_test, + ValPos = v1, ValPos2 = v3, Def = [{attributes, [k, v1, v2, v3]}, {Storage, [Node1]}, - {index, [ValPos]}], - ?match({atomic, ok}, mnesia:create_table(Tab, Def)), - + {index, [ValPos]}], + ?match({atomic, ok}, mnesia:create_table(Tab, Def)), + Pat1 = {Tab, '$1', 2, '$2', '$3'}, - Pat2 = {Tab, '$1', '$2', '$3', '$4'}, - - Rec1 = {Tab, 1, 2, 3, 4}, + Pat2 = {Tab, '$1', '$2', '$3', '$4'}, + Pat3 = {Tab, '_', '_', '_', {4, 14}}, + + Rec1 = {Tab, 1, 2, 3, {4, 14}}, Rec2 = {Tab, 2, 2, 13, 14}, - Rec3 = {Tab, 1, 12, 13, 14}, - Rec4 = {Tab, 4, 2, 13, 14}, - + Rec3 = {Tab, 1, 12, 13, 14}, + Rec4 = {Tab, 4, 2, 13, 14}, + ?match([], mnesia:dirty_index_read(Tab, 2, ValPos)), ?match(ok, mnesia:dirty_write(Rec1)), ?match([Rec1], mnesia:dirty_index_read(Tab, 2, ValPos)), - + ?match(ok, mnesia:dirty_write(Rec2)), R1 = mnesia:dirty_index_read(Tab, 2, ValPos), ?match([Rec1, Rec2], lists:sort(R1)), - + ?match(ok, mnesia:dirty_write(Rec3)), R2 = mnesia:dirty_index_read(Tab, 2, ValPos), ?match([Rec2], lists:sort(R2)), ?match([Rec2], mnesia:dirty_index_match_object(Pat1, ValPos)), - - {atomic, R3} = mnesia:transaction(fun() -> mnesia:match_object(Pat2) end), + + {atomic, R3} = mnesia:transaction(fun() -> mnesia:match_object(Pat2) end), ?match([Rec3, Rec2], lists:sort(R3)), - + ?match(ok, mnesia:dirty_write(Rec4)), R4 = mnesia:dirty_index_read(Tab, 2, ValPos), ?match([Rec2, Rec4], lists:sort(R4)), - + ?match(ok, mnesia:dirty_delete({Tab, 4})), ?match([Rec2], mnesia:dirty_index_read(Tab, 2, ValPos)), - + ?match({atomic, ok}, mnesia:del_table_index(Tab, ValPos)), ?match({atomic, ok}, mnesia:transaction(fun() -> mnesia:write(Rec4) end)), ?match({atomic, ok}, mnesia:add_table_index(Tab, ValPos)), ?match({atomic, ok}, mnesia:add_table_index(Tab, ValPos2)), - + R5 = mnesia:dirty_match_object(Pat2), ?match([Rec3, Rec2, Rec4], lists:sort(R5)), - + R6 = mnesia:dirty_index_read(Tab, 2, ValPos), - ?match([Rec2, Rec4], lists:sort(R6)), - ?match([], mnesia:dirty_index_read(Tab, 4, ValPos2)), + ?match([Rec2, Rec4], lists:sort(R6)), + ?match([], mnesia:dirty_index_read(Tab, {4,14}, ValPos2)), R7 = mnesia:dirty_index_read(Tab, 14, ValPos2), ?match([Rec3, Rec2, Rec4], lists:sort(R7)), ?match({atomic, ok}, mnesia:transaction(fun() -> mnesia:write(Rec1) end)), R8 = mnesia:dirty_index_read(Tab, 2, ValPos), ?match([Rec1, Rec2, Rec4], lists:sort(R8)), - ?match([Rec1], mnesia:dirty_index_read(Tab, 4, ValPos2)), + ?match([Rec1], mnesia:dirty_index_read(Tab, {4,14}, ValPos2)), + ?match([Rec1], mnesia:dirty_match_object(Pat3)), + ?match([Rec1], mnesia:dirty_index_match_object(Pat3, ValPos2)), + R9 = mnesia:dirty_index_read(Tab, 14, ValPos2), ?match([Rec2, Rec4], lists:sort(R9)), ?match({atomic, ok}, mnesia:transaction(fun() -> mnesia:delete_object(Rec2) end)), R10 = mnesia:dirty_index_read(Tab, 2, ValPos), ?match([Rec1, Rec4], lists:sort(R10)), - ?match([Rec1], mnesia:dirty_index_read(Tab, 4, ValPos2)), + ?match([Rec1], mnesia:dirty_index_read(Tab, {4,14}, ValPos2)), ?match([Rec4], mnesia:dirty_index_read(Tab, 14, ValPos2)), ?match(ok, mnesia:dirty_delete({Tab, 4})), R11 = mnesia:dirty_index_read(Tab, 2, ValPos), ?match([Rec1], lists:sort(R11)), - ?match([Rec1], mnesia:dirty_index_read(Tab, 4, ValPos2)), + ?match([Rec1], mnesia:dirty_index_read(Tab, {4,14}, ValPos2)), ?match([], mnesia:dirty_index_read(Tab, 14, ValPos2)), ?verify_mnesia(Nodes, []). |