Search code examples
c++oracle11gocci

how to use setDataBuffer from OCCI for array fetches


I have a query that I'm executing on a database that returns an array of records, I read in the Oracle OCCI documentation you have to use the ResultSet::setDataBuffer() function to fetch array's of data from the db.

I just don't get what I'm supposed to give as the first two args when a database row contains multiple columns of different data? What type should I give as my buffer type?

//example, does not contain all parts, just enough to demonstrate my point
    SELECT AGE, BIRTHDATE, NAME FROM PEOPLE;
    int i[10];  // Type of buffer??? Age is int, but name is a string?
    ResultSet* res;
    res->setDataBuffer(1 /*col index of first col in select statement*/, &i[0], OCCIINT, 10 * sizeof(int));

while(res->next()) { //Fetch data...}

I have searched Google for examples in vain so far. I'm hoping that someone here could help?


Solution

  • As per our comments, I provide a simple example using the getString(),... functions:

    // Statement -> stmt
    // ResultSet -> res
    // Connection -> con
    
    // pseudo code ahead !
    
    stmt = con->createStatement(MY_SELECT, MY_TAG);
    stmt->setPrefetchRowCount(NUMBER_OF_PREFETCHES); // enable bulk collect
    res = stmt->executeQuery();
    
    while(res->next())
    {
        date = res->getDate(INDEX_OF_DATE);
        age = res->getInt(INDEX_OF_AGE);
        name = res->getString(INDEX_OF_NAME);
    
        // do something with date, age, name...
    }
    
    stmt->closeResultSet(res);
    con->terminateStatement(stmt);
    

    But I guess this is exactly what you were originally doing?