view m-toolbox/classes/+utils/@repository/getUser.m @ 51:9d5c88356247 database-connection-manager

Make unit tests database connection parameters configurable
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Wed, 07 Dec 2011 17:24:37 +0100
parents 9174aadb93a5
children
line wrap: on
line source

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