Query method example

The queryex.cpp example demonstrates use of the ExecForStatus, ExecOneRow, and ExecToSet methods.

The following excerpts illustrate the use of the query methods in the queryex.cpp example:
  1. Call ITQuery::ExecOneRow() to check if the table informixfans exists in the database. If the table does not exist, use ITQuery::ExecForStatus() to create it.
    // Does the table exist? If not, then create it.
    ITRow *r1 = q.ExecOneRow(
        "select owner from systables where tabname = 'informixfans';");
    if (!r1
         && (!q.ExecForStatus(
             "create table informixfans (name varchar(128));")))
        {
        cerr << "Could not create table 'informixfans'!" << endl;
        return 1;
        }
  2. Call ITQuery::ExecToSet to fetch the results of a select statement:
    // Show the contents of the table
    cout << "These are the members of the Informix fan club, version ";
    ITValue *rel = q.ExecOneRow 
        ("select owner from systables where tabname = ' VERSION';");
    cout << rel->Printable() << " ALWAYS_DIFFERENT" << endl;
    rel->Release(); 
    
    ITSet *set = q.ExecToSet
        ("select * from informixfans order by 1;"); 
    if(!set)
    {
        cout << "Query failed!" << endl;
        conn.SetTransaction(ITConnection::Abort);
        conn.Close();
        return -1;
    }
    ITValue *v;
    while ((v = set->Fetch()) != NULL)
    {
        cout << v->Printable() << endl;
        v->Release();
    } 
    set->Release();