[erlang-questions] Why QLC join query failed on transformed table in mnesia?

devdoer bird devdoer2@REDACTED
Fri Aug 8 16:36:40 CEST 2008


HI:

I have two tables :"user" and "product", I found the join query  failed when
one table is been transformed by function "mensia:transform_table".

 Here is the record defination:
-record(user,{uuid,name,version}).
-record(user2,{uuid,name}).
-record(product,{uuid,name,price,user}).

The user table is first defined as the record "user", then is transformed by
mensia:transform_table to  the record "user2",after the transformation ,the
join query on user table and  product table failed and report badrecord
exception.

The related code lists as below.

 1.Here is the record defination:

-record(user,{uuid,name,version}).
-record(user2,{uuid,name}).
-record(product,{uuid,name,price,user}).

----------------------------------------------------------
2.here is the transform code:

upgrade_fun(X)->
    #user2{
        uuid=X#user.uuid,
        name=X#user.name
    }.

upgrade_table()->

    mnesia:transform_table(user,fun
upgrade_fun/1,record_info(fields,user2),user2),

--------------------------------------------------------------------
3. here is my QLC query code:

q_product_6()->
    do(qlc:q([{Y#user.uuid,Y#user.name
}||X<-mnesia:table(product),X#product.price<5,Y<-mnesia:table(
user),Y#user.uuid =< 6])).
do(Q) ->
    F = fun() -> qlc:e(Q) end,
   Val= mnesia:transaction(F),

    Val.


The join query throw the exception:

** exception exit: {aborted,{{badrecord,user},
                             [{product,'-q_product_6/0-fun-1-',8},
                              {qlc,collect,1},
                              {qlc,eval,2},
                              {mnesia_tm,apply_fun,3},
                              {mnesia_tm,execute_transaction,5},
                              {mnesia,wrap_trans,6},
                              {erl_eval,do_apply,5},
                              {shell,exprs,6}]}}
     in function  mnesia:wrap_trans/6

Any guys know why? It seems be a bug in QLC.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20080808/4aeffe27/attachment.htm>


More information about the erlang-questions mailing list