Export data from Navision to MySQL (Integer Type Field)

EVM79EVM79 Member Posts: 4
edited 2005-10-31 in Navision Attain
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_S32 TableNo;
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);
/* 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]));


// Mostrem per pantalla
if (j==1)
printf("Provant si em transforma l'enter = %i amb (%i bytes) \n",atoi(encdata[j]),i[j]);
printf("Dada no es enter = %s amb (%i bytes) \n",s[j],i[j]);
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]);
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))){
for (j=1;j<6;j++) {
} while (DBL_NextRec(hTable,hRec, 1));
printf("OK: (%d) CODIGOS POSTALES importados",contadorImportats);

Thanks a lot!



  • kinekine Member Posts: 12,562
    Are you sure, that you are using 32-bit integer in your program?
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • EVM79EVM79 Member Posts: 4
    I think so...

    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 :)

  • kinekine Member Posts: 12,562
    I think that there is problem with casting between types. Did you compare your code with the one used in c/front example?

    In the example there is DBL_GetFieldDataAddr used for getting the data. Maybe there is some problem...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • EVM79EVM79 Member Posts: 4
    Hi again,

    First of all thanks kine for your help :D

    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!

Sign In or Register to comment.