Export data from Navision to MySQL (Integer Type Field)

EVM79
Member Posts: 4
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.
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
-
Are you sure, that you are using 32-bit integer in your program?0
-
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
Eduard.0 -
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...0 -
Hi again,
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.0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions