AM_CONDITIONAL(WITHGUI, test x"$with_gui" != x"no")
+dnl Checks needed for psql reader
+AC_CHECK_PROG(psql_support, pg_config, yes, no)
+if test x"$psql_support" = x"yes" ; then
+ AC_DEFINE([PSQL_SUPPORT], 1,
+ [Define to 1 if building in support for reading from postgres databases.])
+ PG_CFLAGS=-I`pg_config --includedir`
+ AC_SUBST(PG_CFLAGS)
+ PG_LDFLAGS=-L`pg_config --libdir`
+ AC_SUBST(PG_LDFLAGS)
+ PG_LIBS=-lpq
+ AC_SUBST(PG_LIBS)
+fi
+AM_CONDITIONAL(PSQL_SUPPORT, test x"$psql_support" = x"yes")
+
dnl Checks needed for gnumeric reader
gnm_support=yes;
PKG_CHECK_MODULES(LIBXML2, libxml-2.0,,
+2008-02-04 John Darrington <john@darrington.wattle.id.au>
+
+ * files.texi data-io.texi: Document the GET DATA TYPE=PSQL
+ option. Thanks to Ben Pfaff for reviewing this text.
+
+
2007-11-10 Ben Pfaff <blp@gnu.org>
* not-implemented.texi: Fix @include command so that it works
pertaining to single respondent is a case.
This chapter examines
the PSPP commands for defining variables and reading and writing data.
+There are alternative commands to read data from predefined sources
+such as system files or databases (@xref{GET, GET DATA}.)
@quotation Note
These commands tell PSPP how to read data, but the data will not
@display
GET DATA
- /TYPE=@{GNM,TXT@}
- /FILE=@{'file-name',file_handle@}
+ /TYPE=@{GNM,PSQL,TXT@}
@dots{}additional subcommands depending on TYPE@dots{}
@end display
@item GNM
Spreadsheet files created by Gnumeric (@url{http://gnumeric.org}).
+@item PSQL
+Relations from PostgreSQL databases (@url{http://postgresql.org}).
+
@item TXT
Textual data files in columnar and delimited formats.
@end table
-The FILE subcommand is mandatory for all implemented file types.
-Specify the file to be read as a string file name or (for textual data
-only) a file handle (@pxref{File Handles}).
-
Each supported file type has additional subcommands, explained in
separate sections below.
@menu
* GET DATA /TYPE=GNM::
+* GET DATA /TYPE=PSQL::
* GET DATA /TYPE=TXT::
@end menu
determined from the length of the string it contains, unless the
ASSUMEDVARWIDTH subcommand is given.
+
+The FILE subcommand is mandatory. Specify the name of the file
+to be read.
+
The SHEET subcommand specifies the sheet within the spreadsheet file to read.
There are two forms of the SHEET subcommand.
In the first form,
If omitted, the default value is determined from the length of the
string in the first spreadsheet cell for each variable.
+
+@node GET DATA /TYPE=PSQL
+@subsection Postgres Database Queries
+
+@display
+GET DATA /TYPE=PSQL
+ /CONNECT=@{connection info@}
+ /SQL=@{query@}
+ [/ASSUMEDVARWIDTH=n]
+ [/UNENCRYPTED].
+@end display
+
+@cindex postgres
+@cindex databases
+
+The PSQL type is used to import data from a postgres database server.
+The server may be located locally or remotely.
+Variables are automatically created based on the table column names
+or the names specified in the SQL query.
+Postgres data types of high precision, will loose precision when
+imported into PSPP.
+Not all the postgres data types are able to be represented in PSPP.
+If a datum cannot be represented a warning will be issued and that
+datum will be set to SYSMIS.
+
+The CONNECT subcommand is mandatory.
+It is a string specifying the parameters of the database server from
+which the data should be fetched.
+The format of the string is given in the postgres manual
+@url{http://www.postgresql.org/docs/8.0/static/libpq.html#LIBPQ-CONNECT}.
+
+The SQL subcommand is mandatory.
+It must be a valid SQL string to retrieve data from the database.
+
+The ASSUMEDVARWIDTH subcommand specifies the maximum width of string
+variables read from the database.
+If omitted, the default value is determined from the length of the
+string in the first value read for each variable.
+
+The UNENCRYPTED subcommand allows data to be retrieved over an insecure
+connection.
+If the connection is not encrypted, and the UNENCRYPTED subcommand is not
+given, then an error will occur.
+Whether or not the connection is
+encrypted depends upon the underlying psql library and the
+capabilities of the database server.
+
+The following syntax is an example:
+@example
+GET DATA /TYPE=PSQL
+ /CONNECT='host=example.com port=5432 dbname=product user=fred passwd=xxxx'
+ /SQL='select * from manufacturer'.
+@end example
+
+
@node GET DATA /TYPE=TXT
@subsection Textual Data Files
@cindex text files
@cindex data files
When TYPE=TXT is specified, GET DATA reads data in a delimited or
-fixed columnar format, much like DATA LIST (@pxref{DATA LIST}). The
-FILE subcommand must be specified indicate the name or the file handle
-of the file to be read.
+fixed columnar format, much like DATA LIST (@pxref{DATA LIST}).
+
+The FILE subcommand is mandatory. Specify the file to be read as
+a string file name or (for textual data
+only) a file handle (@pxref{File Handles}).
The ARRANGEMENT subcommand determines the file's basic format.
DELIMITED, the default setting, specifies that fields in the input
+2008-02-02 John Darrington <john@darrington.wattle.id.au>
+
+ psql-reader.c psql-reader.h: New files. Thanks to Ben Pfaff
+ for reviewing this code.
+
2008-02-02 Ben Pfaff <blp@gnu.org>
Patch #6347.
noinst_LIBRARIES += src/data/libdata.a
-src_data_libdata_a_CPPFLAGS = $(LIBXML2_CFLAGS) $(AM_CPPFLAGS)
+src_data_libdata_a_CPPFLAGS = $(LIBXML2_CFLAGS) $(PG_CFLAGS) $(AM_CPPFLAGS)
src_data_libdata_a_SOURCES = \
src/data/por-file-reader.h \
src/data/por-file-writer.c \
src/data/por-file-writer.h \
+ src/data/psql-reader.c \
+ src/data/psql-reader.h \
src/data/scratch-handle.c \
src/data/scratch-handle.h \
src/data/scratch-reader.c \
+2008-02-02 John Darrington <john@darrington.wattle.id.au>
+
+ * get-data.c (cmd_get_data): Support PSQL type.
+
2007-12-07 Ben Pfaff <blp@gnu.org>
Patch #6302.
/* PSPP - a program for statistical analysis.
- Copyright (C) 2007 Free Software Foundation, Inc.
+ Copyright (C) 2007, 2008 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
#include <stdlib.h>
#include <data/gnumeric-reader.h>
+#include <data/psql-reader.h>
#include <data/dictionary.h>
#include <data/format.h>
static int parse_get_gnm (struct lexer *lexer, struct dataset *);
static int parse_get_txt (struct lexer *lexer, struct dataset *);
+static int parse_get_psql (struct lexer *lexer, struct dataset *);
int
cmd_get_data (struct lexer *lexer, struct dataset *ds)
return parse_get_gnm (lexer, ds);
else if (lex_match_id (lexer, "TXT"))
return parse_get_txt (lexer, ds);
+ else if (lex_match_id (lexer, "PSQL"))
+ return parse_get_psql (lexer, ds);
msg (SE, _("Unsupported TYPE %s"), lex_tokid (lexer));
return CMD_FAILURE;
}
+static int
+parse_get_psql (struct lexer *lexer, struct dataset *ds)
+{
+ struct psql_read_info psql;
+ psql.allow_clear = false;
+ psql.conninfo = NULL;
+ psql.str_width = -1;
+ ds_init_empty (&psql.sql);
+
+ lex_force_match (lexer, '/');
+
+ if (!lex_force_match_id (lexer, "CONNECT"))
+ goto error;
+
+ lex_force_match (lexer, '=');
+
+ if (!lex_force_string (lexer))
+ goto error;
+
+ psql.conninfo = strdup (ds_cstr (lex_tokstr (lexer)));
+
+ lex_get (lexer);
+
+ while (lex_match (lexer, '/') )
+ {
+ if ( lex_match_id (lexer, "ASSUMEDSTRWIDTH"))
+ {
+ lex_match (lexer, '=');
+ psql.str_width = lex_integer (lexer);
+ lex_get (lexer);
+ }
+ else if ( lex_match_id (lexer, "UNENCRYPTED"))
+ {
+ psql.allow_clear = true;
+ }
+ else if (lex_match_id (lexer, "SQL"))
+ {
+ lex_match (lexer, '=');
+ if ( ! lex_force_string (lexer) )
+ goto error;
+
+ ds_put_substring (&psql.sql, lex_tokstr (lexer)->ss);
+ lex_get (lexer);
+ }
+ }
+ {
+ struct dictionary *dict = NULL;
+ struct casereader *reader = psql_open_reader (&psql, &dict);
+
+ if ( reader )
+ proc_set_active_file (ds, reader, dict);
+ }
+
+ ds_destroy (&psql.sql);
+ free (psql.conninfo);
+
+ return CMD_SUCCESS;
+
+ error:
+
+ ds_destroy (&psql.sql);
+ free (psql.conninfo);
+
+ return CMD_FAILURE;
+}
static int
parse_get_gnm (struct lexer *lexer, struct dataset *ds)
src/libpspp/libpspp.a \
$(GTK_LIBS) \
$(GLADE_LIBS) \
+ $(PG_LIBS) \
gl/libgl.la \
@LIBINTL@ @LIBREADLINE@
src/data/libdata.a \
src/libpspp/libpspp.a \
$(LIBXML2_LIBS) \
+ $(PG_LIBS) \
$(LIBICONV) \
gl/libgl.la \
@LIBINTL@ @LIBREADLINE@
dist_TESTS += tests/command/get-data-gnm.sh
endif
+if PSQL_SUPPORT
+dist_TESTS += tests/command/get-data-psql.sh
+endif
+
nodist_TESTS = \
tests/libpspp/abt-test \
tests/libpspp/bt-test \