#endif
static struct variable *
-create_var (struct psql_reader *r, const struct fmt_spec *fmt,
+create_var (struct psql_reader *r, struct fmt_spec fmt,
int width, const char *suggested_name, int col)
{
unsigned long int vx = 0;
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)
}
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 <a12321aabb@gmail.com> 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."),
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."),
fmt.w = width = PSQL_DEFAULT_WIDTH;
- var = create_var (r, &fmt, width, PQfname (qres, i), i);
+ var = create_var (r, fmt, width, PQfname (qres, i), i);
if (type == NUMERICOID && n_tuples > 0)
{
const uint8_t *vptr = (const uint8_t *) PQgetvalue (qres, 0, i);
fmt.type = FMT_E;
fmt.w = fmt_max_output_width (fmt.type) ;
fmt.d = MIN (dscale, fmt_max_output_decimals (fmt.type, fmt.w));
- var_set_both_formats (var, &fmt);
+ var_set_both_formats (var, fmt);
}
/* Timezones need an extra variable */
fmt.w = 8;
fmt.d = 2;
- create_var (r, &fmt, 0, ds_cstr (&name), -1);
+ create_var (r, fmt, 0, ds_cstr (&name), -1);
ds_destroy (&name);
}
fmt.w = 3;
fmt.d = 0;
- create_var (r, &fmt, 0, ds_cstr (&name), -1);
+ create_var (r, fmt, 0, ds_cstr (&name), -1);
ds_destroy (&name);
}
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);