function [affected,insertid] = sqlinsert(table,varargin);

%SQLINSERT - insert records into an SQL database
%
%    [AFFECTED,INSERTID] = SQLINSERT (TABLE,'valuename',value,...);
%
%    See also: MYSQL

%-----------------------------------
% BUILD QUERY
%-----------------------------------

sqlc = ['INSERT INTO ', table, '('];

for k = 1:2:(length(varargin) - 2)
	sqlc = [sqlc, varargin{k}, ','];
end

k = length(varargin) - 1;

sqlc = [sqlc, varargin{k}, ') VALUES ('];

for k = 2:2:(length(varargin) - 2)
	
	if ischar(varargin{k}),
		sqlc = [sqlc, '"', varargin{k}, '"' ','];
	else
		sqlc = [sqlc, num2str(varargin{k}), ','];
	end
	
end

k = length(varargin);

if ischar(varargin{k})
	sqlc = [sqlc, '"', varargin{k}, '"' ')'];
else
	sqlc = [sqlc, num2str(varargin{k},20), ')'];
end

%% DEBUG

%--
% display string
%--

disp(' '); disp(sqlc);

return;

%-----------------------------------
% EXECUTE QUERY
%-----------------------------------

[res,affected,insertid] = mysql(sqlc);
