Mercurial > hg > ltpda
comparison m-toolbox/classes/+utils/@mysql/insert.m @ 0:f0afece42f48
Import.
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Wed, 23 Nov 2011 19:22:13 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f0afece42f48 |
---|---|
1 % INSERT inserts values into a single row of a table using JDBC driver | |
2 % specified by the input connection. | |
3 % | |
4 % Usage: message = insert(conn, table, 'field1', value1, 'field2', value2,...) | |
5 % | |
6 % M Hewitson | |
7 % | |
8 % 31-07-07 | |
9 % | |
10 % $Id: insert.m,v 1.6 2010/01/22 12:46:08 ingo Exp $ | |
11 % | |
12 | |
13 function message = insert(conn, table, varargin) | |
14 | |
15 error('### Obsolete as of LTPDA version 2.2. Replaced my the utils class jmysql (utils.jmysql.%s)', mfilename()); | |
16 | |
17 q = sprintf('INSERT INTO %s SET ', table); | |
18 | |
19 for j=1:2:length(varargin) | |
20 | |
21 col = varargin{j}; | |
22 val = varargin{j+1}; | |
23 if isnumeric(val) | |
24 if ~any(isnan(val)) | |
25 q = [q col '=' num2str(val) ',']; | |
26 end | |
27 elseif ischar(val) | |
28 q = [q col '=' '''' val '''' ',']; | |
29 else | |
30 error('### val class [%s]', class(val)) | |
31 end | |
32 | |
33 end | |
34 | |
35 q = deblank([q(1:end-1) ';']); | |
36 | |
37 utils.helper.msg(utils.const.msg.PROC1, 'running query %s', q); | |
38 | |
39 try | |
40 curs = exec(conn, q); | |
41 message = curs.Message; | |
42 close(curs); | |
43 catch | |
44 error('### insert: failed to execute query: %s\nServer returned %s', q, curs.Message); | |
45 end | |
46 end | |
47 |