view m-toolbox/classes/+utils/@jmysql/getUserID.m @ 1:2014ba5b353a database-connection-manager

Remove old code
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Sat, 03 Dec 2011 18:13:55 +0100
parents f0afece42f48
children
line wrap: on
line source

% GETUSERID gets the user ID number corresponding to the given user name.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% DESCRIPTION: GETUSERID gets the user ID number corresponding to the
%              user name that connected to the MySQL database.
%
% CALL:        userid = getUserID(conn)
%
% VERSION:     $Id: getUserID.m,v 1.1 2008/08/08 11:51:12 ingo Exp $
%
% HISTORY:     24-05-2007 M Hewitson
%                 Creation
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function [userid,dbuser] = getUserID(varargin)

  userid = [];
  conn = varargin{1};
  if nargin > 1
    username = varargin{2};
  else
    username = char(conn.getUsername);
  end
  try
    if ~conn.isConnected
      conn.openConnection;
    end
    if conn.isConnected
      q    = sprintf('select id from users where username="%s"', username);
      results = conn.query(q);
      while results.next
        userid = str2num(char(results.getString(1)));
      end
    end
    dbuser = conn.getUsername;
        
  catch
    warning('!!! Unable to retrieve user ID.');
  end

end