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.4 2008/02/25 11:54:20 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.4 2008/02/25 11:54:20 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   % get hostname
0021   hostname = get(findobj('Tag','serverTxt'), 'String');
0022   
0023   % connect
0024   conn = mysql_connect(hostname);
0025   if ~isa(conn, 'database')
0026     error('# couldn''t connect to server');
0027   end
0028 end
0029 
0030 % get the databases
0031 q = 'show databases';
0032 curs = exec(conn, q);
0033 curs = fetch(curs);
0034 
0035 ltpda_dbs = [];
0036 % Now get the LTPDA databases
0037 for j=1:length(curs.Data)
0038   db = curs.Data{j};
0039   
0040   if ~strcmp(db, 'information_schema')
0041     
0042     q = sprintf('show tables from %s', db);
0043     c = exec(conn, q);
0044     c = fetch(c);
0045     match = 0;
0046     for l=1:length(c.Data)
0047       for k=1:length(tables)
0048         if strcmp(c.Data{l}, tables{k})
0049           match = match + 1;
0050         end
0051       end
0052     end
0053     close(c);
0054     if match == 5
0055       % we have an LTPDA database
0056       ltpda_dbs = [ltpda_dbs cellstr(db)];
0057     end    
0058   end
0059   
0060 end
0061 close(curs);
0062 
0063 % Set the list
0064 id = findobj('Tag', 'dbSelect');
0065 set(id, 'String', ltpda_dbs, 'Value', 1);
0066 
0067 % Get selected DB
0068 dbh = findobj('Tag', 'dbSelect');
0069 dbs = get(dbh, 'String');
0070 db  = dbs{1};
0071 
0072 % set selected DB
0073 dbh = findobj('Tag', 'databaseTxt');
0074 set(dbh, 'String', db);
0075 
0076 
0077

Generated on Tue 26-Feb-2008 10:52:52 by m2html © 2003