Mercurial > hg > ltpda
view m-toolbox/classes/+utils/@mysql/insert.m @ 44:409a22968d5e default
Add unit tests
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Tue, 06 Dec 2011 18:42:11 +0100 |
parents | f0afece42f48 |
children |
line wrap: on
line source
% INSERT inserts values into a single row of a table using JDBC driver % specified by the input connection. % % Usage: message = insert(conn, table, 'field1', value1, 'field2', value2,...) % % M Hewitson % % 31-07-07 % % $Id: insert.m,v 1.6 2010/01/22 12:46:08 ingo Exp $ % function message = insert(conn, table, varargin) error('### Obsolete as of LTPDA version 2.2. Replaced my the utils class jmysql (utils.jmysql.%s)', mfilename()); q = sprintf('INSERT INTO %s SET ', table); for j=1:2:length(varargin) col = varargin{j}; val = varargin{j+1}; if isnumeric(val) if ~any(isnan(val)) q = [q col '=' num2str(val) ',']; end elseif ischar(val) q = [q col '=' '''' val '''' ',']; else error('### val class [%s]', class(val)) end end q = deblank([q(1:end-1) ';']); utils.helper.msg(utils.const.msg.PROC1, 'running query %s', q); try curs = exec(conn, q); message = curs.Message; close(curs); catch error('### insert: failed to execute query: %s\nServer returned %s', q, curs.Message); end end