|
26 | 26 |
|
27 | 27 | function kill(restriction, connection, order_by) |
28 | 28 |
|
29 | | -if nargin < 3 |
30 | | - order_by = {}; |
31 | | -end |
| 29 | + if nargin < 3 |
| 30 | + order_by = {}; |
| 31 | + end |
32 | 32 |
|
33 | | -if nargin < 2 |
34 | | - connection = dj.conn; |
35 | | -end |
| 33 | + if nargin < 2 |
| 34 | + connection = dj.conn; |
| 35 | + end |
36 | 36 |
|
37 | | -qstr = 'SELECT * FROM information_schema.processlist WHERE id <> CONNECTION_ID()'; |
| 37 | + qstr = 'SELECT * FROM information_schema.processlist WHERE id <> CONNECTION_ID()'; |
38 | 38 |
|
39 | | -if nargin && ~isempty(restriction) |
40 | | - qstr = sprintf('%s AND (%s)', qstr, restriction); |
41 | | -end |
| 39 | + if nargin && ~isempty(restriction) |
| 40 | + qstr = sprintf('%s AND (%s)', qstr, restriction); |
| 41 | + end |
42 | 42 |
|
43 | | -if isempty(order_by) |
44 | | - qstr = sprintf('%s ORDER BY id', qstr); |
45 | | -else |
46 | | - if iscell(order_by) |
47 | | - qstr = sprintf('%s ORDER BY %s', qstr, strjoin(order_by, ',')); |
| 43 | + if isempty(order_by) |
| 44 | + qstr = sprintf('%s ORDER BY id', qstr); |
48 | 45 | else |
49 | | - qstr = sprintf('%s ORDER BY %s', qstr, order_by); |
| 46 | + if iscell(order_by) |
| 47 | + qstr = sprintf('%s ORDER BY %s', qstr, strjoin(order_by, ',')); |
| 48 | + else |
| 49 | + qstr = sprintf('%s ORDER BY %s', qstr, order_by); |
| 50 | + end |
50 | 51 | end |
51 | | -end |
52 | 52 |
|
53 | | -while true |
54 | | - query(connection, qstr) |
55 | | - id = input('process to kill (''q''-quit, ''a''-all) > ', 's'); |
56 | | - if ischar(id) && strncmpi(id, 'q', 1) |
57 | | - break |
58 | | - elseif ischar(id) && strncmpi(id, 'a', 1) |
59 | | - res = query(connection, qstr); |
60 | | - id = double(res.ID)'; |
61 | | - for i = id |
62 | | - query(connection, 'kill {Si}', i) |
| 53 | + while true |
| 54 | + query(connection, qstr) |
| 55 | + id = input('process to kill (''q''-quit, ''a''-all) > ', 's'); |
| 56 | + if ischar(id) && strncmpi(id, 'q', 1) |
| 57 | + break |
| 58 | + elseif ischar(id) && strncmpi(id, 'a', 1) |
| 59 | + res = query(connection, qstr); |
| 60 | + |
| 61 | + res = cell2struct(struct2cell(res), lower(fieldnames(res))); |
| 62 | + |
| 63 | + id = double(res.id)'; |
| 64 | + for i = id |
| 65 | + query(connection, 'kill {Si}', i) |
| 66 | + end |
| 67 | + break |
| 68 | + end |
| 69 | + id = sscanf(id,'%d'); |
| 70 | + if ~isempty(id) |
| 71 | + query(connection, 'kill {Si}', id(1)) |
63 | 72 | end |
64 | | - break |
65 | | - end |
66 | | - id = sscanf(id,'%d'); |
67 | | - if ~isempty(id) |
68 | | - query(connection, 'kill {Si}', id(1)) |
69 | 73 | end |
| 74 | + |
70 | 75 | end |
0 commit comments