[Mono-bugs] [Bug 466071] New: Mono.Data.Tds.Protocol.Tds70: Wrong SQL generated for parameter name without @ with NULL value

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Wed Jan 14 11:13:26 EST 2009


https://bugzilla.novell.com/show_bug.cgi?id=466071


           Summary: Mono.Data.Tds.Protocol.Tds70: Wrong SQL generated for
                    parameter name without @ with NULL value
    Classification: Mono
           Product: Mono: Class Libraries
           Version: unspecified
          Platform: Macintosh
        OS/Version: Mac OS X 10.5
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: Sys.Data.SqlClient
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: william.shallum at gmail.com
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---


User-Agent:       Opera/9.63 (Macintosh; Intel Mac OS X; U; en) Presto/2.1.1

in Mono.Data.Tds.Protocol/Tds70.cs
private string FormatParameter (TdsMetaParameter parameter) 
generates wrong results for parameterName without leading "@" that has NULL
value.

I am using 2.0.1 on OSX but looking at the code in current SVN  (r122385),
problem seems to exist there too.



Reproducible: Always

Steps to Reproduce:
loumz at Sylphie:/tmp/s $ cat t.cs
using System.Data.SqlClient;

class X {
  static void Main() {
    SqlConnection c = new SqlConnection();
    c.ConnectionString=@"Server=localhost;Initial Catalog=tudung;User
ID=ARABICA\Administrator;Password=root;Integrated Security=SSPI";
    c.Open();
    SqlCommand cmd = c.CreateCommand();
    cmd.CommandText = "INSERT INTO t (c) VALUES (@c)";
    SqlParameter p = cmd.CreateParameter(); 
    p.ParameterName = "c"; p.Value = null; 
    cmd.Parameters.Add(p);
    cmd.ExecuteNonQuery();
    c.Close();
  }
}
loumz at Sylphie:/tmp/s $ mcs /r:System.Data t.cs
loumz at Sylphie:/tmp/s $ mono t.exe

Actual Results:  
Mono sends:
exec sp_executesql N'INSERT INTO t (c) VALUES (@c), N'@c nvarchar(4000)',
c=NULL

Results in:
Unhandled Exception: System.Data.SqlClient.SqlException: Line 1: Incorrect
syntax near '='.
<snip stack trace>

Expected Results:  
Should send:

exec sp_executesql N'INSERT INTO t (c) VALUES (@c), N'@c nvarchar(4000)',
@c=NULL


fix for current SVN:

if (parameter.Value == null || parameter.Value == DBNull.Value)
                return parameter.ParameterName + "=NULL";

->

if (parameter.Value == null || parameter.Value == DBNull.Value)
                return "@" + parameter.ParameterName + "=NULL";

-- 
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.


More information about the mono-bugs mailing list