[Mono-bugs] [Bug 74917][Maj] Changed - OdbcParameters not working in Mono 1.1.7

bugzilla-daemon at bugzilla.ximian.com bugzilla-daemon at bugzilla.ximian.com
Wed Jun 22 09:59:14 EDT 2005


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by dfreund at runlevel-5.org.

http://bugzilla.ximian.com/show_bug.cgi?id=74917

--- shadow/74917	2005-06-20 09:40:05.000000000 -0400
+++ shadow/74917.tmp.17304	2005-06-22 09:59:14.000000000 -0400
@@ -307,6 +307,115 @@
 I can do some more tests or try to fix it myself?
 Are queries with parameters using ODBC supposed to work at all?
 
 Any help would be appreciated,
 
 /daniel
+
+------- Additional Comments From dfreund at runlevel-5.org  2005-06-22 09:59 -------
+Did some more tests (Mono 1.1.8/SLES9) and added an integer-column to
+my table, which now looks like this (Firebird isql output):
+SQL> show table t_odbc_test;
+ID                              SMALLINT Not Null
+LAST_NAME                       VARCHAR(20) Nullable
+FIRST_NAME                      CHAR(20) Nullable
+TESTINT                         INTEGER Nullable
+CONSTRAINT PK_T_ODBC_TEST:
+  Primary key (ID)
+SQL> select * from t_odbc_test;
+
+     ID LAST_NAME            FIRST_NAME                TESTINT
+======= ==================== ==================== ============
+
+      1 Dent                 Arthur                         10
+      2 Prefect              Ford                           20
+
+My test programm looks like:
+
+class MainClass
+{
+   public static void Main(string[] args)
+   {
+      string dsn = args[0]; // the ODBC DSN
+      string typ = args[1]; // varchar|char|int
+
+      string DB_CONN = "DSN=" + dsn;
+
+      Console.WriteLine("act. DSN:      " + DB_CONN);
+      Console.WriteLine("act. OdbcType: " + typ);
+
+      using (OdbcConnection conn = new OdbcConnection(DB_CONN)) {
+         conn.Open();
+         OdbcCommand cmdFail = conn.CreateCommand();
+         cmdFail.CommandType = CommandType.Text;
+
+         switch (typ) {
+            case "varchar": // last_name is of type VarChar
+               cmdFail.CommandText =
+                  "SELECT * FROM t_odbc_test WHERE last_name=?";
+                  cmdFail.Parameters.Add("@p1",
+OdbcType.VarChar,20).Value = "Perfect";
+               break;
+            case "char": // first_name is of type Char
+               cmdFail.CommandText =
+                  "SELECT * FROM t_odbc_test WHERE first_name like (?)";
+                  cmdFail.Parameters.Add("@p1",
+OdbcType.Char,20).Value = "Ford%";
+               break;
+            case "int": // testint is of type Integer
+            default:
+               cmdFail.CommandText =
+                  "SELECT * FROM t_odbc_test WHERE testint=?";
+               cmdFail.Parameters.Add("@p1", OdbcType.Int).Value = 20;
+
+               break;
+         }
+
+         OdbcDataReader readerFail = cmdFail.ExecuteReader();
+
+         while (readerFail.Read())
+            Console.WriteLine("--> " + readerFail["LAST_NAME"]);
+
+         readerFail.Close();
+         Console.WriteLine("------------------------------------------");
+      }
+   }
+}
+
+Results:
+When using OdbcType.Int, I get the expected result (GREAT!)
+When using OdbcType.Char, I get an empty result (NOT VERY GOOD)
+When using OdbcType.VarChar, I get an exception (BAD!)
+
+The type of the exception varies between Firebird and Informix.
+Firebird complains the following way:
+
+Unhandled Exception: System.Data.Odbc.OdbcException: [unixODBC]Driver
+not capable
+in <0x001ba> System.Data.Odbc.OdbcParameter:Bind (IntPtr hstmt, Int32
+ParamNum)
+in (wrapper remoting-invoke-with-check)
+System.Data.Odbc.OdbcParameter:Bind (intptr,int)
+[SNIP]
+
+In the sources of OdbcParameter.Bind() there is distinguished between
+int parameters and "the rest":
+
+// Bind parameter based on type
+int ind = -3;
+if (odbcType == OdbcType.Int)
+   ret = libodbc.SQLBindParameter(hstmt, (ushort)ParamNum,
+(short)paramdir,
+                                  ctype, sqltype, Convert.ToUInt32(Size),
+                                  0, ref intbuf, 0, ref ind);
+else
+   ret = libodbc.SQLBindParameter(hstmt, (ushort)ParamNum,
+(short)paramdir,
+                                  ctype, sqltype, Convert.ToUInt32(Size),
+                                  0, buffer, buffer.Length, ref ind);
+
+So I suppose the error is in the way SQLBindparameter is called for
+non int parameters
+
+hope it helps (as long as somebody works on it anyway)
+
+/d


More information about the mono-bugs mailing list