comparison 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
comparison
equal deleted inserted replaced
10:75007001cbfe 11:9174aadb93a5
1 function [username, userid] = getUser(conn)
2 % GETUSER Return username and userid of the current database user.
3 %
4 % CALL:
5 %
6 % [username, userid] = utils.repository.getUser(conn)
7 %
8
9 % current database user
10 rows = utils.mysql.execute(conn, 'SELECT SUBSTRING_INDEX(USER(),''@'',1)');
11 username = rows{1};
12
13 % userid
14 rows = utils.mysql.execute(conn, 'SELECT id FROM users WHERE username = ?', username);
15 if isempty(rows)
16 error('### could not determine user id');
17 end
18 userid = rows{1};
19
20 end