Home > FMAToolbox > Database > DBRemoveVariables.m

DBRemoveVariables

PURPOSE ^

DBRemoveVariables - Remove all variables that match given criteria.

SYNOPSIS ^

function DBRemoveVariables(query)

DESCRIPTION ^

DBRemoveVariables - Remove all variables that match given criteria.

  Actual removal will require confirmation from the user.

  USAGE

    DBRemoveVariables(query)

    query          optional figure list query (WHERE clause; see Example)

  SEE

    See also DBAddVariable, DBGetVariables, DBRemove.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function DBRemoveVariables(query)
0002 
0003 %DBRemoveVariables - Remove all variables that match given criteria.
0004 %
0005 %  Actual removal will require confirmation from the user.
0006 %
0007 %  USAGE
0008 %
0009 %    DBRemoveVariables(query)
0010 %
0011 %    query          optional figure list query (WHERE clause; see Example)
0012 %
0013 %  SEE
0014 %
0015 %    See also DBAddVariable, DBGetVariables, DBRemove.
0016 %
0017 
0018 % Copyright (C) 2007-2016 by Michaƫl Zugaro
0019 %
0020 % This program is free software; you can redistribute it and/or modify
0021 % it under the terms of the GNU General Public License as published by
0022 % the Free Software Foundation; either version 3 of the License, or
0023 % (at your option) any later version.
0024 
0025 % Make sure MyM is installed and functional
0026 CheckMyM;
0027 
0028 % Optional query provided?
0029 if nargin == 0,
0030     query = '';
0031 end
0032 
0033 % Edit query
0034 query = strtrim(query);
0035 query = regexprep(query,'^where','');
0036 if ~isempty(query), query = [' where ' query]; end
0037 
0038 % Get database name
0039 database = DBUse;
0040 
0041 % Query database
0042 f = mym(['select eid,name from variables' query]);
0043 
0044 % Make sure query results are not empty
0045 if isempty(f.eid),
0046     if isempty(query),
0047         warning(['No variables in ''' database '''.']);
0048     else
0049         warning(['No variables match (' query ').']);
0050     end
0051     return
0052 end
0053 
0054 % Print warning and display variables to remove
0055 disp(' ');
0056 disp(['This would remove the following variables from ''' database ''':']);
0057 DBDisplay(f);
0058 
0059 % Confirm
0060 s = lower(input('Type ''remove'' to confirm: ','s'));
0061 if ~strcmp(s,'remove'),
0062     disp('*** Cancelled ***');
0063     return
0064 end
0065 
0066 % Remove variables from external storage if necessary
0067 storage = DBExternalStoragePath;
0068 targetDirectory = [storage '/' database '/variables'];
0069 for i = 1:length(f.eid),
0070     matFile = [targetDirectory '/' f.eid{i} '-' f.name{i} '.mat'];
0071     if ~exist(matFile,'file'),
0072         warning(['External storage file for (' f.eid{i} ',' f.name{i} ') is missing.']); 
0073     else
0074         delete(matFile);
0075     end
0076 end
0077 
0078 % Remove
0079 mym(['delete from variables' query]);
0080 disp('Variables removed.');
0081

Generated on Fri 16-Mar-2018 13:00:20 by m2html © 2005