views:

276

answers:

1

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.

+1  A: 

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.

Jonathan Leffler