*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/arrayfuncs.c,v 1.111 2004/09/02 20:05:40 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/arrayfuncs.c,v 1.112 2004/09/16 03:15:52 neilc Exp $
*
*-------------------------------------------------------------------------
*/
k,
indx[MAXDIM];
int ndim,
- *dim,
+ *dims,
*lb;
ArrayMetaState *my_extra;
typioparam = my_extra->typioparam;
ndim = ARR_NDIM(v);
- dim = ARR_DIMS(v);
+ dims = ARR_DIMS(v);
lb = ARR_LBOUND(v);
- nitems = ArrayGetNItems(ndim, dim);
+ nitems = ArrayGetNItems(ndim, dims);
if (nitems == 0)
{
values = (char **) palloc(nitems * sizeof(char *));
needquotes = (bool *) palloc(nitems * sizeof(bool));
p = ARR_DATA_PTR(v);
- overall_length = 1; /* [TRH] don't forget to count \0 at end. */
+ overall_length = 1; /* don't forget to count \0 at end. */
+
for (i = 0; i < nitems; i++)
{
Datum itemvalue;
- bool nq;
+ bool needquote;
itemvalue = fetch_att(p, typbyval, typlen);
values[i] = DatumGetCString(FunctionCall3(&my_extra->proc,
p = (char *) att_align(p, typalign);
/* count data plus backslashes; detect chars needing quotes */
- nq = (values[i][0] == '\0'); /* force quotes for empty string */
- for (tmp = values[i]; *tmp; tmp++)
+ if (values[i][0] == '\0')
+ needquote = true; /* force quotes for empty string */
+ else
+ needquote = false;
+
+ for (tmp = values[i]; *tmp != '\0'; tmp++)
{
char ch = *tmp;
overall_length += 1;
if (ch == '"' || ch == '\\')
{
- nq = true;
+ needquote = true;
#ifndef TCL_ARRAYS
overall_length += 1;
#endif
}
else if (ch == '{' || ch == '}' || ch == typdelim ||
isspace((unsigned char) ch))
- nq = true;
+ needquote = true;
}
- needquotes[i] = nq;
+ needquotes[i] = needquote;
/* Count the pair of double quotes, if needed */
- if (nq)
+ if (needquote)
overall_length += 2;
/* and the comma */
/*
* count total number of curly braces in output string
*/
- for (i = j = 0, k = 1; i < ndim; k *= dim[i++], j += k);
+ for (i = j = 0, k = 1; i < ndim; i++)
+ k *= dims[i], j += k;
+
+ dims_str[0] = '\0';
/* add explicit dimensions if required */
if (needdims)
for (i = 0; i < ndim; i++)
{
- sprintf(ptr, "[%d:%d]", lb[i], lb[i] + dim[i] - 1);
+ sprintf(ptr, "[%d:%d]", lb[i], lb[i] + dims[i] - 1);
ptr += strlen(ptr);
}
*ptr++ = *ASSGN;
if (needdims)
APPENDSTR(dims_str);
APPENDCHAR('{');
- for (i = 0; i < ndim; indx[i++] = 0);
+ for (i = 0; i < ndim; i++)
+ indx[i] = 0;
j = 0;
k = 0;
do
for (i = ndim - 1; i >= 0; i--)
{
- indx[i] = (indx[i] + 1) % dim[i];
+ indx[i] = (indx[i] + 1) % dims[i];
if (indx[i])
{
APPENDCHAR(typdelim);
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/arrayutils.c,v 1.16 2004/08/29 04:12:51 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/arrayutils.c,v 1.17 2004/09/16 03:15:52 neilc Exp $
*
*-------------------------------------------------------------------------
*/
/* Convert array dimensions into number of elements */
int
-ArrayGetNItems(int n, int *a)
+ArrayGetNItems(int ndim, int *dims)
{
int i,
ret;
- if (n <= 0)
+ if (ndim <= 0)
return 0;
ret = 1;
- for (i = 0; i < n; i++)
- ret *= a[i];
+ for (i = 0; i < ndim; i++)
+ ret *= dims[i];
return ret;
}
* Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/utils/array.h,v 1.49 2004/08/29 04:13:10 momjian Exp $
+ * $PostgreSQL: pgsql/src/include/utils/array.h,v 1.50 2004/09/16 03:15:54 neilc Exp $
*
*-------------------------------------------------------------------------
*/
*
* ARR_LBOUND returns a pointer to an array of array lower bounds.
*
- * That is: if the third axis of an array has elements 5 through 10, then
- * ARR_DIMS(a)[2] == 6 and ARR_LBOUND(a)[2] == 5.
+ * That is: if the third axis of an array has elements 5 through 8, then
+ * ARR_DIMS(a)[2] == 4 and ARR_LBOUND(a)[2] == 5.
*
* Unlike C, the default lower bound is 1.
*/
extern int ArrayGetOffset(int n, int *dim, int *lb, int *indx);
extern int ArrayGetOffset0(int n, int *tup, int *scale);
-extern int ArrayGetNItems(int n, int *a);
+extern int ArrayGetNItems(int ndims, int *dims);
extern void mda_get_range(int n, int *span, int *st, int *endp);
extern void mda_get_prod(int n, int *range, int *prod);
extern void mda_get_offset_values(int n, int *dist, int *prod, int *span);