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

发布于 2024-07-17 21:50:55 字数 640 浏览 5 评论 0原文

我似乎找不到一种方法来获取 .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 技术交流群。

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

发布评论

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

评论(1

宣告ˉ结束 2024-07-24 21:50:55

我向一位同事询问了这个问题,这是他给我的答复。 因为这不是我的作品,所以我已经将答案设为“社区维基”,所以我没有得到荣誉(除了知道在哪里询问之外)。


为了回答这个问题...以下程序是使用 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) 方法。

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:

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();
         }
      }
   }
}

And here's the output it generates:

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

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 the GetIfxValue(int) method, or if you can be more specific, by the GetIfxClob(int) method.

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