X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdata%2Fpsql-reader.c;h=e372a859a98ea661be660c479e4be83184a9d638;hb=f5c08530fe57a5a1a0bd1b6d82ad2fd446068d93;hp=6780138b08da038015f0022ef81b59e606a2e2ce;hpb=eeb5800b97c3d4e768fb3f7cbdabf54b3bd162b4;p=pspp diff --git a/src/data/psql-reader.c b/src/data/psql-reader.c index 6780138b08..e372a859a9 100644 --- a/src/data/psql-reader.c +++ b/src/data/psql-reader.c @@ -233,8 +233,7 @@ psql_open_reader (struct psql_read_info *info, struct dictionary **dict) casenumber n_cases = CASENUMBER_MAX; const char *encoding; - struct psql_reader *r = xzalloc (sizeof *r); - struct string query ; + struct psql_reader *r = XZALLOC (struct psql_reader); r->conn = PQconnectdb (info->conninfo); if (NULL == r->conn) @@ -305,21 +304,19 @@ psql_open_reader (struct psql_read_info *info, struct dictionary **dict) } const int version = PQserverVersion (r->conn); - ds_init_empty (&query); /* Versions before 9.1 don't have the REPEATABLE READ isolation level. However according to if the server is in the "hot standby" mode then SERIALIZABLE won't work. */ - ds_put_c_format (&query, - "BEGIN READ ONLY ISOLATION LEVEL %s; " - "DECLARE pspp BINARY CURSOR FOR ", - (version < 90100) ? "SERIALIZABLE" : "REPEATABLE READ"); + char *query = xasprintf ( + "BEGIN READ ONLY ISOLATION LEVEL %s; " + "DECLARE pspp BINARY CURSOR FOR %s", + (version < 90100) ? "SERIALIZABLE" : "REPEATABLE READ", + info->sql); + qres = PQexec (r->conn, query); + free (query); - ds_put_substring (&query, info->sql.ss); - - qres = PQexec (r->conn, ds_cstr (&query)); - ds_destroy (&query); if (PQresultStatus (qres) != PGRES_COMMAND_OK) { msg (ME, _("Error from psql source: %s."), @@ -339,12 +336,11 @@ psql_open_reader (struct psql_read_info *info, struct dictionary **dict) On the other hand, most PSPP functions don't need to know this. The GUI is the notable exception. */ - ds_init_cstr (&query, "SELECT count (*) FROM ("); - ds_put_substring (&query, info->sql.ss); - ds_put_cstr (&query, ") stupid_sql_standard"); + query = xasprintf ("SELECT count (*) FROM (%s) stupid_sql_standard", + info->sql); + qres = PQexec (r->conn, query); + free (query); - qres = PQexec (r->conn, ds_cstr (&query)); - ds_destroy (&query); if (PQresultStatus (qres) != PGRES_TUPLES_OK) { msg (ME, _("Error from psql source: %s."), @@ -615,7 +611,7 @@ set_value (struct psql_reader *r) case INTERVALOID: case TIMESTAMPTZOID: case TIMETZOID: - if (i < r->vmapsize && var_get_dict_index(v) + 1 < dict_get_var_cnt (r->dict)) + if (i < r->vmapsize && var_get_dict_index(v) + 1 < dict_get_n_vars (r->dict)) { const struct variable *v1 = NULL; v1 = dict_get_var (r->dict, var_get_dict_index (v) + 1);