Hi everybody,
I'm new at using and working with Navision and I have to develop an application in C++ using CFRONT to export data from Navision to a MySQL database but I have problems when the Data Type in a Field in Navision is Integer because it does not export de data (in all the other cases it works).
Please can anybody tell me how to retrieve the data of a field when its type is Integer??
(I'm showing my code if it helps)
void codigospostales () {
DBL_HTABLE hTable;
DBL_S32 TableNo;
DBL_HREC hRec;
int contadorTemp=0;
char s[5][100];
int mapping[5] = {0,4,1,2,3};
int i[5];
int datasize[5];
char *encdata[5];
char *query;
TableNo = DBL_TableNo((DBL_U8*)"50097");
if (TableNo != 0) {
DBL_OpenTable(&hTable, TableNo);
/* Guardem la memoria pel registre */
hRec = DBL_AllocRec(hTable);
DBL_Allow(DBL_Err_RecordNotFound);
/* Busquem el primer registre */
int contadorImportats = 0;
if (DBL_FindRec(hTable, hRec, (DBL_U8*)"-")) {
do { // Recorrem tots els registres
int j;
for (j=1;j<5;j++) {
i[j] = DBL_GetFieldData(s[j], 100, hTable, hRec, mapping[j]);
encdata[j]=(char *)malloc(4*i[j]);
datasize[j]=mysql_real_escape_string(&mysql_db, encdata[j], s[j], strlen(s[j]));
datasize[j]=(i[j]);
// Mostrem per pantalla
if (j==1)
{
printf("Provant si em transforma l'enter = %i amb (%i bytes) \n",atoi(encdata[j]),i[j]);
}
else
{
printf("Dada no es enter = %s amb (%i bytes) \n",s[j],i[j]);
}
}
// MYSQL
if (strcmp("",encdata[1])!=0) { // Si el codi no es nul insertem el registre
query=(char *)malloc(datasize[1]+datasize[2]+datasize[3]+datasize[4]+255);
sprintf(query, "INSERT INTO codigos_postales VALUES(\'%s\',\'%s\',\'%s\',\'%s\')", encdata[1], encdata[2], encdata[3], encdata[4]);
printf("QUERY -> INSERT INTO codigos_postales VALUES(\'%s\',\'%s\',\'%s\',\'%s\')\n", encdata[1], encdata[2], encdata[3], encdata[4]);
for(j=1;j<5;j++)
{
printf("Edu(2) -> Dada amb j = %i es = %s i mapping = %i \n", j, encdata[j], mapping[j]);
}
if(mysql_real_query(&mysql_db, query, strlen(query))){
printf(mysql_error(&mysql_db));
exit(1);
}
free(query);
contadorImportats++;
}
for (j=1;j<6;j++) {
free(encdata[j]);
}
// F_MYSQL
} while (DBL_NextRec(hTable,hRec, 1));
}
DBL_FreeRec(hRec);
DBL_CloseTable(hTable);
printf("OK: (%d) CODIGOS POSTALES importados",contadorImportats);
}
}
Thanks a lot!
Eduard.
0
Comments
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
The problem is when I retrieve an Integer data from Navision ir returns me a strange character but in all the other cases (when the data is String or Decimal or Code) it returns me the correct data (well, when I retrieve a Code data it reuturns me a strange character in the beginning of the data but I discard it).
I'm a little bit lost in this moment so every reply will be wellcome
Eduard.
In the example there is DBL_GetFieldDataAddr used for getting the data. Maybe there is some problem...
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
First of all thanks kine for your help
Well, yes I've been looking the c/front example (sample.c) and I've compared the codes but I'm quite new on this and I still haven't found the solution.... but I'm working to find it.
See u!
Eduard.