2010-07-12 Veerapuram Varadhan <vvaradhan@novell.com>
[mono.git] / mcs / class / Mono.Data.Tds / Mono.Data.Tds.Protocol / Tds80.cs
index 9cd6825bf6528f33f252605c4901f348a3fa8eba..8d03305578b7c1904985c3412fcad4f32c709629 100644 (file)
@@ -4,6 +4,7 @@
 // Author:
 //   Tim Coleman (tim@timcoleman.com)
 //      Veerapuram Varadhan  (vvaradhan@novell.com)
+//
 // Copyright (C) 2002 Tim Coleman
 // Copyright (C) 2008,2009 Novell Inc.
 //
@@ -60,20 +61,30 @@ namespace Mono.Data.Tds.Protocol {
                protected override byte[] ClientVersion {
                        get { return new byte[] {0x00, 0x0, 0x0, 0x71};}
                }
+               protected override byte Precision {
+                       get { return 38; }
+               }
+               
                #endregion // Properties
                
                #region Methods
 
                public override bool Connect (TdsConnectionParameters connectionParameters)
                {
+                       //Console.WriteLine ("Tds80::Connect");
                        return base.Connect (connectionParameters);
                }
 
-               protected override TdsDataColumnCollection ProcessColumnInfo ()
+               protected override void ProcessColumnInfo ()
                {
+                       // We are connected to a Sql 7.0 server
+                       if (TdsVersion < TdsVersion.tds80) {
+                               base.ProcessColumnInfo ();
+                               return;
+                       }
+                       
                        // VARADHAN: TDS 8 Debugging
                        //Console.WriteLine ("Tds80.cs: In ProcessColumnInfo... entry");
-                       TdsDataColumnCollection result = new TdsDataColumnCollection ();
                        int numColumns = Comm.GetTdsShort ();
                        //Console.WriteLine ("Column count={0}", numColumns); TDS 8 Debugging
                        for (int i = 0; i < numColumns; i += 1) {
@@ -102,6 +113,7 @@ namespace Mono.Data.Tds.Protocol {
                                int columnSize;
                                string tableName = null;
                                byte[] collation = null;
+                               int lcid = 0, sortId = 0;
 
                                if (IsBlobType (columnType)) {
                                        columnSize = Comm.GetTdsInt ();
@@ -119,6 +131,8 @@ namespace Mono.Data.Tds.Protocol {
                                    xColumnType == TdsColumnType.NText) {
                                    // Read collation for SqlServer 2000 and beyond
                                    collation = Comm.GetBytes (5, true);
+                                       lcid = TdsCollation.LCID (collation);
+                                       sortId = TdsCollation.SortId (collation);
                                }
 
                                if (IsBlobType (columnType)) {
@@ -148,7 +162,7 @@ namespace Mono.Data.Tds.Protocol {
                                string columnName = Comm.GetString (Comm.GetByte ());
 
                                TdsDataColumn col = new TdsDataColumn ();
-                               result.Add (col);
+                               Columns.Add (col);
 #if NET_2_0
                                col.ColumnType = columnType;
                                col.ColumnName = columnName;
@@ -160,6 +174,8 @@ namespace Mono.Data.Tds.Protocol {
                                col.IsReadOnly = !writable;
                                col.AllowDBNull = nullable;
                                col.BaseTableName = tableName;
+                               col.LCID = lcid;
+                               col.SortOrder = sortId;
 #else
                                col ["ColumnType"] = columnType;
                                col ["ColumnName"] = columnName;
@@ -171,14 +187,21 @@ namespace Mono.Data.Tds.Protocol {
                                col ["IsReadOnly"] = !writable;
                                col ["AllowDBNull"] = nullable;
                                col ["BaseTableName"] = tableName;
+                               col ["LCID"] = lcid;
+                               col ["SortOrder"] = sortId;
 #endif
                        }
                        //Console.WriteLine ("Tds80.cs: In ProcessColumnInfo... exit");  TDS 8 Debugging
-                       return result;
                }
 
                protected override void ProcessOutputParam ()
                {
+                       // We are connected to a Sql 7.0 server
+                       if (TdsVersion < TdsVersion.tds80) {
+                               base.ProcessOutputParam ();
+                               return;
+                       }
+
                        GetSubPacketLength ();
                        
                        Comm.Skip ((Comm.GetByte () & 0xff) <<1); // Parameter name
@@ -191,6 +214,43 @@ namespace Mono.Data.Tds.Protocol {
                        OutputParameters.Add (value);
                }
                
+               public override void Execute (string commandText, TdsMetaParameterCollection parameters, int timeout, bool wantResults)
+               {
+                       // We are connected to a Sql 7.0 server
+                       if (TdsVersion < TdsVersion.tds80) {
+                               base.Execute (commandText, parameters, timeout, wantResults);
+                               return;
+                       }
+
+                       Parameters = parameters;
+                       string sql = commandText;
+
+                       if (Parameters != null && Parameters.Count > 0) {
+                               ExecRPC (TdsRpcProcId.ExecuteSql, commandText, parameters, timeout, wantResults);
+                       } else {
+                               if (wantResults)
+                                       sql = BuildExec (commandText);
+                               ExecuteQuery (sql, timeout, wantResults);
+                       }
+               }
+               
+               public override void ExecPrepared (string commandText, TdsMetaParameterCollection parameters, int timeout, bool wantResults)
+               {
+                       Parameters = parameters;
+                       // We are connected to a Sql 7.0 server
+                       if (TdsVersion < TdsVersion.tds80 || 
+                           Parameters == null || Parameters.Count < 1) {
+                               base.ExecPrepared (commandText, parameters, timeout, wantResults);
+                               return;
+                       }
+                       TdsMetaParameterCollection parms = new TdsMetaParameterCollection ();
+                       parms.Add (new TdsMetaParameter ("@Handle", "int", Int32.Parse (commandText)));
+                       foreach (TdsMetaParameter parm in Parameters)
+                               parms.Add (parm);
+                       
+                       ExecRPC ("sp_execute", parms, timeout, wantResults);                    
+               }
+
                #endregion // Methods
        }
 }