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 | awk '/BINDIR/{print $3}'`
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
61 if [ ! -x $pgpath/initdb ] ; then
62 echo 'No Postgres server was found, so the postgres database interface cannot be tested.'
71 activity="create cluster"
72 $pgpath/initdb -D $TEMPDIR/cluster -A trust > /dev/null
73 if [ $? -ne 0 ] ; then no_result ; fi
76 PGHOST=$TEMPDIR PGPORT=$port $pgpath/pg_ctl -D $TEMPDIR/cluster start -w -o "-k $TEMPDIR -h ''" > /dev/null
77 if [ $? -ne 0 ] ; then no_result ; fi
80 activity="create database"
81 createdb -h $TEMPDIR -p $port $dbase > /dev/null 2> /dev/null
84 activity="populate database"
85 psql -h $TEMPDIR -p $port $dbase > /dev/null << EOF
87 CREATE TABLE empty (a int, b date, c numeric(23, 4));
89 -- a largeish table to check big queries work ok.
90 CREATE TABLE large (x int);
91 INSERT INTO large (select * from generate_series(1, 1000));
101 numeric numeric(50,6) ,
111 timestamp timestamp ,
112 timestamptz timestamptz ,
117 INSERT INTO thing VALUES (
134 'January 8 04:05:06 1999',
135 'January 8 04:05:06 1999 PST',
140 INSERT INTO thing VALUES (
163 INSERT INTO thing VALUES (
180 '10-Jan-1963 23:58:00',
181 '10-Jan-1963 23:58:00 CET',
182 '2 year 1 month 12 days 1 hours 3 minutes 4 seconds',
186 if [ $? -ne 0 ] ; then fail ; fi
188 activity="create program 1"
189 cat > $TESTFILE <<EOF
191 /CONNECT="host=$TEMPDIR port=$port dbname=$dbase"
193 /SQL="select * from thing".
199 if [ $? -ne 0 ] ; then no_result ; fi
202 activity="run program 1"
203 $SUPERVISOR $PSPP --testing-mode -o raw-ascii $TESTFILE
204 if [ $? -ne 0 ] ; then no_result ; fi
206 activity="compare output 1"
207 perl -pi -e 's/^\s*$//g' $TEMPDIR/pspp.list
208 diff -b $TEMPDIR/pspp.list - << 'EOF'
210 +---------------+-------------------------------------------+--------+
211 |Variable |Description |Position|
212 #===============#===========================================#========#
213 |bool |Format: F8.2 | 1|
214 | |Measure: Scale | |
215 | |Display Alignment: Right | |
216 | |Display Width: 8 | |
217 +---------------+-------------------------------------------+--------+
218 |bytea |Format: AHEX2 | 2|
219 | |Measure: Nominal | |
220 | |Display Alignment: Left | |
221 | |Display Width: 1 | |
222 +---------------+-------------------------------------------+--------+
223 |char |Format: A8 | 3|
224 | |Measure: Nominal | |
225 | |Display Alignment: Left | |
226 | |Display Width: 8 | |
227 +---------------+-------------------------------------------+--------+
228 |int8 |Format: F8.2 | 4|
229 | |Measure: Scale | |
230 | |Display Alignment: Right | |
231 | |Display Width: 8 | |
232 +---------------+-------------------------------------------+--------+
233 |int2 |Format: F8.2 | 5|
234 | |Measure: Scale | |
235 | |Display Alignment: Right | |
236 | |Display Width: 8 | |
237 +---------------+-------------------------------------------+--------+
238 |int4 |Format: F8.2 | 6|
239 | |Measure: Scale | |
240 | |Display Alignment: Right | |
241 | |Display Width: 8 | |
242 +---------------+-------------------------------------------+--------+
243 |numeric |Format: E40.6 | 7|
244 | |Measure: Scale | |
245 | |Display Alignment: Right | |
246 | |Display Width: 8 | |
247 +---------------+-------------------------------------------+--------+
248 |text |Format: A16 | 8|
249 | |Measure: Nominal | |
250 | |Display Alignment: Left | |
251 | |Display Width: 16 | |
252 +---------------+-------------------------------------------+--------+
253 |oid |Format: F8.2 | 9|
254 | |Measure: Scale | |
255 | |Display Alignment: Right | |
256 | |Display Width: 8 | |
257 +---------------+-------------------------------------------+--------+
258 |float4 |Format: F8.2 | 10|
259 | |Measure: Scale | |
260 | |Display Alignment: Right | |
261 | |Display Width: 8 | |
262 +---------------+-------------------------------------------+--------+
263 |float8 |Format: F8.2 | 11|
264 | |Measure: Scale | |
265 | |Display Alignment: Right | |
266 | |Display Width: 8 | |
267 +---------------+-------------------------------------------+--------+
268 |money |Format: DOLLAR8.2 | 12|
269 | |Measure: Scale | |
270 | |Display Alignment: Right | |
271 | |Display Width: 8 | |
272 +---------------+-------------------------------------------+--------+
273 |pbchar |Format: A8 | 13|
274 | |Measure: Nominal | |
275 | |Display Alignment: Left | |
276 | |Display Width: 8 | |
277 +---------------+-------------------------------------------+--------+
278 |varchar |Format: A8 | 14|
279 | |Measure: Nominal | |
280 | |Display Alignment: Left | |
281 | |Display Width: 8 | |
282 +---------------+-------------------------------------------+--------+
283 |date |Format: DATE11 | 15|
284 | |Measure: Scale | |
285 | |Display Alignment: Right | |
286 | |Display Width: 8 | |
287 +---------------+-------------------------------------------+--------+
288 |time |Format: TIME11.0 | 16|
289 | |Measure: Scale | |
290 | |Display Alignment: Right | |
291 | |Display Width: 8 | |
292 +---------------+-------------------------------------------+--------+
293 |timestamp |Format: DATETIME22.0 | 17|
294 | |Measure: Scale | |
295 | |Display Alignment: Right | |
296 | |Display Width: 8 | |
297 +---------------+-------------------------------------------+--------+
298 |timestamptz |Format: DATETIME22.0 | 18|
299 | |Measure: Scale | |
300 | |Display Alignment: Right | |
301 | |Display Width: 8 | |
302 +---------------+-------------------------------------------+--------+
303 |interval |Format: DTIME13.0 | 19|
304 | |Measure: Scale | |
305 | |Display Alignment: Right | |
306 | |Display Width: 8 | |
307 +---------------+-------------------------------------------+--------+
308 |interval_months|Format: F3.0 | 20|
309 | |Measure: Scale | |
310 | |Display Alignment: Right | |
311 | |Display Width: 8 | |
312 +---------------+-------------------------------------------+--------+
313 |timetz |Format: TIME11.0 | 21|
314 | |Measure: Scale | |
315 | |Display Alignment: Right | |
316 | |Display Width: 8 | |
317 +---------------+-------------------------------------------+--------+
318 |timetz_zone |Format: F8.2 | 22|
319 | |Measure: Scale | |
320 | |Display Alignment: Right | |
321 | |Display Width: 8 | |
322 +---------------+-------------------------------------------+--------+
323 bool bytea char int8 int2 int4 numeric text oid float4 float8 money pbchar varchar date time timestamp timestamptz interval interval_months timetz timetz_zone
324 -------- ----- -------- -------- -------- -------- ---------------------------------------- ---------------- -------- -------- -------- -------- -------- -------- ----------- ----------- ---------------------- ---------------------- ------------- --------------- ----------- -----------
325 .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
326 . 20 . . . . . . . . . . . . . . . .
327 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
329 if [ $? -ne 0 ] ; then fail ; fi
332 activity="create program 2"
333 cat > $TESTFILE <<EOF
335 /CONNECT="host=$TEMPDIR port=$port dbname=$dbase"
337 /SQL="select * from empty".
343 if [ $? -ne 0 ] ; then no_result ; fi
345 activity="run program 2"
346 $SUPERVISOR $PSPP --testing-mode -o raw-ascii $TESTFILE
347 if [ $? -ne 0 ] ; then no_result ; fi
349 activity="compare output 2"
350 perl -pi -e 's/^\s*$//g' $TEMPDIR/pspp.list
351 diff -b $TEMPDIR/pspp.list - << 'EOF'
353 +--------+-------------------------------------------+--------+
354 |Variable|Description |Position|
355 #========#===========================================#========#
356 |a |Format: F8.2 | 1|
357 | |Measure: Scale | |
358 | |Display Alignment: Right | |
359 | |Display Width: 8 | |
360 +--------+-------------------------------------------+--------+
361 |b |Format: DATE11 | 2|
362 | |Measure: Scale | |
363 | |Display Alignment: Right | |
364 | |Display Width: 8 | |
365 +--------+-------------------------------------------+--------+
366 |c |Format: E40.2 | 3|
367 | |Measure: Scale | |
368 | |Display Alignment: Right | |
369 | |Display Width: 8 | |
370 +--------+-------------------------------------------+--------+
372 if [ $? -ne 0 ] ; then fail ; fi
374 activity="create program 3"
375 cat > $TESTFILE <<EOF
377 /CONNECT="host=$TEMPDIR port=$port dbname=$dbase"
380 /SQL="select * from large".
383 COMPUTE diff = x - lag (x).
386 SELECT IF (diff <> 1).
400 if [ $? -ne 0 ] ; then no_result ; fi
402 activity="run program 3"
403 $SUPERVISOR $PSPP --testing-mode -o raw-ascii $TESTFILE
404 if [ $? -ne 0 ] ; then no_result ; fi
406 activity="compare output 3"
407 perl -pi -e 's/^\s*$//g' $TEMPDIR/pspp.list
408 diff -b $TEMPDIR/pspp.list - << 'EOF'
426 if [ $? -ne 0 ] ; then fail ; fi