X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdata%2Fpsql-reader.c;h=85e777a991b9218bfbf2c5f17555a9972093bd5e;hb=537fdeb3702c011e05d7826a8d556a7beeba2605;hp=9df82b558c69252930fdf932e0ed5575edd3cfa8;hpb=18e5609ea65b59f38fcd681f8555775f2e5b7ccd;p=pspp-builds.git diff --git a/src/data/psql-reader.c b/src/data/psql-reader.c index 9df82b55..85e777a9 100644 --- a/src/data/psql-reader.c +++ b/src/data/psql-reader.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 2008 Free Software Foundation, Inc. + Copyright (C) 2008, 2009 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 @@ -37,7 +37,7 @@ #if !PSQL_SUPPORT struct casereader * -psql_open_reader (struct psql_read_info *info, struct dictionary **dict) +psql_open_reader (struct psql_read_info *info UNUSED, struct dictionary **dict UNUSED) { msg (ME, _("Support for reading postgres databases was not compiled into this installation of PSPP")); @@ -75,8 +75,7 @@ psql_open_reader (struct psql_read_info *info, struct dictionary **dict) static void psql_casereader_destroy (struct casereader *reader UNUSED, void *r_); -static bool psql_casereader_read (struct casereader *, void *, - struct ccase *); +static struct ccase *psql_casereader_read (struct casereader *, void *); static const struct casereader_class psql_casereader_class = { @@ -109,8 +108,7 @@ struct psql_reader }; -static bool set_value (struct psql_reader *r, - struct ccase *cc); +static struct ccase *set_value (struct psql_reader *r); @@ -290,10 +288,22 @@ psql_open_reader (struct psql_read_info *info, struct dictionary **dict) /* Create the dictionary and populate it */ *dict = r->dict = dict_create (); + { + const int enc = PQclientEncoding (r->conn); + + /* According to section 22.2 of the Postgresql manual + a value of zero (SQL_ASCII) indicates + "a declaration of ignorance about the encoding". + Accordingly, we don't set the dictionary's encoding + if we find this value. + */ + if ( enc != 0 ) + dict_set_encoding (r->dict, pg_encoding_to_char (enc)); + } + /* select count (*) from (select * from medium) stupid_sql_standard; */ - ds_init_cstr (&query, "BEGIN READ ONLY ISOLATION LEVEL SERIALIZABLE; " "DECLARE pspp BINARY CURSOR FOR "); @@ -550,9 +560,8 @@ psql_casereader_destroy (struct casereader *reader UNUSED, void *r_) -static bool -psql_casereader_read (struct casereader *reader UNUSED, void *r_, - struct ccase *cc) +static struct ccase * +psql_casereader_read (struct casereader *reader UNUSED, void *r_) { struct psql_reader *r = r_; @@ -562,24 +571,24 @@ psql_casereader_read (struct casereader *reader UNUSED, void *r_, return false; } - return set_value (r, cc); + return set_value (r); } -static bool -set_value (struct psql_reader *r, - struct ccase *c) +static struct ccase * +set_value (struct psql_reader *r) { - int i; + struct ccase *c; int n_vars; + int i; assert (r->res); n_vars = PQnfields (r->res); if ( r->tuple >= PQntuples (r->res)) - return false; + return NULL; - case_create (c, r->value_cnt); + c = case_create (r->value_cnt); memset (case_data_rw_idx (c, 0)->s, ' ', MAX_SHORT_STRING * r->value_cnt); @@ -874,7 +883,7 @@ set_value (struct psql_reader *r, r->tuple++; - return true; + return c; } #endif