3 # This program tests the psql import feature.
5 TEMPDIR=/tmp/pspp-tst-$$
6 TESTFILE=$TEMPDIR/`basename $0`.sps
8 # ensure that top_srcdir and top_builddir are absolute
9 if [ -z "$top_srcdir" ] ; then top_srcdir=. ; fi
10 if [ -z "$top_builddir" ] ; then top_builddir=. ; fi
11 top_srcdir=`cd $top_srcdir; pwd`
12 top_builddir=`cd $top_builddir; pwd`
14 PSPP=$top_builddir/src/ui/terminal/pspp
16 STAT_CONFIG_PATH=$top_srcdir/config
17 export STAT_CONFIG_PATH
24 PG_CONFIG=${PG_CONFIG:=pg_config}
25 pgpath=`$PG_CONFIG --bindir`
29 if [ x"$PSPP_TEST_NO_CLEANUP" != x ] ; then
30 echo "NOT cleaning $TEMPDIR"
33 PGHOST=$TEMPDIR $pgpath/pg_ctl -D $TEMPDIR/cluster stop -W -o "-k $TEMPDIR -h ''" > /dev/null 2>&1
62 if [ ! -x $pgpath/initdb ] ; then
63 echo 'No Postgres server was found, so the postgres database interface cannot be tested.'
72 activity="create cluster"
73 $pgpath/initdb -D $TEMPDIR/cluster -A trust > /dev/null
74 if [ $? -ne 0 ] ; then no_result ; fi
77 PGHOST=$TEMPDIR PGPORT=$port $pgpath/pg_ctl -D $TEMPDIR/cluster start -w -o "-k $TEMPDIR -h ''" > /dev/null
78 if [ $? -ne 0 ] ; then no_result ; fi
81 activity="create database"
82 $pgpath/createdb -h $TEMPDIR -p $port $dbase > /dev/null 2> /dev/null
83 if [ $? -ne 0 ] ; then no_result ; fi
86 activity="populate database"
87 $pgpath/psql -h $TEMPDIR -p $port $dbase > /dev/null << EOF
89 CREATE TABLE empty (a int, b date, c numeric(23, 4));
91 -- a largeish table to check big queries work ok.
92 CREATE TABLE large (x int);
93 INSERT INTO large (select * from generate_series(1, 1000));
103 numeric numeric(50,6) ,
113 timestamp timestamp ,
114 timestamptz timestamptz ,
119 INSERT INTO thing VALUES (
136 'January 8 04:05:06 1999',
137 'January 8 04:05:06 1999 PST',
142 INSERT INTO thing VALUES (
165 INSERT INTO thing VALUES (
182 '10-Jan-1963 23:58:00',
183 '10-Jan-1963 23:58:00 CET',
184 '2 year 1 month 12 days 1 hours 3 minutes 4 seconds',
188 if [ $? -ne 0 ] ; then fail ; fi
190 activity="create program 1"
191 cat > $TESTFILE <<EOF
193 /CONNECT="host=$TEMPDIR port=$port dbname=$dbase"
195 /SQL="select * from thing".
201 if [ $? -ne 0 ] ; then no_result ; fi
204 activity="run program 1"
205 $SUPERVISOR $PSPP -o pspp.csv $TESTFILE
206 if [ $? -ne 0 ] ; then no_result ; fi
208 activity="compare output 1"
209 diff -c $TEMPDIR/pspp.csv - << 'EOF'
210 Variable,Description,,Position
213 ,Display Alignment: Right,,
215 bytea,Format: AHEX2,,2
217 ,Display Alignment: Left,,
221 ,Display Alignment: Left,,
225 ,Display Alignment: Right,,
229 ,Display Alignment: Right,,
233 ,Display Alignment: Right,,
235 numeric,Format: E40.6,,7
237 ,Display Alignment: Right,,
241 ,Display Alignment: Left,,
245 ,Display Alignment: Right,,
247 float4,Format: F8.2,,10
249 ,Display Alignment: Right,,
251 float8,Format: F8.2,,11
253 ,Display Alignment: Right,,
255 money,Format: DOLLAR8.2,,12
257 ,Display Alignment: Right,,
259 pbchar,Format: A8,,13
261 ,Display Alignment: Left,,
263 varchar,Format: A8,,14
265 ,Display Alignment: Left,,
267 date,Format: DATE11,,15
269 ,Display Alignment: Right,,
271 time,Format: TIME11.0,,16
273 ,Display Alignment: Right,,
275 timestamp,Format: DATETIME22.0,,17
277 ,Display Alignment: Right,,
279 timestamptz,Format: DATETIME22.0,,18
281 ,Display Alignment: Right,,
283 interval,Format: DTIME13.0,,19
285 ,Display Alignment: Right,,
287 interval_months,Format: F3.0,,20
289 ,Display Alignment: Right,,
291 timetz,Format: TIME11.0,,21
293 ,Display Alignment: Right,,
295 timetz_zone,Format: F8.2,,22
297 ,Display Alignment: Right,,
301 bool,bytea,char,int8,int2,int4,numeric,text,oid,float4,float8,money,pbchar,varchar,date,time,timestamp,timestamptz,interval,interval_months,timetz,timetz_zone
302 .00,30,a ,.00,.00,.00,-2.560980E+002,this-long-text ,.00,.00,.00,$.01,a ,A ,01-JAN-2000,0:00:00,08-JAN-1999 04:05:06,08-JAN-1999 12:05:06,0 00:01:00,0,10:09:00,4.00
303 . ,20,,. ,. ,. ,. ,,. ,. ,. ,. ,,,.,.,.,.,.,.,.,.
304 1.00,31,b ,1.00,1.00,1.00,6.553500E+004,that-long-text ,.00,1.00,1.00,$1.23,b ,B ,10-JAN-1963,1:05:02,10-JAN-1963 23:58:00,10-JAN-1963 22:58:00,12 01:03:04,25,1:05:02,-7.00
306 if [ $? -ne 0 ] ; then fail ; fi
309 activity="create program 2"
310 cat > $TESTFILE <<EOF
312 /CONNECT="host=$TEMPDIR port=$port dbname=$dbase"
314 /SQL="select * from empty".
320 if [ $? -ne 0 ] ; then no_result ; fi
322 activity="run program 2"
323 $SUPERVISOR $PSPP -o pspp.csv $TESTFILE
324 if [ $? -ne 0 ] ; then no_result ; fi
326 activity="compare output 2"
327 diff -c $TEMPDIR/pspp.csv - << 'EOF'
328 Variable,Description,,Position
331 ,Display Alignment: Right,,
335 ,Display Alignment: Right,,
339 ,Display Alignment: Right,,
342 if [ $? -ne 0 ] ; then fail ; fi
344 activity="create program 3"
345 cat > $TESTFILE <<EOF
347 /CONNECT="host=$TEMPDIR port=$port dbname=$dbase"
350 /SQL="select * from large".
353 COMPUTE diff = x - lag (x).
356 SELECT IF (diff <> 1).
370 if [ $? -ne 0 ] ; then no_result ; fi
372 activity="run program 3"
373 $SUPERVISOR $PSPP -o pspp.csv $TESTFILE
374 if [ $? -ne 0 ] ; then no_result ; fi
376 activity="compare output 3"
377 diff -c $TEMPDIR/pspp.csv - << 'EOF'
396 if [ $? -ne 0 ] ; then fail ; fi
400 # Check for a bug caused by having string variables in the database,
401 # all of which are null.
403 activity="populate database 4"
404 $pgpath/psql -h $TEMPDIR -p $port $dbase > /dev/null << EOF
406 -- a table which has a text field containing only null, or zero
409 CREATE TABLE foo (int4 int4, text text);
411 INSERT INTO foo VALUES ('12', '');
413 INSERT INTO foo VALUES (null, '');
416 if [ $? -ne 0 ] ; then fail ; fi
419 activity="create program 4"
420 cat > $TESTFILE <<EOF
422 /CONNECT="host=$TEMPDIR port=$port dbname=$dbase"
424 /SQL="select * from foo".
430 if [ $? -ne 0 ] ; then no_result ; fi
433 activity="run program 4"
434 $SUPERVISOR $PSPP -o pspp.csv $TESTFILE
435 if [ $? -ne 0 ] ; then no_result ; fi