#include
"mx.h"
#include "db.h"
int OnReceiveAck (MXMessage* pmessage, MXCom* pcom, void* par)
{
char Message[400];
LONG RowsProcessed = (LONG)MXGetValue (pmessage, "RowsProcessed", 1);
LONG SqlCode = (LONG)MXGetValue (pmessage, "SqlCode", 1);
STRING SqlErrMsg = (STRING)MXGetValue (pmessage,"SqlErrMsg", 1);
SHORT Stop = (SHORT)MXGetValue (pmessage, "Stop", 1);
sprintf (Message, "Ack Result = %s , %d, %d\n", SqlErrMsg , RowsProcessed, SqlCode);
printf ("Ack Result = %s , %d, %d\n", SqlErrMsg , RowsProcessed,
SqlCode);
return 1 ;
}
int OnReceiveSelectCountry (MXMessage* pmessage, MXCom* pcom, void* par)
{
DWORD NbrRows = MXGetNbrRows (pmessage);
DWORD i = 1;
while (i <= NbrRows)
{
STRING id_country = MXGetValue (pmessage, "ID_COUNTRY" , i);
STRING id_currency = MXGetValue (pmessage, "ID_CURRENCY" , i);
STRING code_country = MXGetValue (pmessage, "CODE_UPU" , i);
STRING code_douane = MXGetValue (pmessage, "CODE_OTHER" , i);
STRING code_tnt = MXGetValue (pmessage, "CODE_IXD" , i);
/*
Do whatever you want */
i++;
}
return 1;
}
void main ()
{
MX
mx;
MXMessage* pmessage;
MXCom* DBCom;
/*
Initialize MX manager */
MXInit (&mx, MXSERVER, NULL, NULL, 0, NULL);
/* Connect to database */
DBCom
= MXOpenBase (&mx, "MyDataBase","UserName",
"PassWord", 80, DBPROTO_ODBC, TRUE);
if (!DBCom) return;
MXAddComCallBack (&mx, DBCom, "DB", "AckStatement" , MXONRECV, OnReceiveAck,
NULL);
MXAddComCallBack(pmx, dbclient, "DB", "SelectCountries",
MXONRECV, OnReceiveSelectCountry, dbclient);
/*Load countries from table country */
{
BYTE TreatmentType = OSSEQUENTIALTREATMENT;
DWORD Every = 1000;
DWORD MaxRows = 1300;
/* put message in queue */
pmessage = MXPutMessage(&mx,"DB", "ExecuteQuery");
MXSetValue (pmessage, "TreatmentType", 1, &TreatmentType);
MXSetValue (pmessage, "Every", 1, &Every);
MXSetValue (pmessage, "MaxRows", 1, &MaxRows);
MXSetValue (pmessage, "Name", 1, "SelectCountries");
MXSetValue (pmessage, "SqlStatement", 1, "SELECT * FROM
country");
}
MXDispatchEvents (&mx, 0);
MXEnd (&mx);
}
|