Home > m > gui > ltpdaRepoGUI > callbacks > cb_getDBs.m

cb_getDBs

PURPOSE ^

Callback executed when the user clicks the 'Get DBs' button

SYNOPSIS ^

function cb_getDBs(varargin)

DESCRIPTION ^

 Callback executed when the user clicks the 'Get DBs' button
 
 M Hewitson
 
 $Id: cb_getDBs.m,v 1.5 2008/03/02 11:51:08 hewitson Exp $

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function cb_getDBs(varargin)
0002 
0003 % Callback executed when the user clicks the 'Get DBs' button
0004 %
0005 % M Hewitson
0006 %
0007 % $Id: cb_getDBs.m,v 1.5 2008/03/02 11:51:08 hewitson Exp $
0008 %
0009 
0010 myh     = varargin{1};
0011 mainfig = varargin{4};
0012 
0013 tables = {'collections', 'objmeta', 'objs', 'transactions', 'users'};
0014 
0015 % Get conn
0016 conn = getappdata(mainfig, 'connection');
0017 
0018 if isempty(conn)
0019   
0020   % have we a stored username and password
0021   dbuser = getappdata(mainfig, 'dbuser');
0022   dbpass = getappdata(mainfig, 'dbpass');
0023     
0024   % get hostname
0025   hostname = get(findobj('Tag','serverTxt'), 'String');
0026   
0027   % connect
0028   if ~isempty(dbuser) && ~isempty(dbpass)
0029     conn = mysql_connect(hostname, 'test', dbuser, dbpass);
0030   else
0031     [conn, dbpass] = mysql_connect(hostname);
0032   end
0033   if ~isa(conn, 'database')
0034     error('# couldn''t connect to server');
0035   end
0036   
0037   % store the connection
0038   setappdata(mainfig, 'dbuser', conn.Username);
0039   setappdata(mainfig, 'dbpass', dbpass);
0040   
0041 %
0042 %   % update the connect button and status string
0043 %   status  = findobj('Tag', 'statusTxt');
0044 %   connBtn = findobj('Tag', 'connectBtn');
0045 %   set(connBtn, 'String', 'disconnect');
0046 %   set(status, 'String', sprintf('connected to %s on %s as %s', db, hostname, conn.Username));
0047   
0048 end
0049 
0050 % get the databases
0051 q = 'show databases';
0052 curs = exec(conn, q);
0053 curs = fetch(curs);
0054 
0055 ltpda_dbs = [];
0056 % Now get the LTPDA databases
0057 for j=1:length(curs.Data)
0058   db = curs.Data{j};
0059   
0060   if ~strcmp(db, 'information_schema')
0061     
0062     q = sprintf('show tables from %s', db);
0063     c = exec(conn, q);
0064     c = fetch(c);
0065     match = 0;
0066     for l=1:length(c.Data)
0067       for k=1:length(tables)
0068         if strcmp(c.Data{l}, tables{k})
0069           match = match + 1;
0070         end
0071       end
0072     end
0073     close(c);
0074     if match == 5
0075       % we have an LTPDA database
0076       ltpda_dbs = [ltpda_dbs cellstr(db)];
0077     end    
0078   end
0079   
0080 end
0081 close(curs);
0082 close(conn);
0083 
0084 % Set the list
0085 id = findobj('Tag', 'dbSelect');
0086 set(id, 'String', ltpda_dbs, 'Value', 1);
0087 
0088 % Get selected DB
0089 dbh = findobj('Tag', 'dbSelect');
0090 dbs = get(dbh, 'String');
0091 db  = dbs{1};
0092 
0093 % set selected DB
0094 dbh = findobj('Tag', 'databaseTxt');
0095 set(dbh, 'String', db);
0096 
0097 
0098

Generated on Fri 07-Mar-2008 15:46:43 by m2html © 2003