使用 OLEDB select 语句获取错误值
我在本地运行 Oracle 11g2 32b,并在代码中连接到它。我使用 VC++ 并与 OLE DB 连接。连接工作正常(最终),我可以毫无问题地将数据插入到我的表中。
然而,我确实遇到问题的是在获取数据时。我有一个名为 ITEM 的表,只是用来测试我的东西。我使用 CCommand。命令执行,我的命令实际上包含数据。事实上,它包含正确数量的列和行;但是,它似乎不包含正确的数据。
当我运行这个程序时,我应该得到 7 行编号为 4 到 10 的行,而我却收到了 83 000 000 到 168 000 000 之间逐渐增加且遥远的值。当我尝试获取列名称时,我也得到数字而不是字符串。
stringstream stream;
string str;
stream << "SELECT * FROM ITEM";
str = stream.str();
wstring commandText = s2ws(str);
hr = cmd.Open(session, commandText.c_str());
if(FAILED(hr)){
cout << "Select failed." << endl;
//Cropped for brevity, closes connection and returns -1
}else{
cout << "Selection successful." << endl;
hr = cmd.MoveFirst();
int counter = 0;
while(!FAILED(hr) && hr != DB_S_ENDOFROWSET){
counter++;
hr = cmd.MoveNext();
cout << *(long*)(cmd.GetValue(1)) << endl;
}
cout << "Number of entries : " << counter << endl;
}
我首先认为这可能是数据类型问题(Oracle 中我的列的数据类型是 INTEGER),所以我尝试了不同的类型而不是“long”,但无济于事。
提前致谢。
编辑:我能够在另一个测试表上检索 VARCHAR,但我仍然在与数字作斗争。
编辑:进一步测试表明,4 个不同的数字 DBTYPE 都读取不同的令人震惊的数字。
编辑:我能够将数字作为字符串读取,并在代码中将它们转换回 int 。这完全是荒谬的,但它确实有效。如果有人解决了问题,我仍然想知道正确的方法,但在那之前,这将是必须要做的。
I'm running Oracle 11g2 32b locally and I'm connecting to it in code. I use VC++ and connect with OLE DB. The connection is working fine (finally) and I can insert data into my table without problem.
Where I do run into problems, however, is when fetching data. I have a single table called ITEM just to test my stuff on. I use a CCommand. The command executes and my command actually contains data. In fact, it contains the correct amount of columns and rows; however, it doesn't seem to contain the correct data.
When I run this, I should get 7 rows numbered 4 to 10, while I instead receive progressively increasing and distant values between 83 000 000 and 168 000 000. When I try to obtain the column names I also get numbers instead of strings.
stringstream stream;
string str;
stream << "SELECT * FROM ITEM";
str = stream.str();
wstring commandText = s2ws(str);
hr = cmd.Open(session, commandText.c_str());
if(FAILED(hr)){
cout << "Select failed." << endl;
//Cropped for brevity, closes connection and returns -1
}else{
cout << "Selection successful." << endl;
hr = cmd.MoveFirst();
int counter = 0;
while(!FAILED(hr) && hr != DB_S_ENDOFROWSET){
counter++;
hr = cmd.MoveNext();
cout << *(long*)(cmd.GetValue(1)) << endl;
}
cout << "Number of entries : " << counter << endl;
}
I first though it might be a Data Type problem (my column's data type in Oracle is INTEGER), so I tried different types instead of "long", but to no avail.
Thanks in advance.
EDIT: I was able to retrieve a VARCHAR on another test table, but I am still struggling with numerics.
EDIT: Further testing showed that 4 different numeric DBTYPEs all read different outrageous numbers.
EDIT: I was able to read the numbers as strings and convert them back to int in my code. This is completely ridiculous, but it works. I would still like to know the proper way of doing it if someone figures something out, but until then, this is going to have to do.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我怀疑您的演员遇到了字节序问题。尝试使用模板(请参阅 CDynamicAccessor::GetValue< /a>) 形式的 GetValue 来获取数字。
I suspect that you are running into an endian problem with your cast. Try using the templated (see CDynamicAccessor::GetValue) form of GetValue to get numerics.