在这个例子中,我们有通过OCCI函数在Oracle数据库中插入int和char值的代码。 我试图通过setDataBuffer插入双值,但它插入一些垃圾值。在这种情况下,我认为我传递的是错误的大小或长度。有人可以通过更新以下示例来帮助插入双值。
Statement *stmt = conn->createStatement(
"insert into departments (department_id, department_name) values(:1, :2)");
char dnames[][100] = {"Community Outreach", "University Recruiting"};
ub2 dnameLen[2];
for (int i = 0; i < 2; i++)
dnameLen[i] = strlen(dnames[i] + 1);
int ids[2] = {7369, 7654};
ub2 idLen[2] = {sizeof(ids[0]), sizeof(ids[1])};
stmt->setDataBuffer(1, ids, OCCIINT, sizeof(ids[0]), idLen);
stmt->setDataBuffer(2, dnames, OCCI_SQLT_STR, sizeof(dnames[0]), dnameLen);