Home > database > mysql_describe_table.m

mysql_describe_table

PURPOSE ^

Returns a description of the given mysql table.

SYNOPSIS ^

function tbl = mysql_describe_table(table, conn_id, params)

DESCRIPTION ^

 Returns a description of the given mysql table.

 tbl = mysql_describe_table(table, conn_id);

 Fields are those returned by the SQL DESCRIBE command

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function tbl = mysql_describe_table(table, conn_id, params)
0002 % Returns a description of the given mysql table.
0003 %
0004 % tbl = mysql_describe_table(table, conn_id);
0005 %
0006 % Fields are those returned by the SQL DESCRIBE command
0007 %
0008 
0009 % 01/26/07 Petr Janata
0010 % 06/15/10 PJ sanitized mysql_make_conn
0011 
0012 % Check for connection to database
0013 try conn_id(1);
0014 catch   
0015   if exist('params','var')
0016     tmp_conn_id = 1;
0017     if ~isfield(params,'conn_id')
0018       params.conn_id = 0;
0019     end
0020     conn_id = mysql_make_conn(params);
0021   else
0022     error('%s: No valid conn_id provided', mfilename)
0023   end
0024 end
0025 
0026 [tbl.flds,tbl.types,tbl.null, tbl.key,tbl.default,tbl.extra] = ...
0027     mysql(conn_id,sprintf('DESCRIBE %s', table));
0028 
0029 % Close the database connection if it was temporary
0030 if (exist('tmp_conn_id','var'))
0031   mysql(conn_id,'close');
0032 end

Generated on Wed 20-Mar-2019 04:00:51 by m2html © 2003