annotate m-toolbox/classes/+utils/@repository/getUser.m @ 35:4be5f7a5316f database-connection-manager

Suppress output messages on preferences loading and saving
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Mon, 05 Dec 2011 16:20:06 +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