Commits

Andrew Dunstan committed 07f5b98

Correctly handle nulls.

Error reported by David Wheeler.

Comments (0)

Files changed (1)

 static void report_invalid_token(JsonLexContext *lex);
 static char *extract_mb_char(char *s);
 static void composite_to_json(Datum composite, StringInfo result, bool use_line_feeds);
-static void array_dim_to_json(StringInfo result, int dim, int ndims,int * dims,
-							  Datum *vals, int * valcount, TYPCATEGORY tcategory,
-							  Oid typoutputfunc, bool use_line_feeds);
+static void array_dim_to_json(StringInfo result, int dim, int ndims, int *dims,
+							  Datum *vals, bool *nulls, int *valcount, 
+							  TYPCATEGORY tcategory, Oid typoutputfunc, 
+							  bool use_line_feeds);
 static void array_to_json_internal(Datum array, StringInfo result, bool use_line_feeds);
 static void  escape_json(StringInfo buf, const char *str);
 static Oid JSONOID;
  * composite_to_json or array_to_json_internal as appropriate.
  */
 static inline void
-datum_to_json(Datum val, StringInfo result, TYPCATEGORY tcategory,
+datum_to_json(Datum val, bool is_null, StringInfo result, TYPCATEGORY tcategory,
 			  Oid typoutputfunc)
 {
 
 	char *outputstr;
 
-	if (val == (Datum) NULL)
+	if (is_null)
 	{
 		appendStringInfoString(result,"null");
 		return;
  */
 static void
 array_dim_to_json(StringInfo result, int dim, int ndims,int * dims, Datum *vals,
-				  int * valcount, TYPCATEGORY tcategory, Oid typoutputfunc,
-				  bool use_line_feeds)
+				  bool *nulls, int * valcount, TYPCATEGORY tcategory, 
+				  Oid typoutputfunc, bool use_line_feeds)
 {
 
 	int i;
 
 		if (dim + 1 == ndims)
 		{
-			datum_to_json(vals[*valcount],result,tcategory,typoutputfunc);
+			datum_to_json(vals[*valcount], nulls[*valcount], result, tcategory,
+						  typoutputfunc);
 			(*valcount)++;
 		}
 		else
 			 * Do we want line feeds on inner dimensions of arrays?
 			 * For now we'll say no.
 			 */
-			array_dim_to_json(result, dim+1, ndims, dims, vals, valcount,
-							  tcategory,typoutputfunc,false);
+			array_dim_to_json(result, dim+1, ndims, dims, vals, nulls,
+							  valcount, tcategory, typoutputfunc, false);
 		}
 	}
 
 	else
 		tcategory = TypeCategory(element_type);
 
-	array_dim_to_json(result, 0, ndim, dim, elements, &count, tcategory,
+	array_dim_to_json(result, 0, ndim, dim, elements, nulls, &count, tcategory,
 					  typoutputfunc, use_line_feeds);
 
 	pfree(elements);
 		else
 			val = origval;
 
-		datum_to_json(val, result, tcategory, typoutput);
+		datum_to_json(val, isnull, result, tcategory, typoutput);
 
 		/* Clean up detoasted copy, if any */
 		if (val != origval)