Why do i receive the error 'Too many output arguments' when using sqlite/exec command
Mostrar comentarios más antiguos
I'am trying to import and export data to a sqlite-database. Data export is possible via fetch-command and sqlquery. I expected that's possible to do the same work via exec-command (getting an cursor object and then do the fetch-command).
But always when using exec-command while assign the output to a variable, I'm getting the 'Too many output arguments' error.
(I can't use fetch because later I want execute the SQL command 'PRAGMA table_info(table_name)' )
The attached example shows the working fetch-only solution and the not working exec-solution.
- Matlab 2017a
- database/sqlite toolbox
%%open/ create sqlite databse
try
if exist(filename)==0
db_connect=sqlite(filename,'create');
else
db_connect=sqlite(filename,'connect');
end
catch exc
display([datestr(datetime('now')) ': ' exc.identifier]);
success = false;
close (db_connect);
return;
end
% data definition
tablename='TestTable';
col_names ={'a','b'}; % column header
data = {1 , 2}; % data
data_table = cell2table(data,'VariableNames',col_names);
%%create sql table
try
exec(db_connect,['create table ' tablename ...
'(' col_names{1} ' NUMERIC, ' col_names{2} ' NUMERIC)']);
catch exc
disp('...table already exists');
end
% insert data in sql table
insert(db_connect,tablename,col_names,data_table);
% extract dat from table via fetch
try
x=fetch(db_connect,['SELECT * FROM ' tablename]);
disp('fetch success');
catch exc
disp('fetch failed');
error([exc.identifier ':' exc.message]);
close (db_connect);
end
% extract dat from table via exec - fetch
try
curs = exec(db_connect,['SELECT * FROM ' tablename]);
a=fetch(curs);
disp('exec success');
catch exc
disp('exec failed');
disp([exc.identifier ':' exc.message]);
close (db_connect)
end
%%close database
close (db_connect)
2 comentarios
Geoff Hayes
el 1 de Ag. de 2017
Markus - please show the full error message including the line of code that is generating the error. I know that you have said that it is the exec line, but if that is
curs = exec(db_connect,['SELECT * FROM ' tablename]);
Markus Meißner
el 2 de Ag. de 2017
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Import Data Programmatically en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!