IBM Informix Object Interface for C++
Posted in 2008
Topics: Data Types & Schema Design
I am using the IBM Informix Object Interface for C++...or I suppose I should say that I am "trying to use" it. I'm on Windows XP and I have version 3.5. I have no problem with building the example programs I can connect to a database and in a very basic sense I can send queries and process results. It is the "process results" part that has me quite confused. Here is what I need to do: 1. Recognize the type of each column. Generally I have been able to do this (see example below) but I'm not sure what use this information is to me in a practical sense. 2. Then, for each row, get access to the bytes that represent the value in each column and process these bytes appropriately based on the type. In many C database programming APIs you would simply find out the type and then get a pointer to the data for the actual value in the column for this type and you are good to go...easy!! In the Informix Object Interface for C++ you are left with the need, it appears, to exhaustively "query the interface" for each column values as follows: if (v->QueryInterface(ITDateTimeIID, (void **) &dt) == IT_QUERYINTERFACE_SUCCESS) { for each and every column in each and every row in order to "properly address the data." You basically need to keep asking "are you one of these" if not then "are you one of these", etc, etc. I've done a limited amount of COM programming in my career and I remember that the basic approach was similar to this. But, my reaction here is that I must be missing something because this seems like an approach that is way over the top. I know what type is in "this column" (see example below)...now, give me access to the data and I'll take it from there. If you (Mr. Informix Object Interface for C++ designer) want me to access this data using COM/QueryInterface structure, then provide me with a way to produce that interface based on the column type (that I already am aware of). I cannot see anything in the example programs that demonstrate an approach...or I suppose I should say, "if it is there, in the examples, then I cannot see it"... I could say more, but I think it would be more illuminating to simply look at the example below, then if anyone can offer some very basic pointers I would appreciate it. Thanks in advance!! Brian string qtext; qtext = "select * from city"; if ( ! query.ExecForIteration(qtext.c_str())) { cout << "Could not execute query: " << qtext << endl; } else { const ITTypeInfo * rowTypeInfo = query.RowType(); int colCount = rowTypeInfo->ColumnCount(); for (int i = 0; i < colCount; ++i) { const ITTypeInfo * colType = rowTypeInfo->ColumnType(i); std::cout << "DBTYPENAME=" << colType->Name() << " FieldName=" << rowTypeInfo->ColumnName(i) << endl; } ITRow * row; int rowcount = 0; while ((row = query.NextRow()) != NULL) { ITValue * v = row->Column(0); const ITTypeInfo & ti = v->TypeOf(); // I need to accomplish something like this // I need to accomplish something like this // I need to accomplish something like this for (int i = 0; i < colCount; ++i) { // 1. Determine the SQL/Native datatype of the column (as I show above maybe??) // 2. Get access to the actual data and process it properly depending on it's type } // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ // I need to accomplish something like this rowcount++; cout << row->Printable() << endl; row->Release(); } cout << rowcount << " rows received, Command:" << query.Command () << endl; }
Not sure if you got a response yet. Try using the ESQL/C instead of C++ first. (There's metadata that you can access.) I'm pretty sure that you can find the same meta data from C++, just that well.... most of the stuff I've done either just required C so ESQL/C was the easiest and most efficient way to write the code , or its been done via Java or going way back Objective C. (Objective C is making a comeback these days...) -HTH > From: brplummer@gmail.com > Subject: IBM Informix Object Interface for C++ > Date: Sun, 7 Dec 2008 06:13:36 -0800 > To: informix-list@iiug.org > > I am using the IBM Informix Object Interface for C++...or I suppose I > should say that I am "trying to use" it. > > I'm on Windows XP and I have version 3.5. I have no problem with > building the example programs I can connect to a database and in a > very basic sense I can send queries and process results. It is the > "process results" part that has me quite confused. Here is what I > need to do: > > 1. Recognize the type of each column. Generally I have been able to > do this (see example below) but I'm not sure what use this information > is to me in a practical sense. > 2. Then, for each row, get access to the bytes that represent the > value in each column and process these bytes appropriately based on > the type. > > In many C database programming APIs you would simply find out the type > and then get a pointer to the data for the actual value in the column > for this type and you are good to go...easy!! > > In the Informix Object Interface for C++ you are left with the need, > it appears, to exhaustively "query the interface" for each column > values as follows: > > if (v->QueryInterface(ITDateTimeIID, (void **) &dt) == > IT_QUERYINTERFACE_SUCCESS) { > > for each and every column in each and every row in order to "properly > address the data." You basically need to keep asking "are you one of > these" if not then "are you one of these", etc, etc. > > I've done a limited amount of COM programming in my career and I > remember that the basic approach was similar to this. But, my > reaction here is that I must be missing something because this seems > like an approach that is way over the top. I know what type is in > "this column" (see example below)...now, give me access to the data > and I'll take it from there. If you (Mr. Informix Object Interface > for C++ designer) want me to access this data using COM/QueryInterface > structure, then provide me with a way to produce that interface based > on the column type (that I already am aware of). I cannot see > anything in the example programs that demonstrate an approach...or I > suppose I should say, "if it is there, in the examples, then I cannot > see it"... > > I could say more, but I think it would be more illuminating to simply > look at the example below, then if anyone can offer some very basic > pointers I would appreciate it. > > Thanks in advance!! > > Brian > > > string qtext; > qtext = "select * from city"; > > if ( ! query.ExecForIteration(qtext.c_str())) { > cout << "Could not execute query: " << qtext << endl; > } else { > const ITTypeInfo * rowTypeInfo = query.RowType(); > int colCount = rowTypeInfo->ColumnCount(); > for (int i = 0; i < colCount; ++i) { > const ITTypeInfo * colType = rowTypeInfo->ColumnType(i); > std::cout << "DBTYPENAME=" << colType->Name() << " > FieldName=" > << rowTypeInfo->ColumnName(i) << endl; > } > ITRow * row; > int rowcount = 0; > while ((row = query.NextRow()) != NULL) { > > ITValue * v = row->Column(0); > const ITTypeInfo & ti = v->TypeOf(); > > // I need to accomplish something like this > // I need to accomplish something like this > // I need to accomplish something like this > for (int i = 0; i < colCount; ++i) { > > // 1. Determine the SQL/Native datatype of the column (as > I show above maybe??) > // 2. Get access to the actual data and process it > properly depending on it's type > > } > // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > // I need to accomplish something like this > > rowcount++; > cout << row->Printable() << endl; > row->Release(); > } > cout << rowcount << " rows received, Command:" << query.Command > () << endl; > } > _______________________________________________ > Informix-list mailing list > Informix-list@iiug.org > http://www.iiug.org/mailman/listinfo/informix-list _________________________________________________________________ Send e-mail faster without improving your typing skills. http://windowslive.com/Explore/hotmail?ocid=TXT_TAGLM_WL_hotmail_acq_speed_122008