MCPcopy Create free account
hub / github.com/apache/cloudberry / dectoasc

Function dectoasc

src/interfaces/ecpg/compatlib/informix.c:361–410  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

359}
360
361int
362dectoasc(decimal *np, char *cp, int len, int right)
363{
364 char *str;
365 numeric *nres;
366
367 rsetnull(CSTRINGTYPE, (char *) cp);
368 if (risnull(CDECIMALTYPE, (char *) np))
369 return 0;
370
371 nres = PGTYPESnumeric_new();
372 if (nres == NULL)
373 return ECPG_INFORMIX_OUT_OF_MEMORY;
374
375 if (PGTYPESnumeric_from_decimal(np, nres) != 0)
376 {
377 PGTYPESnumeric_free(nres);
378 return ECPG_INFORMIX_OUT_OF_MEMORY;
379 }
380
381 if (right >= 0)
382 str = PGTYPESnumeric_to_asc(nres, right);
383 else
384 str = PGTYPESnumeric_to_asc(nres, nres->dscale);
385
386 PGTYPESnumeric_free(nres);
387 if (!str)
388 return -1;
389
390 /*
391 * TODO: have to take care of len here and create exponential notation if
392 * necessary
393 */
394 if ((int) (strlen(str) + 1) > len)
395 {
396 if (len > 1)
397 {
398 cp[0] = '*';
399 cp[1] = '\0';
400 }
401 free(str);
402 return -1;
403 }
404 else
405 {
406 strcpy(cp, str);
407 free(str);
408 return 0;
409 }
410}
411
412int
413dectodbl(decimal *np, double *dblp)

Callers 2

mainFunction · 0.85
dump_sqldaFunction · 0.85

Calls 6

rsetnullFunction · 0.85
risnullFunction · 0.85
PGTYPESnumeric_newFunction · 0.85
PGTYPESnumeric_freeFunction · 0.85
PGTYPESnumeric_to_ascFunction · 0.85

Tested by 2

mainFunction · 0.68
dump_sqldaFunction · 0.68