static const struct casereader_class proc_casereader_class;
-/* Opens dataset DS for reading cases with proc_read.
+/* Opens dataset DS for reading cases with proc_read. If FILTER is true, then
+ cases filtered out with FILTER BY will not be included in the casereader
+ (which is usually desirable). If FILTER is false, all cases will be
+ included regardless of FILTER BY settings.
+
proc_commit must be called when done. */
struct casereader *
-proc_open (struct dataset *ds)
+proc_open_filtering (struct dataset *ds, bool filter)
{
struct casereader *reader;
/* Finish up the collection of transformations. */
add_case_limit_trns (ds);
- add_filter_trns (ds);
+ if (filter)
+ add_filter_trns (ds);
trns_chain_finalize (ds->cur_trns_chain);
/* Make permanent_dict refer to the dictionary right before
return reader;
}
+/* Opens dataset DS for reading cases with proc_read.
+ proc_commit must be called when done. */
+struct casereader *
+proc_open (struct dataset *ds)
+{
+ return proc_open_filtering (ds, true);
+}
+
/* Returns true if a procedure is in progress, that is, if
proc_open has been called but proc_commit has not. */
bool
/* PSPP - a program for statistical analysis.
- Copyright (C) 1997-9, 2000, 2006, 2007, 2009 Free Software Foundation, Inc.
+ Copyright (C) 1997-9, 2000, 2006, 2007, 2009, 2010 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
bool proc_execute (struct dataset *ds);
time_t time_of_last_procedure (struct dataset *ds);
+struct casereader *proc_open_filtering (struct dataset *, bool filter);
struct casereader *proc_open (struct dataset *);
bool proc_is_open (const struct dataset *);
bool proc_commit (struct dataset *);
/* PSPP - a program for statistical analysis.
- Copyright (C) 1997-9, 2000, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
+ Copyright (C) 1997-9, 2000, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
enum writer_type writer_type)
{
bool retain_unselected;
- struct variable *saved_filter_variable;
struct casewriter *output;
bool ok;
if (output == NULL)
return CMD_CASCADING_FAILURE;
- saved_filter_variable = dict_get_filter (dataset_dict (ds));
- if (retain_unselected)
- dict_set_filter (dataset_dict (ds), NULL);
-
- casereader_transfer (proc_open (ds), output);
+ casereader_transfer (proc_open_filtering (ds, !retain_unselected), output);
ok = casewriter_destroy (output);
ok = proc_commit (ds) && ok;
- dict_set_filter (dataset_dict (ds), saved_filter_variable);
-
return ok ? CMD_SUCCESS : CMD_CASCADING_FAILURE;
}
TESTSUITE_AT = \
tests/data/calendar.at \
tests/language/data-io/data-list.at \
+ tests/language/data-io/save.at \
tests/language/dictionary/mrsets.at \
tests/language/expressions/evaluate.at \
tests/language/stats/aggregate.at \
--- /dev/null
+AT_BANNER([SAVE])
+
+# UNSELECTED=DELETE used to cause a crash if there was actually a
+# filter variable.
+AT_SETUP([SAVE -- delete unselected])
+AT_DATA([data.txt], [dnl
+0 '1 9:30:05' 1/2/2003 "25/8/1995 15:30:00" "'a,b,c'",0
+, '-0 5:17' 10/31/2010 "9/4/2008 9:29:00" " xxx ",1
+1.625,'0 12:00',,,xyzzy,1
+])
+AT_DATA([save.pspp], [dnl
+SET DECIMAL=DOT.
+DATA LIST LIST NOTABLE FILE="data.txt"
+ /number(F8.3) time(DTIME10) date(ADATE10) datetime(DATETIME20) string(A8)
+ filter(F1.0).
+MISSING VALUES number(0) time('0 12:00') string('xyzzy').
+FILTER BY filter.
+SAVE /OUTFILE="data.sav" /UNSELECTED=DELETE.
+])
+AT_DATA([get.pspp], [dnl
+GET FILE='data.sav'.
+LIST.
+])
+AT_CHECK([pspp -O format=csv save.pspp])
+AT_CHECK([pspp -O format=csv get.pspp], [0], [dnl
+Table: Data List
+number,time,date,datetime,string,filter
+. ,-0 05:17,10/31/2010,09-APR-2008 09:29:00,xxx ,1
+1.625,0 12:00:00,.,.,xyzzy ,1
+])
+AT_CLEANUP