D
David Jacques
I have to reformat a string from the form
"SRID=4269;POINT(-90.673 69.4310000006199)"
to
GeometryFromText('POINT (-141.095 68.5430000006417)',4269) );
I have a function to do this by taking the input string as char* and
returning
another char* as the result string. This function is called repeatedly in a
loop
(once for each table record). However the second time this function is
called,
the memory is not allocated. I figure out the size of the output string by
the
length of the inputs + 1 for the null char. I can't issue free() within the
function
since that memory is the char* object I am returning. Anyone have an idea
what
is going on ?
char* BuildGeometryInsert(char* in_geom_columndata)
{
int sSRID;
char sGeomPrefix[] = "GeometryFromText('";
char* pchr1;
char* pchr2;
int Length;
char* sGeometry;
pchr1 = strrchr(in_geom_columndata,'=');
pchr1++;
sSRID = atoi(pchr1);
pchr2 = strrchr(in_geom_columndata,';');
pchr2++;
Length = (strlen(sGeomPrefix) + strlen(pchr2)+1);
sGeometry = (char*)calloc(Length,sizeof(char));
if (sGeometry == NULL)
{
printf("\nFATAL ERROR: Cannot allocate memory for sGeometry\n");
printf(" Exit now...\n");
exit(0);
}
sprintf(sGeometry,"%s%s%',%d",sGeomPrefix,pchr2,sSRID);
return sGeometry;
}
"SRID=4269;POINT(-90.673 69.4310000006199)"
to
GeometryFromText('POINT (-141.095 68.5430000006417)',4269) );
I have a function to do this by taking the input string as char* and
returning
another char* as the result string. This function is called repeatedly in a
loop
(once for each table record). However the second time this function is
called,
the memory is not allocated. I figure out the size of the output string by
the
length of the inputs + 1 for the null char. I can't issue free() within the
function
since that memory is the char* object I am returning. Anyone have an idea
what
is going on ?
char* BuildGeometryInsert(char* in_geom_columndata)
{
int sSRID;
char sGeomPrefix[] = "GeometryFromText('";
char* pchr1;
char* pchr2;
int Length;
char* sGeometry;
pchr1 = strrchr(in_geom_columndata,'=');
pchr1++;
sSRID = atoi(pchr1);
pchr2 = strrchr(in_geom_columndata,';');
pchr2++;
Length = (strlen(sGeomPrefix) + strlen(pchr2)+1);
sGeometry = (char*)calloc(Length,sizeof(char));
if (sGeometry == NULL)
{
printf("\nFATAL ERROR: Cannot allocate memory for sGeometry\n");
printf(" Exit now...\n");
exit(0);
}
sprintf(sGeometry,"%s%s%',%d",sGeomPrefix,pchr2,sSRID);
return sGeometry;
}