Author: suresh
Date: 2005-04-04 03:51:28 -0400 (Mon, 04 Apr 2005)
New Revision: 42502

Modified:
   trunk/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/ChangeLog
   trunk/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/Tds50.cs
Log:
2005-04-04  Sureshkumar T  <[EMAIL PROTECTED]>

        * Tds50.cs: Pass parameters to the server. cut & paste from
        Tds70.cs. To make the parmeters work with SybaseClient.



Modified: trunk/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/ChangeLog
===================================================================
--- trunk/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/ChangeLog      
2005-04-04 04:32:29 UTC (rev 42501)
+++ trunk/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/ChangeLog      
2005-04-04 07:51:28 UTC (rev 42502)
@@ -1,3 +1,8 @@
+2005-04-04  Sureshkumar T  <[EMAIL PROTECTED]>
+
+       * Tds50.cs: Pass parameters to the server. cut & paste from
+       Tds70.cs. To make the parmeters work with SybaseClient.
+
 2005-03-18 Gonzalo Paniagua Javier <[EMAIL PROTECTED]>
 
        * Tds70.cs: turns out that sp_reset_connection procedure might not be

Modified: trunk/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/Tds50.cs
===================================================================
--- trunk/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/Tds50.cs       
2005-04-04 04:32:29 UTC (rev 42501)
+++ trunk/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/Tds50.cs       
2005-04-04 07:51:28 UTC (rev 42502)
@@ -309,9 +309,82 @@
                public override void Execute (string sql, 
TdsMetaParameterCollection parameters, int timeout, bool wantResults)
                {
                        Parameters = parameters;
-                       ExecuteQuery (BuildExec (sql), timeout, wantResults);
+                        string ex = BuildExec (sql);
+                       ExecuteQuery (ex, timeout, wantResults);
                }
 
+               public override void ExecProc (string commandText, 
TdsMetaParameterCollection parameters, int timeout, bool wantResults)
+               {
+                       Parameters = parameters;
+                       ExecuteQuery (BuildProcedureCall (commandText), 
timeout, wantResults);
+               }
+                
+                private string BuildProcedureCall (string procedure)
+               {
+                       string exec = String.Empty;
+
+                       StringBuilder declare = new StringBuilder ();
+                       StringBuilder select = new StringBuilder ();
+                       StringBuilder set = new StringBuilder ();
+                       
+                       int count = 0;
+                       if (Parameters != null) {
+                               foreach (TdsMetaParameter p in Parameters) {
+                                       if (p.Direction != 
TdsParameterDirection.Input) {
+
+                                               if (count == 0)
+                                                       select.Append ("select 
");
+                                               else
+                                                       select.Append (", ");
+                                               select.Append (p.ParameterName);
+                                                       
+                                               declare.Append (String.Format 
("declare {0}\n", p.Prepare ()));
+
+                                               if (p.Direction != 
TdsParameterDirection.ReturnValue) {
+                                                       if( p.Direction == 
TdsParameterDirection.InputOutput )
+                                                               set.Append 
(String.Format ("set {0}\n", FormatParameter(p)));
+                                                       else
+                                               set.Append (String.Format ("set 
{0}=NULL\n", p.ParameterName));
+                                               }
+                                       
+                                               count += 1;
+                                       }
+                                       
+                                       if (p.Direction == 
TdsParameterDirection.ReturnValue) {
+                                               exec = p.ParameterName + "=";
+                                       }
+                               }
+                       }
+                        exec = "exec " + exec;
+                        
+                        string sql = String.Format ("{0}{1}{2}{3} {4}\n{5}", 
declare.ToString (), 
+                                                    set.ToString (), 
+                                                    exec, procedure, 
+                                                    BuildParameters (), 
select.ToString ());
+                       return sql;
+               }
+
+                
+               private string BuildParameters ()
+               {
+                       if (Parameters == null || Parameters.Count == 0)
+                               return String.Empty;
+
+                       StringBuilder result = new StringBuilder ();
+                       foreach (TdsMetaParameter p in Parameters) {
+                               if (p.Direction != 
TdsParameterDirection.ReturnValue) {
+                               if (result.Length > 0)
+                                       result.Append (", ");
+                                       if (p.Direction == 
TdsParameterDirection.InputOutput)
+                                               result.Append 
(String.Format("{0}={0} output", p.ParameterName));
+                                       else
+                               result.Append (FormatParameter (p));
+                       }
+                       }
+                       return result.ToString ();
+               }
+
+
                private string FormatParameter (TdsMetaParameter parameter)
                {
                        if (parameter.Direction == TdsParameterDirection.Output)

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to