如何从 .net 中的 Informix 查询中获取 IfxBlob?
我似乎找不到一种方法来获取 .Net 下列的定位器对象。 看起来 Informix 会自动将 blob 列转换为 Byte[],并且没有留下更改该行为的方法。
IBM.Data.Informix.IfxConnection c =
new IBM.Data.Informix.IfxConnection("...");
c.Open();
IBM.Data.Informix.IfxCommand cmd =
new IBM.Data.Informix.IfxCommand("SELECT id,data FROM aaa", c);
IBM.Data.Informix.IfxDataReader r = cmd.ExecuteReader();
while (r.Read()) {
Debug.WriteLine(r.GetValue(1).GetType());
}
c.Close();
结果:
System.Byte[]
System.Byte[]
System.DBNull
System.DBNull
我预期:
IBM.Data.Informix.IfxBlob
或类似的东西。
I can't seem to find a way to get just the locator object of a column under .Net. It seems that Informix is automatically converting the blob column to Byte[] and not leaving a way to change that behavior.
IBM.Data.Informix.IfxConnection c =
new IBM.Data.Informix.IfxConnection("...");
c.Open();
IBM.Data.Informix.IfxCommand cmd =
new IBM.Data.Informix.IfxCommand("SELECT id,data FROM aaa", c);
IBM.Data.Informix.IfxDataReader r = cmd.ExecuteReader();
while (r.Read()) {
Debug.WriteLine(r.GetValue(1).GetType());
}
c.Close();
results:
System.Byte[]
System.Byte[]
System.DBNull
System.DBNull
I expected:
IBM.Data.Informix.IfxBlob
or something similar.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我向一位同事询问了这个问题,这是他给我的答复。 因为这不是我的作品,所以我已经将答案设为“社区维基”,所以我没有得到荣誉(除了知道在哪里询问之外)。
为了回答这个问题...以下程序是使用 Common Informix Provider(使用 DRDA 通信协议的 IBM.Data.Informix.dll)编写的...您可以在“IBM Data Server Driver for CLI, ODBC”中获取它和.NET”包)。 使用 Legacy Informix Provider(使用 SQLI 通信协议的 IBM.Data.Informix.dll...您可以在“Informix Client SDK”包中获取它)应该能够完成非常类似的事情。
下面是一个示例程序:
下面是它生成的输出:
IfxDataReader.GetValue(int)
方法将以本机 .NET Framework 数据类型返回列值。 要获取作为 Informix 类型返回的列值,您必须通过调用GetIfxValue(int)
方法请求按此返回该值,或者如果可以更具体,则通过GetIfxClob(int) 方法。
I asked a colleague about this, and this is his response to me. Since it isn't my handiwork, I've made the answer 'Community Wiki' so I don't get the credit (beyond knowing where to ask).
To answer the question... the following program was written using the Common Informix Provider (the IBM.Data.Informix.dll which uses the DRDA communication protocol... you can get it in the "IBM Data Server Driver for CLI, ODBC, and .NET" package). Something very similar should be able to be done with the Legacy Informix Provider (the IBM.Data.Informix.dll which uses the SQLI communication protocol... you can get it in the "Informix Client SDK" package).
Here's an example program:
And here's the output it generates:
The
IfxDataReader.GetValue(int)
method is going to return the column value in a native .NET Framework data type. To get the column value returned as an Informix type, you must request that it be returned as such by either calling theGetIfxValue(int)
method, or if you can be more specific, by theGetIfxClob(int)
method.