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
>Right, but how do I get that USER name into the USERID column
>automatically with each transaction?? This would be easy with a stored
> UPDATE PRODUCT
> SET BARCODE = ?
> AND USERID = USER
> WHERE BARDOCDE = ?;
>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();
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);
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