#include <iostream>
#include <string>
#include <istream>
#include <it.h>
using namespace std;
ITCallbackResult
my_error_handler(const ITErrorManager &errorobject,
void *userdata,
long errorlevel)
{
// Cast the user data into a stream
ostream *stream = (ostream *) userdata;
(*stream) << "my_error_handler: errorlevel="
<< errorlevel
<< " sqlstate="
<< errorobject.SqlState()
<< ' '
<< errorobject.ErrorText()
<< endl;
return IT_NOTHANDLED;
}
int main(int, char **)
{
ITDBInfo *dbinfo = new ITDBInfo(
"taiDB",
"informix",
"iftx1",
"passwd" );
ITConnection conn;
conn.Open(*dbinfo);
ITQuery query( conn );
query.AddCallback(my_error_handler, (void *) &cerr);
char qtext[4096]={0} ;
sprintf(qtext,"%s","select * from idximply") ;
if (!query.ExecForIteration(qtext))
{
cout << "Could not execute query: " << qtext << endl;
}
else
{
ITRow *row;
int rowcount = 0;
while ((row = query.NextRow()) != NULL)
{
ITConversions *c;
ITDateTime *dt;
ITString itstring ;
int itinteger ;
double itdouble ;
const char *cstring ;
rowcount++;
//cout << row->Printable() << endl;
ITValue *v1 = row->Column("issuecode");
if(v1->QueryInterface(ITConversionsIID, (void **) &c)== IT_QUERYINTERFACE_SUCCESS){
c->ConvertTo( itstring );
cout << itstring << " " ;
c->Release();
}
ITValue *v2 = row->Column("bestbid_price1");
if(v2->QueryInterface(ITConversionsIID, (void **) &c)== IT_QUERYINTERFACE_SUCCESS){
c->ConvertTo( itdouble );
cout << itdouble << " " ;
c->Release();
}
ITValue *v3 = row->Column("totalvol");
if(v3->QueryInterface(ITConversionsIID, (void **) &c)== IT_QUERYINTERFACE_SUCCESS){
c->ConvertTo( itinteger );
cout << itinteger << " " ;
c->Release();
}
ITValue *v4 = row->Column("currenttime");
if(v4->QueryInterface(ITDateTimeIID, (void **) &dt)== IT_QUERYINTERFACE_SUCCESS){
char tmp[8]={0} ;
sprintf(tmp,"%02d",dt->Day()) ;
cout << " "
<< dt->Year()
<< "-" << dt->Month()
<< "-" << tmp
<< " " << dt->Hour()
<< ":" << dt->Minute()
<< ":" << dt->Second() ;
dt->Release();
}else{
cout << "currenttime error" << endl ;
}
cout << endl ;
row->Release();
}
cout << rowcount << " rows received, Command:"
<< query.Command() << endl;
}
cout << "===============================================================" << endl ;
sprintf(qtext,"%s","select trdday from tradingday") ;
if (!query.ExecForIteration(qtext))
{
cout << "Could not execute query: " << qtext << endl;
}
else
{
ITRow *row;
int rowcount = 0;
while ((row = query.NextRow()) != NULL)
{
ITConversions *c;
ITDateTime *dt;
ITString itstring ;
int itinteger ;
double itdouble ;
const char *cstring ;
rowcount++;
ITValue *v1 = row->Column("trdday");
if(v1->QueryInterface(ITDateTimeIID, (void **) &dt)== IT_QUERYINTERFACE_SUCCESS){
char tmp[8]={0} ;
sprintf(tmp,"%02d",dt->Day()) ;
cout << " "
<< dt->Year()
<< "/" << dt->Month()
<< "/" << tmp ;
dt->Release();
}else{
cout << "currenttime error" << endl ;
}
cout << endl ;
row->Release();
}
cout << rowcount << " rows received, Command:"
<< query.Command() << endl;
}
sprintf(qtext,"%s","update idximply set currenttime = current ") ;
if (!query.ExecForStatus(qtext))
cout<< "ExecForStatus Failed:" << qtext << endl;
conn.Close();
return 0;
}
留言列表