如何从.net中的Informix查询中获取IfxBlob?

时间:2009-04-22 15:07:56

标签: vb.net informix

我似乎无法找到一种方法来获取.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

或类似的东西。

1 个答案:

答案 0 :(得分: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”包中获取它。

这是一个示例程序:

using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using IBM.Data.Informix;

namespace InformixClob
{
   class Program
   {
      static void Main(string[] args)
      {
         try
         {
            IfxConnection tConn = new IfxConnection("database=idsdb;server=my-system:9089;uid=informix;pwd=********");
            tConn.Open();

            IfxCommand tCmd = tConn.CreateCommand();
            // create table mytesttab (col1 integer, col2 clob)
            tCmd.CommandText = "select * from mytesttab";
            IfxDataReader tRdr = tCmd.ExecuteReader();
            while (tRdr.Read())
            {
               Console.WriteLine("Col1 is a {0}", tRdr.GetValue(0).GetType());
               Console.WriteLine("Col2(GetValue) is a {0}", tRdr.GetValue(1).GetType());
               Console.WriteLine("Col2(GetIfxValue) is a {0}", tRdr.GetIfxValue(1).GetType());
               Console.WriteLine("Col2(GetIfxClob) is a {0}", tRdr.GetIfxClob(1).GetType());
            }
            tRdr.Close();
            tConn.Close();
         }
         catch (Exception e)
         {
            Console.WriteLine(e.ToString());
         }
         finally
         {
            Console.Write("Press ENTER"); Console.ReadLine();
         }
      }
   }
}

这是它产生的输出:

Col1 is a System.Int32
Col2(GetValue) is a System.String
Col2(GetIfxValue) is a IBM.Data.Informix.IfxClob
Col2(GetIfxClob) is a IBM.Data.Informix.IfxClob
Press ENTER

IfxDataReader.GetValue(int)方法将返回本机.NET Framework数据类型中的列值。要获取作为Informix类型返回的列值,您必须通过调用GetIfxValue(int)方法或通过GetIfxClob(int)方法更具体地请求返回它。