Ask Your Question

How to use username in a query / sql statement? [closed]

asked 2014-02-25 06:12:21 +0200

Libre Nut gravatar image

I have a LO base connected to a postgresql database with mutliple users. I want to load different forms based on the current user name. How do I fetch the current user name using query or a sql statement?

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Alex Kemp
close date 2016-02-19 14:58:11.604042

2 Answers

Sort by » oldest newest most voted

answered 2014-02-25 22:56:57 +0200

m.a.riosv gravatar image

I'm not sure if this can help.

Use of parameters in queries
If you often use the same basic query but with different values each time, queries with parameters can be used. In principle queries with parameters function just like queries for a subform:
SELECT "ID", "ReaderID", "Media_ID", "Loan_date" FROM "Loans" WHERE "Return_Date" IS NULL AND "Reader_ID"=2;
This query shows only the media on loan to the reader with the number 2.
SELECT "ID", "Reader_ID", "Media_ID", "Loan_date" FROM "Loans" WHERE "Return_Date" IS NULL AND "Reader_ID" = :Readernumber;
Now when you run the query, an entry field appears. It prompts you to enter a reader number. Whatever value you enter here, the media currently on loan to that reader will be displayed. When using forms, the parameter can be passed from the main form to a subform. However it sometimes happens that queries using parameters in subforms are not updated, if data is changed or newly entered.
Often it would be nice to alter the contents of list boxes using settings in the main form. So for example, we could prevent library media from being loaned to individuals who are currently banned from borrowing media. Unfortunately controlling list box settings in this personalized way by using parameters is not possible.

(From documentation chapter 5 - queries)

edit flag offensive delete link more


I'm sorry if I was not clear in my question. I want the query to pickup the name of the current user automatically. Can you guide me how to do it?

Libre Nut gravatar imageLibre Nut ( 2014-02-26 08:44:58 +0200 )edit

answered 2014-02-26 13:43:06 +0200

Libre Nut gravatar image

The answer was pretty simple. Current_User returns the value of the logged in user. How naive of me! Thanks to mariosv and others who helped me find the solution.

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2014-02-25 06:12:21 +0200

Seen: 660 times

Last updated: Feb 26 '14