{
int row_number;
int col_number;
- pivot_field *p;
+ pivot_field *rp,
+ *cp;
pivot_field elt;
/* Find target row */
elt.name = PQgetvalue(results, rn, field_for_rows);
else
elt.name = NULL;
- p = (pivot_field *) bsearch(&elt,
- piv_rows,
- num_rows,
- sizeof(pivot_field),
- pivotFieldCompare);
- Assert(p != NULL);
- row_number = p->rank;
+ rp = (pivot_field *) bsearch(&elt,
+ piv_rows,
+ num_rows,
+ sizeof(pivot_field),
+ pivotFieldCompare);
+ Assert(rp != NULL);
+ row_number = rp->rank;
/* Find target column */
if (!PQgetisnull(results, rn, field_for_columns))
else
elt.name = NULL;
- p = (pivot_field *) bsearch(&elt,
- piv_columns,
- num_columns,
- sizeof(pivot_field),
- pivotFieldCompare);
- Assert(p != NULL);
- col_number = p->rank;
+ cp = (pivot_field *) bsearch(&elt,
+ piv_columns,
+ num_columns,
+ sizeof(pivot_field),
+ pivotFieldCompare);
+ Assert(cp != NULL);
+ col_number = cp->rank;
/* Place value into cell */
if (col_number >= 0 && row_number >= 0)
if (cont.cells[idx] != NULL)
{
psql_error("\\crosstabview: query result contains multiple data values for row \"%s\", column \"%s\"\n",
- piv_rows[row_number].name ? piv_rows[row_number].name :
- popt.nullPrint ? popt.nullPrint : "(null)",
- piv_columns[col_number].name ? piv_columns[col_number].name :
- popt.nullPrint ? popt.nullPrint : "(null)");
+ rp->name ? rp->name :
+ (popt.nullPrint ? popt.nullPrint : "(null)"),
+ cp->name ? cp->name :
+ (popt.nullPrint ? popt.nullPrint : "(null)"));
goto error;
}
static int
pivotFieldCompare(const void *a, const void *b)
{
- pivot_field *pa = (pivot_field *) a;
- pivot_field *pb = (pivot_field *) b;
+ const pivot_field *pa = (const pivot_field *) a;
+ const pivot_field *pb = (const pivot_field *) b;
/* test null values */
if (!pb->name)
return 1;
/* non-null values */
- return strcmp(((pivot_field *) a)->name,
- ((pivot_field *) b)->name);
+ return strcmp(pa->name, pb->name);
}
static int
rankCompare(const void *a, const void *b)
{
- return *((int *) a) - *((int *) b);
+ return *((const int *) a) - *((const int *) b);
}
SELECT 1 \crosstabview
\crosstabview: query must return at least three columns
DROP TABLE ctv_data;
+-- check error reporting (bug #14476)
+CREATE TABLE ctv_data (x int, y int, v text);
+INSERT INTO ctv_data SELECT 1, x, '*' || x FROM generate_series(1,10) x;
+SELECT * FROM ctv_data \crosstabview
+ x | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10
+---+----+----+----+----+----+----+----+----+----+-----
+ 1 | *1 | *2 | *3 | *4 | *5 | *6 | *7 | *8 | *9 | *10
+(1 row)
+
+INSERT INTO ctv_data VALUES (1, 10, '*'); -- duplicate data to cause error
+SELECT * FROM ctv_data \crosstabview
+\crosstabview: query result contains multiple data values for row "1", column "10"
+DROP TABLE ctv_data;
SELECT 1 \crosstabview
DROP TABLE ctv_data;
+
+-- check error reporting (bug #14476)
+CREATE TABLE ctv_data (x int, y int, v text);
+
+INSERT INTO ctv_data SELECT 1, x, '*' || x FROM generate_series(1,10) x;
+SELECT * FROM ctv_data \crosstabview
+
+INSERT INTO ctv_data VALUES (1, 10, '*'); -- duplicate data to cause error
+SELECT * FROM ctv_data \crosstabview
+
+DROP TABLE ctv_data;