2005-01-31 Zoltan Varga <vargaz@freemail.hu>
[mono.git] / mcs / class / Mono.Data.Tds / Mono.Data.Tds.Protocol / Tds42.cs
index 40aec7a81d4abe5a91f8bc85d87e27e26dc61091..7051dd5fb5f90b17467e8fe11858baee7e6e7cad 100644 (file)
@@ -1,5 +1,5 @@
 //
-// Mono.Data.TdsClient.Internal.Tds42.cs
+// Mono.Data.Tds.Protocol.Tds42.cs
 //
 // Author:
 //   Tim Coleman (tim@timcoleman.com)
@@ -7,11 +7,31 @@
 // Copyright (C) 2002 Tim Coleman
 //
 
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
 using System;
-using System.Data.Common;
 
-namespace Mono.Data.TdsClient.Internal {
-        internal class Tds42 : Tds, ITds
+namespace Mono.Data.Tds.Protocol {
+        public class Tds42 : Tds
        {
                #region Fields
 
@@ -22,12 +42,12 @@ namespace Mono.Data.TdsClient.Internal {
                #region Constructors
 
                public Tds42 (string server, int port)
-                       : this (server, port, 512)
+                       : this (server, port, 512, 15)
                {
                }
 
-               public Tds42 (string server, int port, int packetSize)
-                       : base (server, port, packetSize, Version)
+               public Tds42 (string server, int port, int packetSize, int timeout)
+                       : base (server, port, packetSize, timeout, Version)
                {
                }
 
@@ -45,7 +65,6 @@ namespace Mono.Data.TdsClient.Internal {
 
                        byte pad = (byte) 0;
                        byte[] empty = new byte[0];
-                       bool isOkay = true;
 
                        Comm.StartPacket (TdsPacketType.Logon);
 
@@ -193,38 +212,26 @@ namespace Mono.Data.TdsClient.Internal {
 
                        Comm.SendPacket ();
 
-                       TdsPacketResult result;
-
-                       while (!((result = ProcessSubPacket()) is TdsPacketEndTokenResult)) {
-                               if (result is TdsPacketErrorResult) {
-                                       isOkay = false;
-                                       break;
-                               }
-                               // XXX Should really process some more types of packets.
-                       }
+                       MoreResults = true;
+                       SkipToEnd ();
 
-                       // XXX Possible bug.  What happend if this is cancelled before the logon
-                       // takes place?  Should isOkay be false?
-
-                       IsConnected = isOkay;
-                       return isOkay;
+                       return IsConnected;
                }
 
-               protected override TdsPacketColumnInfoResult ProcessColumnInfo ()
+               protected override TdsDataColumnCollection ProcessColumnInfo ()
                {
                        byte precision;
                        byte scale;
                        int totalLength = Comm.GetTdsShort ();
                        int bytesRead = 0;
 
-                       TdsPacketColumnInfoResult result = new TdsPacketColumnInfoResult ();
+                       TdsDataColumnCollection result = new TdsDataColumnCollection ();
 
                        while (bytesRead < totalLength) {
                                scale = 0;
                                precision = 0;
 
                                int bufLength = -1;
-                               //int dispSize = -1;
                                byte[] flagData = new byte[4];
                                for (int i = 0; i < 4; i += 1) {
                                        flagData[i] = Comm.GetByte ();
@@ -265,21 +272,17 @@ namespace Mono.Data.TdsClient.Internal {
                                        bytesRead += 1;
                                }
 
-                               int index = result.Add (new TdsSchemaInfo ());
-                               result[index].NumericPrecision = precision;
-                               result[index].NumericScale = scale;
-                               result[index].ColumnSize = bufLength;
-                               result[index].ColumnName = ColumnNames[index];
-                               result[index].ColumnType = columnType;
-                               result[index].BaseTableName = tableName;
-                               result[index].AllowDBNull = nullable;
-                               result[index].IsReadOnly = !writable;
+                               int index = result.Add (new TdsDataColumn ());
+                               result[index]["NumericPrecision"] = precision;
+                               result[index]["NumericScale"] = scale;
+                               result[index]["ColumnSize"] = bufLength;
+                               result[index]["ColumnName"] = ColumnNames[index];
+                               result[index]["ColumnType"] = columnType;
+                               result[index]["BaseTableName"] = tableName;
+                               result[index]["AllowDBNull"] = nullable;
+                               result[index]["IsReadOnly"] = !writable;
                        }
 
-                       //int skipLength = totalLength - bytesRead;
-                       //if (skipLength != 0)
-                               //throw new TdsException ("skipping");
-
                        return result;
                }