Mercurial > hg > ltpda
comparison m-toolbox/classes/+utils/@jmysql/getUserID.m @ 0:f0afece42f48
Import.
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Wed, 23 Nov 2011 19:22:13 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f0afece42f48 |
---|---|
1 % GETUSERID gets the user ID number corresponding to the given user name. | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: GETUSERID gets the user ID number corresponding to the | |
5 % user name that connected to the MySQL database. | |
6 % | |
7 % CALL: userid = getUserID(conn) | |
8 % | |
9 % VERSION: $Id: getUserID.m,v 1.1 2008/08/08 11:51:12 ingo Exp $ | |
10 % | |
11 % HISTORY: 24-05-2007 M Hewitson | |
12 % Creation | |
13 % | |
14 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
15 | |
16 function [userid,dbuser] = getUserID(varargin) | |
17 | |
18 userid = []; | |
19 conn = varargin{1}; | |
20 if nargin > 1 | |
21 username = varargin{2}; | |
22 else | |
23 username = char(conn.getUsername); | |
24 end | |
25 try | |
26 if ~conn.isConnected | |
27 conn.openConnection; | |
28 end | |
29 if conn.isConnected | |
30 q = sprintf('select id from users where username="%s"', username); | |
31 results = conn.query(q); | |
32 while results.next | |
33 userid = str2num(char(results.getString(1))); | |
34 end | |
35 end | |
36 dbuser = conn.getUsername; | |
37 | |
38 catch | |
39 warning('!!! Unable to retrieve user ID.'); | |
40 end | |
41 | |
42 end | |
43 |