comparison m-toolbox/classes/@repogui2/cb_connect.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 % CB_CONNECT callback when the user clicks connect button.
2 %
3 % M Hewitson 22-09-08
4 %
5 % $Id: cb_connect.m,v 1.3 2011/04/08 08:56:36 hewitson Exp $
6 %
7
8 function cb_connect(varargin)
9
10 myh = varargin{1};
11 mainfig = varargin{end};
12 status = findobj(mainfig.handle, 'Tag', 'RepoguiStatusTxt');
13 panels = mainfig.panels;
14
15 % Get conn
16 conn = mainfig.connection;
17
18 if isempty(conn)
19
20 % get hostname
21 hostname = get(findobj(mainfig.handle, 'Tag','RepoguiServerEdit'), 'String');
22
23 % get the database
24 db = get(findobj(mainfig.handle, 'Tag','RepoguiDatabaseEdit'), 'String');
25
26 if isempty(db)
27 error('### Please select a database first.');
28 end
29
30 % check for username and password
31 dbuser = mainfig.dbuser;
32 dbpass = mainfig.dbpass;
33
34 % connect
35 if ~isempty(dbpass) && ~isempty(dbuser)
36 conn = utils.mysql.connect(hostname, db, dbuser, dbpass);
37 else
38 [conn, dbpass] = utils.mysql.connect(hostname, db);
39 end
40 if isa(conn, 'database')
41 mainfig.connection = conn;
42 mainfig.username = conn.Username;
43 set(myh, 'String', 'disconnect');
44 set(status, 'String', sprintf('connected to %s on %s as %s', db, hostname, conn.Username));
45
46 % Set tables on query panel
47 buildConditions(mainfig);
48
49 % store the connection
50 mainfig.dbuser = conn.Username;
51 mainfig.dbpass = dbpass;
52 else
53 set(status, 'String', 'not connected');
54 error('Invalid connection.');
55 end
56 else
57 % disconnect
58 close(conn);
59 conn = [];
60 disp('* disconnected.');
61 mainfig.connection = conn;
62 mainfig.username = '';
63 set(myh, 'String', 'connect');
64 set(status, 'String', 'not connected');
65 mainfig.dbuser = '';
66 mainfig.dbpass = '';
67 end
68
69 end