|
43 | 43 |
|
44 | 44 | % Show databases
|
45 | 45 | function databases = databases(obj)
|
46 |
| - url = [obj.Url '/query']; |
47 |
| - opts = weboptions('Timeout', obj.ReadTimeout, ... |
48 |
| - 'Username', obj.User, 'Password', obj.Password); |
49 |
| - response = webread(url, 'q', 'SHOW DATABASES', opts); |
| 46 | + response = obj.runCommand('SHOW DATABASES'); |
50 | 47 | databases = [response.results.series.values{:}];
|
51 | 48 | end
|
52 | 49 |
|
|
108 | 105 | end
|
109 | 106 |
|
110 | 107 | % Execute other queries or commands
|
111 |
| - function response = runCommand(obj, command, requiresPost) |
| 108 | + function response = runCommand(obj, command, varargin) |
| 109 | + idx = find(cellfun(@(x) ischar(x), varargin), 1, 'first'); |
| 110 | + database = iif(isempty(idx), '', varargin{idx}); |
| 111 | + idx = find(cellfun(@(x) islogical(x), varargin), 1, 'first'); |
| 112 | + requiresPost = iif(isempty(idx), false, varargin{idx}); |
| 113 | + if isempty(database) |
| 114 | + params = {'q', command}; |
| 115 | + else |
| 116 | + params = {'db', database, 'q', command}; |
| 117 | + end |
112 | 118 | url = [obj.Url '/query'];
|
113 | 119 | opts = weboptions('Username', obj.User, 'Password', obj.Password);
|
114 |
| - if nargin > 2 && requiresPost |
| 120 | + if requiresPost |
115 | 121 | opts.Timeout = obj.WriteTimeout;
|
116 |
| - response = webwrite(url, 'q', command, opts); |
| 122 | + response = webwrite(url, params{:}, opts); |
117 | 123 | else
|
118 | 124 | opts.Timeout = obj.ReadTimeout;
|
119 |
| - response = webread(url, 'q', command, opts); |
| 125 | + response = webread(url, params{:}, opts); |
120 | 126 | end
|
121 | 127 | end
|
122 | 128 | end
|
|
0 commit comments