This repository was archived by the owner on Jan 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdbDeleteExperiment.m
More file actions
62 lines (52 loc) · 1.48 KB
/
dbDeleteExperiment.m
File metadata and controls
62 lines (52 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
function dbDeleteExperiment(expId,dryrun)
% Deletes experimental data from DB.
%
% DBDELETEEXPERIMENT(EXPERIMENT_ID) to delete experiment
% or
% DBDELETEEXPERIMENT(EXPERIMENT_ID,1) to show SQL statements as dry experiment.
if nargin<2
dryrun=0;
end
% Check experiment exists and is owned by user.
user = dbGuessUser();
conn = dbOpen();
sql = sprintf(['SELECT experiment.name,file FROM experiment JOIN user ON user_id=user.id '...
'WHERE initials=' interpString('s') ' AND experiment.id=%d;'],user, ...
expId);
results = table2cell(fetch(conn.conn,sql));
if isempty(results)
error('You have no experiment with id %d',expId);
end
row = results(1,:);
name = row{1};
trajPath = row{2};
% Check if runs exist using this data.
sql = sprintf('SELECT run.id FROM run WHERE experiment_id=%d;',expId);
results = table2cell(fetch(conn.conn,sql));
if ~isempty(results)
disp(['Runs exist using this experiment: ' num2str(cell2mat(results(:)))]);
disp('Delete these runs first.');
return
end
% Delete the experiment.
reply = input(['Really delete experiment ' name '? (y/n): '],'s');
if isempty(reply) || reply(1) ~= 'y'
disp('Aborted.');
return
end
% Delete data.
global dbdatapath;
trajPath = fullfile(dbdatapath,trajPath);
dataPath = fileparts(trajPath);
cmd = sprintf('rm -rf %s',dataPath);
if dryrun
disp(cmd);
else
system(cmd);
end
sql = sprintf('DELETE FROM experiment WHERE id = %d;',expId);
if dryrun
disp(sql);
else
dbCheck(exec(conn.conn,sql));
end