-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresult2db.m
More file actions
32 lines (29 loc) · 736 Bytes
/
Copy pathresult2db.m
File metadata and controls
32 lines (29 loc) · 736 Bytes
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
function flag = result2db(tablename,colnames,T, varargin)
%% create connection
% since we are adding one row at a time, we leave the autocommit setting on
conn = varargin_parse(varargin,'conn', dbconn());
%% insert data
pause('on')
flag = true;
if ~isstruct(T)
try
pause(randi(10)*1e-2)
datainsert(conn,tablename,colnames,vertcat(T{:}));
catch
try
pause(randi(10)*1e-2)
datainsert(conn,tablename,colnames,vertcat(T{:}));
catch
flag = false;
end
end
else
for f = fieldnames(T).'
flag_tmp = result2db(tablename.(f{1}), colnames.(f{1}), {T.(f{1})}, 'conn', conn);
flag = flag && flag_tmp;
end
end
%% close connection
if ~any(strcmp(varargin, 'conn'))
close(conn)
end