PostgreSQL clarification -
i have written function inside postgresql has following code:
for (i = 0; < 4; i++) { datum dat_value = cstringgetdatum(inp->str[0][i]); values[i] = datumcopy(dat_value, stats->attrtype->typbyval, stats->attrtype->typlen); }
the input strings {algeria,argentina,brazil,canada}. code runs algeria,argentina terminates abruptly brazil. when investigated found inside datumcopy
function, statement after memcpy
not getting printed. checked if palloc failed (s == null)
condition, seems not reason. think memcpy
failing. reason why? thanks!
datum datumcopy(datum value, bool typbyval, int typlen) { datum res; if (typbyval) res = value; else { size realsize; char *s; if (datumgetpointer(value) == null) return pointergetdatum(null); realsize = datumgetsize(value, typbyval, typlen); s = (char *) palloc(realsize); printf ("value : %s\n",datumgetpointer(value)); memcpy(s, datumgetpointer(value), realsize); printf ("not printing \n"); res = pointergetdatum(s); } return res; }
edited : ok wierd. when input 1 of {brazil,pakistan,france}, code terminates abruptly. if have other countries (i haven't tried extensively, countries), code runs correctly.
edited 2 : found cause , rectified issue. if passing c strings datumcopy
, have pass -2 typlen
parameter. had been passing incorrectly.
thanks!
i have found cause , rectified issue.
if passing c strings datumcopy
, have pass -2 typlen
parameter. had been passing incorrectly.
Comments
Post a Comment