如何使用OCCI中的setDataBuffer进行数组提取

时间:2011-04-06 12:10:57

标签: c++ oracle11g occi

我有一个查询,我正在一个返回记录数组的数据库上执行,我在Oracle OCCI文档中读到你必须使用ResultSet::setDataBuffer()函数从db获取数据的数组。

当数据库行包含多列不同数据时,我只是没有得到我应该给出的前两个args?我应该给什么类型的缓冲区类型?

//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...}

到目前为止,我已经在谷歌搜索了一些徒劳的例子。我希望有人可以帮忙吗?

1 个答案:

答案 0 :(得分:2)

根据我们的评论,我提供了一个使用getString(),...函数的简单示例:

// 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);

但我想这正是你最初做的事情?