List:General Discussion« Previous MessageNext Message »
From:Paul DuBois Date:August 15 1999 11:07pm
Subject:Re: Granting authorities
View as plain text  
At 8:37 AM +1000 8/16/99, gleNN wrote:
>On Sun, 15 Aug 1999, Paul DuBois wrote:
>> If I understand correctly what you want to do...
>> You cannot do it.  The user is set according to the user name that is
>> supplied to the server when you make your connection and does not change
>> thereafter.
>Right, but how do I get that USER name into the USERID column
>automatically with each transaction?? This would be easy with a stored
>    SET BARCODE = ?
>But how do I achieve this using MySQL?

Sorry, I misunderstood what you meant.  From the MySQL manual:

      Returns the current *MySQL* user name.
           mysql> select USER();
                   -> 'davida@localhost'

      In MySQL 3.22.11 or later, this includes the client hostname as
      well as the username.  You can extract just the username part like
      this (which works whether or not the value includes a hostname

           mysql> select substring_index(USER(),"@",1);
                   -> 'davida'

So you should be able to write the "AND USERID = USER" part of your
query as "AND USERID = SUBSTRING_INDEX(USER(),"@",1)".

That assumes all your user names are unique no matter where they're
connecting from.  If you have a user "glenn" who connects from one
host and a user "glenn" who connects from another, you might want
to retain the hostname part.  Or store it separately.  You can get
that from SUBSTRING_INDEX(USER(),"@",-1).

Paul DuBois, paul@stripped
Granting authoritiesgleNN15 Aug
  • Re: Granting authoritiesPaul DuBois15 Aug
    • Re: Granting authoritiesgleNN16 Aug
      • Re: Granting authoritiesPaul DuBois16 Aug
        • Re: Granting authoritiesgleNN16 Aug
          • Re: Granting authoritiesBenjamin Pflugmann16 Aug