1 | function[size] = tbsize(table,varargin) |
---|
2 | % TBSIZE Show size of a MySQL table |
---|
3 | % INPUTS : TABLE - table name, string |
---|
4 | % DIM - dimension, 1 or 2 (optional, both rows and columns |
---|
5 | % counted by default |
---|
6 | % OUTPUTS : SIZE - dimension length(s), scalar or (1 x 2) vector |
---|
7 | % EXAMPLE : [r,c] = tbsize('mytb') |
---|
8 | % NOTES : Use DBASE.TABLE syntax to refer to a table not in the current |
---|
9 | % database |
---|
10 | % AUTHOR : Dimitri Shvorob, dimitri.shvorob@vanderbilt.edu, 8/7/06 |
---|
11 | error(nargchk(1,2,nargin)) |
---|
12 | if ~mycheck |
---|
13 | error('No MySQL instance detected. Use MYOPEN to connect.') |
---|
14 | end |
---|
15 | if nargin > 1 |
---|
16 | d = varargin{1}; |
---|
17 | if ~isscalar(d) || ~(d == 1 || d == 2) |
---|
18 | error('Invalid DIM argument.') |
---|
19 | end |
---|
20 | else |
---|
21 | d = 3; |
---|
22 | end |
---|
23 | try |
---|
24 | switch d |
---|
25 | case 1, size = getrows(table); |
---|
26 | case 2, size = getcols(table); |
---|
27 | case 3, size = [getrows(table) getcols(table)]; |
---|
28 | end |
---|
29 | catch |
---|
30 | error(['Table ' table ' not found. Use TBLIST to list available tables.']) |
---|
31 | end |
---|
32 | |
---|
33 | |
---|
34 | function[r] = getrows(table) |
---|
35 | r = mym(['select count(*) from ' table]'); |
---|
36 | |
---|
37 | function[c] = getcols(table) |
---|
38 | [a,b,c,d,e,f] = mym(['describe ' table]); %#ok |
---|
39 | c = length(a); |
---|