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.6 2008/03/11 14:33:51 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.6 2008/03/11 14:33:51 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 % Assume I don't need to open the connection
0018 wasEmpty = 0;
0019 
0020 % Open connection, if necessary
0021 if isempty(conn)  
0022   
0023   % we opened the connection
0024   wasEmpty = 1;
0025   
0026   % have we a stored username and password
0027   dbuser = getappdata(mainfig, 'dbuser');
0028   dbpass = getappdata(mainfig, 'dbpass');
0029     
0030   % get hostname
0031   hostname = get(findobj('Tag','serverTxt'), 'String');
0032   
0033   % connect
0034   if ~isempty(dbuser) && ~isempty(dbpass)
0035     conn = mysql_connect(hostname, 'test', dbuser, dbpass);
0036   else
0037     [conn, dbpass] = mysql_connect(hostname);
0038   end
0039   if ~isa(conn, 'database')
0040     error('# couldn''t connect to server');
0041   end
0042   
0043   % store the connection
0044   setappdata(mainfig, 'dbuser', conn.Username);
0045   setappdata(mainfig, 'dbpass', dbpass);
0046   
0047 %
0048 %   % update the connect button and status string
0049 %   status  = findobj('Tag', 'statusTxt');
0050 %   connBtn = findobj('Tag', 'connectBtn');
0051 %   set(connBtn, 'String', 'disconnect');
0052 %   set(status, 'String', sprintf('connected to %s on %s as %s', db, hostname, conn.Username));
0053   
0054 end
0055 
0056 % get the databases
0057 q = 'show databases';
0058 curs = exec(conn, q);
0059 curs = fetch(curs);
0060 
0061 ltpda_dbs = [];
0062 % Now get the LTPDA databases
0063 for j=1:length(curs.Data)
0064   db = curs.Data{j};
0065   
0066   if ~strcmp(db, 'information_schema')
0067     
0068     q = sprintf('show tables from %s', db);
0069     c = exec(conn, q);
0070     c = fetch(c);
0071     match = 0;
0072     for l=1:length(c.Data)
0073       for k=1:length(tables)
0074         if strcmp(c.Data{l}, tables{k})
0075           match = match + 1;
0076         end
0077       end
0078     end
0079     close(c);
0080     if match == 5
0081       % we have an LTPDA database
0082       ltpda_dbs = [ltpda_dbs cellstr(db)];
0083     end    
0084   end
0085   
0086 end
0087 close(curs);
0088 
0089 % If I opened the connection, close it again
0090 if wasEmpty
0091   close(conn);
0092 end
0093 
0094 % Set the list
0095 id = findobj('Tag', 'dbSelect');
0096 set(id, 'String', ltpda_dbs, 'Value', 1);
0097 
0098 % Get selected DB
0099 dbh = findobj('Tag', 'dbSelect');
0100 dbs = get(dbh, 'String');
0101 db  = dbs{1};
0102 
0103 % set selected DB
0104 dbh = findobj('Tag', 'databaseTxt');
0105 set(dbh, 'String', db);
0106 
0107 
0108

Generated on Mon 08-Sep-2008 13:18:47 by m2html © 2003