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

发布于 2024-10-30 11:45:54 字数 749 浏览 1 评论 0原文

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

当数据库行包含多列不同数据时,我只是不明白我应该给出什么作为前两个参数?我应该指定什么类型作为我的缓冲区类型?

//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 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

や莫失莫忘 2024-11-06 11:45:54

根据我们的评论,我提供了一个使用 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);

但我想这正是您最初所做的?

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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文