source: MML/trunk/applications/database/mym/utilities/tbsize.m @ 4

Last change on this file since 4 was 4, checked in by zhangj, 11 years ago

Initial import--MML version from SOLEIL@2013

File size: 1.1 KB
Line 
1function[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
11error(nargchk(1,2,nargin))
12if ~mycheck
13   error('No MySQL instance detected. Use MYOPEN to connect.')
14end
15if nargin > 1
16   d = varargin{1};
17   if ~isscalar(d) || ~(d == 1 || d == 2)
18      error('Invalid DIM argument.')
19   end
20else
21   d = 3;
22end
23try
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   
29catch
30  error(['Table ' table ' not found. Use TBLIST to list available tables.'])
31end
32 
33
34function[r] = getrows(table)
35r = mym(['select count(*) from ' table]');
36
37function[c] = getcols(table)
38[a,b,c,d,e,f] = mym(['describe ' table]);    %#ok
39c = length(a);
Note: See TracBrowser for help on using the repository browser.