Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 667235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:54:21+00:00 2026-05-13T23:54:21+00:00

I’m trying to build a small testing app with erlang+mnesia. I have a user

  • 0

I’m trying to build a small testing app with erlang+mnesia.

I have a user table build from the #user record, as defined here:

-record(user_details, {name, password}).
-record(user, {id, details}).

then I insert a user with that function:

add_sample_data() ->
    Mat = #user{
      details = #user_details{
    name = "mat", password = "mat"
       }
     }, 
    user:insert_user(Mat),

the query [U#user.details || U <- mnesia:table(user)] return a non empty list.
now I’m trying to build a query which would return a list containing zero record if there is no record with details.name matching Name or the matching record if there is one.

here is the method I use (this one works):

user_exists() ->
  Fun = fun() ->
    Query = qlc:q([
      U#user.details || 
      U <- mnesia:table(user)
    ]),
    qlc:e(Query)
  end,
  case mnesia:transaction(Fun) of
    {atomic, []} -> false;
    {atomic, [_User]} -> true
  end.

I copied some stuff from this tutorial. A similar problem is solved with mnesia:select in the mne_fun_query({sport, Sport}) method (slide 19) but now I’d like to do it with qlc.

I tried various combinations but without any success (often failed at compilation time..).

I’m really new to erlang, if you can tell which query should works and explains it a little, that would be greatly appreciated!

mat.

edit

here is one version which does not work but maybe explain my problem better

user_exists() ->
  Fun = fun() ->
    Query = qlc:q([
      U#user.details || 
      U <- mnesia:table(user), 
      U#user.details.name == "mat"     <<<<< This is the line with the problem
    ]),
    qlc:e(Query)
  end,
  case mnesia:transaction(Fun) of
    {atomic, []} -> false;
    {atomic, [_User]} -> true
  end.

and the error I have:

mathieu@evangeneer:~/projects/nopair$ make
Recompile: src/resources/user_resource
src/resources/user_resource.erl:22: syntax error before: ‘.’
src/resources/user_resource.erl:6: function user_exists/2 undefined make:
*** [erl] Error 1

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T23:54:21+00:00Added an answer on May 13, 2026 at 11:54 pm

    On the problem line:

    U#user.details.name == "mat"
    

    You are attempting to access the user_details record but not naming it. Try…

    (U#user.details)#user_details.name == "mat"
    

    From my experience, the compiler doesn’t figure out on its own that #user.details is a #user_details.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.