1 Reply Latest reply on Dec 9, 2013 2:33 PM by TSGal

    Reading Text data via ODBC hangs when the text lengh is over 4092

    ranja

      Summary

      Reading Text data via ODBC hangs when the text lengh is over 4092

      Product

      FileMaker Server

      Version

      12

      Operating system version

      Windows Server 2008, Windows 7

      Description of the issue

      When I try to read a text data from a Text column via ODBC, the application hangs if the data length exceeds 4092.
      Oddly enough, however, if the text data consists of Zenkaku characters (multibyte characters), it works fine without hanging.

      Steps to reproduce the problem

      Here is the sample C# code I made to reproduce the problem.
      Field2 column contains a text data of repeating "0123456789", that is, "012345678901234567890123456789...".
      The version of FileMaker ODBC driver is 13.00.12.00(32bit)
      I'm using Visual Studio 2013.

      using (var conn = new System.Data.Odbc.OdbcConnection("Dsn=TestODBC;uid=admin;pwd="))
      {
           conn.Open();
           using (var cmd = conn.CreateCommand())
           {
                cmd.CommandText = "SELECT Field2 FROM TestODBC WHERE ID = 4";
                using (var reader = cmd.ExecuteReader())
                {
                     while (reader.Read())
                     {
                          var Txt = reader.GetString(0);
                     }
                }
           }
      }
      When the length of the text data in Field2 column exceeds 4092, the code hangs at 'var Txt = reader.GetString(0);' line.
      However, if I convert the text data to Zenkaku characters, that is "012345678901234567890123456789...", the code runs without any problem regardless of its length.  I don't know why.

      Configuration information

      I have tested with FileMaker Pro 13 Advanced instead of FileMaker Server 12 Advanced.  But the results were the same.

      Workaround

      The only way I have found to workaround this problem is using GetBytes method.
      Here's the simplified code that works without hanging.

      using (var conn = new System.Data.Odbc.OdbcConnection("Dsn=TestODBC;uid=admin;pwd="))
      {
           conn.Open();
           using (var cmd = conn.CreateCommand())
           {
                cmd.CommandText = "SELECT Field2 FROM TestODBC WHERE ID = 4";

                using (var reader = cmd.ExecuteReader())
                {

                     while (reader.Read())
                     {          
                          int arraySize = 50000;//for simplicity
                          long dataIndex = 0;

                          var buffer = new byte[arraySize];

                          var retval = (int)reader.GetBytes(0, dataIndex, buffer, 0, arraySize);

                          var Txt = System.Text.Encoding.UTF8.GetString(buffer, 0, retval);     
                     }
                }
           }
      }