Mercurial > hg > ltpda
diff m-toolbox/classes/+utils/@repository/getUser.m @ 11:9174aadb93a5 database-connection-manager
Add LTPDA Repository utility functions into utils.repository
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Mon, 05 Dec 2011 16:20:06 +0100 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/m-toolbox/classes/+utils/@repository/getUser.m Mon Dec 05 16:20:06 2011 +0100 @@ -0,0 +1,20 @@ +function [username, userid] = getUser(conn) +% GETUSER Return username and userid of the current database user. +% +% CALL: +% +% [username, userid] = utils.repository.getUser(conn) +% + + % current database user + rows = utils.mysql.execute(conn, 'SELECT SUBSTRING_INDEX(USER(),''@'',1)'); + username = rows{1}; + + % userid + rows = utils.mysql.execute(conn, 'SELECT id FROM users WHERE username = ?', username); + if isempty(rows) + error('### could not determine user id'); + end + userid = rows{1}; + +end