Skip to content

Commit 67faa89

Browse files
committed
Allow blank table data for sqlwrite (Issue #11)
* inst/@octave_sqlite/sqlwrite.m: check if data is empty, add empty bist test
1 parent 7c96133 commit 67faa89

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

inst/@octave_sqlite/sqlwrite.m

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,9 @@ function sqlwrite (db, tablename, data, varargin)
181181
execute(db, tsql);
182182
endif
183183

184-
execute(db, sql);
184+
if ! isempty(data)
185+
execute(db, sql);
186+
endif
185187

186188
endfunction
187189

@@ -247,3 +249,21 @@ function sqlwrite (db, tablename, data, varargin)
247249
%! delete(testfile);
248250
%! endif
249251
%! end_unwind_protect
252+
253+
%!test
254+
%! testfile = tempname;
255+
%! t = dbtable([],[], 'VariableNames', {'Id','Name'});
256+
%! unwind_protect
257+
%! db = sqlite(testfile, "create");
258+
%! sqlwrite(db, "Test", t);
259+
%! data = sqlread(db, 'Test');
260+
%! assert(size(data), [0 2]);
261+
%! close(db);
262+
%!
263+
%! unwind_protect_cleanup
264+
%! db = 0;
265+
%!
266+
%! if exist(testfile, "file")
267+
%! delete(testfile);
268+
%! endif
269+
%! end_unwind_protect

0 commit comments

Comments
 (0)