Home > m > mysql > ltpda_insert.m

ltpda_insert

PURPOSE ^

LTPDA_INSERT inserts values into a single row of a table using JDBC driver

SYNOPSIS ^

function message = ltpda_insert(conn, table, varargin)

DESCRIPTION ^

 LTPDA_INSERT inserts values into a single row of a table using JDBC driver
 specified by the input connection.
 
 Usage: message = ltpda_insert(conn, table, 'field1', value1, 'field2',
                               value2,...)
 
 M Hewitson
 
 31-07-07
 
 $Id: submit.m,v 1.14 2007/08/16 06:55:25 hewitson Exp $

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function message = ltpda_insert(conn, table, varargin)
0002 
0003 % LTPDA_INSERT inserts values into a single row of a table using JDBC driver
0004 % specified by the input connection.
0005 %
0006 % Usage: message = ltpda_insert(conn, table, 'field1', value1, 'field2',
0007 %                               value2,...)
0008 %
0009 % M Hewitson
0010 %
0011 % 31-07-07
0012 %
0013 % $Id: submit.m,v 1.14 2007/08/16 06:55:25 hewitson Exp $
0014 %
0015 
0016 q = sprintf('INSERT INTO %s(',  table);
0017 for j=1:2:length(varargin)
0018   q = [q varargin{j} ','];
0019 end
0020 q = q(1:end-1);
0021 
0022 q = [q ') VALUES('];
0023 
0024 for j=2:2:length(varargin)
0025   val = varargin{j};
0026   if ischar(val)
0027     q = [q '''' val '''' ','];
0028   elseif isnumeric(val)
0029     q = [q mat2str(val) ','];
0030   else
0031     error('unknown data type');
0032   end
0033   
0034 end
0035 
0036 q = q(1:end-1);
0037 q = [q ');'];
0038 
0039 curs = exec(conn, q);
0040 message = curs.Message;
0041 disp(message);
0042 close(curs);

Generated on Mon 03-Sep-2007 12:12:34 by m2html © 2003