annotate m-toolbox/classes/+utils/@repository/getUser.m @ 52:daf4eab1a51e database-connection-manager tip

Fix. Default password should be [] not an empty string
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Wed, 07 Dec 2011 17:29:47 +0100
parents 9174aadb93a5
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11
9174aadb93a5 Add LTPDA Repository utility functions into utils.repository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
1 function [username, userid] = getUser(conn)
9174aadb93a5 Add LTPDA Repository utility functions into utils.repository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
2 % GETUSER Return username and userid of the current database user.
9174aadb93a5 Add LTPDA Repository utility functions into utils.repository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
3 %
9174aadb93a5 Add LTPDA Repository utility functions into utils.repository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
4 % CALL:
9174aadb93a5 Add LTPDA Repository utility functions into utils.repository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
5 %
9174aadb93a5 Add LTPDA Repository utility functions into utils.repository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
6 % [username, userid] = utils.repository.getUser(conn)
9174aadb93a5 Add LTPDA Repository utility functions into utils.repository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
7 %
9174aadb93a5 Add LTPDA Repository utility functions into utils.repository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
8
9174aadb93a5 Add LTPDA Repository utility functions into utils.repository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
9 % current database user
9174aadb93a5 Add LTPDA Repository utility functions into utils.repository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
10 rows = utils.mysql.execute(conn, 'SELECT SUBSTRING_INDEX(USER(),''@'',1)');
9174aadb93a5 Add LTPDA Repository utility functions into utils.repository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
11 username = rows{1};
9174aadb93a5 Add LTPDA Repository utility functions into utils.repository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
12
9174aadb93a5 Add LTPDA Repository utility functions into utils.repository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
13 % userid
9174aadb93a5 Add LTPDA Repository utility functions into utils.repository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
14 rows = utils.mysql.execute(conn, 'SELECT id FROM users WHERE username = ?', username);
9174aadb93a5 Add LTPDA Repository utility functions into utils.repository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
15 if isempty(rows)
9174aadb93a5 Add LTPDA Repository utility functions into utils.repository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
16 error('### could not determine user id');
9174aadb93a5 Add LTPDA Repository utility functions into utils.repository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
17 end
9174aadb93a5 Add LTPDA Repository utility functions into utils.repository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
18 userid = rows{1};
9174aadb93a5 Add LTPDA Repository utility functions into utils.repository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
19
9174aadb93a5 Add LTPDA Repository utility functions into utils.repository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
20 end