From: John Darrington Date: Sun, 8 Mar 2009 01:47:48 +0000 (+0900) Subject: Fixed a bug reading empty strings from Postgres databases. X-Git-Tag: v0.6.2-pre1~15 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?p=pspp-builds.git;a=commitdiff_plain;h=18e5609ea65b59f38fcd681f8555775f2e5b7ccd Fixed a bug reading empty strings from Postgres databases. Fixed a bug in the Postgresql import feature, where a segfault would occur when a reading a database which contained string fields with only null, or zero length values. Thanks to Joerg Schmengle for reporting this. --- diff --git a/src/data/psql-reader.c b/src/data/psql-reader.c index 72e14be4..9df82b55 100644 --- a/src/data/psql-reader.c +++ b/src/data/psql-reader.c @@ -442,6 +442,10 @@ psql_open_reader (struct psql_read_info *info, struct dictionary **dict) break; } + if ( width == 0 && fmt_is_string (fmt.type)) + fmt.w = width = MAX_SHORT_STRING; + + var = create_var (r, &fmt, width, PQfname (qres, i), i); if ( type == NUMERICOID && n_tuples > 0) { diff --git a/tests/command/get-data-psql.sh b/tests/command/get-data-psql.sh index fa61d6d6..1d8afada 100755 --- a/tests/command/get-data-psql.sh +++ b/tests/command/get-data-psql.sh @@ -427,4 +427,44 @@ diff -b $TEMPDIR/pspp.list - << 'EOF' EOF if [ $? -ne 0 ] ; then fail ; fi + + +# Check for a bug caused by having string variables in the database, +# all of which are null. + +activity="populate database 4" +$pgpath/psql -h $TEMPDIR -p $port $dbase > /dev/null << EOF + +-- a table which has a text field containing only null, or zero +-- length entries. + +CREATE TABLE foo (int4 int4, text text); + +INSERT INTO foo VALUES ('12', ''); + +INSERT INTO foo VALUES (null, ''); + +EOF +if [ $? -ne 0 ] ; then fail ; fi + + +activity="create program 4" +cat > $TESTFILE <