0
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1 % CB_GET_DBS callback when the user clicks the 'get dbs' button.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
3 % M Hewitson 22-09-08
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
4 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
5 % $Id: cb_get_dbs.m,v 1.2 2011/04/08 08:56:36 hewitson Exp $
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
6 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
7
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
8 function cb_get_dbs(varargin)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
9
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
10 % Handles
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
11 myh = varargin{1};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
12 mainfig = varargin{end};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
13
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
14 tables = {'collections', 'objmeta', 'objs', 'transactions', 'users'};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
15
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
16 % Get conn
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
17 conn = mainfig.connection;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
18 % Assume I don't need to open the connection
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
19 wasEmpty = 0;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
20
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
21 % Open connection, if necessary
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
22 if isempty(conn)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
23
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
24 % we opened the connection
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
25 wasEmpty = 1;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
26
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
27 % have we a stored username and password
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
28 dbuser = mainfig.dbuser;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
29 dbpass = mainfig.dbpass;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
30
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
31 % get hostname
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
32 hostname = get(findobj(mainfig.handle, 'Tag','RepoguiServerEdit'), 'String');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
33 if isempty(hostname)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
34 error('### Please select a server to connect to.');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
35 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
36
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
37 % connect
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
38 if ~isempty(dbuser) && ~isempty(dbpass)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
39 conn = utils.mysql.connect(hostname, 'test', dbuser, dbpass);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
40 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
41 [conn, dbpass] = utils.mysql.connect(hostname);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
42 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
43 if ~isa(conn, 'database')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
44 error('### couldn''t connect to server');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
45 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
46
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
47 % store the connection
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
48 mainfig.dbuser = conn.Username;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
49 mainfig.dbpass = dbpass;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
50
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
51 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
52
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
53 % get the databases
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
54 q = 'show databases';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
55 curs = exec(conn, q);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
56 curs = fetch(curs);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
57
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
58 ltpda_dbs = [];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
59 % Now get the LTPDA databases
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
60 for j=1:length(curs.Data)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
61 db = curs.Data{j};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
62
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
63 if ~strcmp(db, 'information_schema')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
64
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
65 q = sprintf('show tables from %s', db);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
66 c = exec(conn, q);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
67 c = fetch(c);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
68 match = 0;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
69 for l=1:length(c.Data)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
70 for k=1:length(tables)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
71 if strcmp(c.Data{l}, tables{k})
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
72 match = match + 1;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
73 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
74 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
75 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
76 close(c);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
77 if match == 5
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
78 % we have an LTPDA database
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
79 ltpda_dbs = [ltpda_dbs cellstr(db)];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
80 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
81 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
82
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
83 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
84 close(curs);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
85
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
86 % If I opened the connection, close it again
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
87 if wasEmpty
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
88 close(conn);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
89 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
90
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
91 % Set the list
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
92 id = findobj(mainfig.handle, 'Tag', 'RepoguiDatabaseList');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
93 set(id, 'String', ltpda_dbs, 'Value', 1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
94
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
95 % Get selected DB
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
96 dbh = findobj(mainfig.handle, 'Tag', 'RepoguiDatabaseList');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
97 dbs = get(dbh, 'String');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
98 db = dbs{1};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
99
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
100 % set selected DB
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
101 dbh = findobj(mainfig.handle, 'Tag', 'RepoguiDatabaseEdit');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
102 set(dbh, 'String', db);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
103
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
104 end
|