diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/m-toolbox/classes/+utils/@mysql/insert.m	Wed Nov 23 19:22:13 2011 +0100
@@ -0,0 +1,47 @@
+% 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
+