Author: anagappan
Date: 2007-07-22 02:31:43 -0400 (Sun, 22 Jul 2007)
New Revision: 82420

Added:
   trunk/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/TdsBulkCopy.cs
Modified:
   trunk/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/ChangeLog
   trunk/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/Tds.cs
   trunk/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/Tds42.cs
   trunk/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/Tds50.cs
   trunk/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/Tds70.cs
   trunk/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/TdsComm.cs
   trunk/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/TdsPacketType.cs
Log:
2007-07-22  Nagappan A  <[EMAIL PROTECTED]>

        * TdsBulkCopy.cs: Added new file to handle the bulk copy
        operation.

        * Tds.cs (ExecBulkCopyMetaData, ExecBulkCopy): Added new methods
        to send and receive bulk data information.

        * Tds70.cs (IsBlobType, IsLargeType): Moved methods to Tds.cs.

        * TdsComm.cs: Fixed 2.0 compilation warnings.

        * Tds50.cs: Fixed compilation warnings.

        * Tds42.cs: Fixed compilation warnings.

        * TdsPacketType.cs: Added Bulk type.



Modified: trunk/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/ChangeLog
===================================================================
--- trunk/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/ChangeLog      
2007-07-21 21:18:51 UTC (rev 82419)
+++ trunk/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/ChangeLog      
2007-07-22 06:31:43 UTC (rev 82420)
@@ -1,3 +1,21 @@
+2007-07-22  Nagappan A  <[EMAIL PROTECTED]>
+
+       * TdsBulkCopy.cs: Added new file to handle the bulk copy
+       operation.
+
+       * Tds.cs (ExecBulkCopyMetaData, ExecBulkCopy): Added new methods
+       to send and receive bulk data information.
+
+       * Tds70.cs (IsBlobType, IsLargeType): Moved methods to Tds.cs.
+
+       * TdsComm.cs: Fixed 2.0 compilation warnings.
+
+       * Tds50.cs: Fixed compilation warnings.
+
+       * Tds42.cs: Fixed compilation warnings.
+
+       * TdsPacketType.cs: Added Bulk type.
+
 2007-05-30  Nagappan A  <[EMAIL PROTECTED]>
 
        * TdsColumnType.cs: Added new types BigNVarChar, Variant to

Modified: trunk/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/Tds.cs
===================================================================
--- trunk/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/Tds.cs 2007-07-21 
21:18:51 UTC (rev 82419)
+++ trunk/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/Tds.cs 2007-07-22 
06:31:43 UTC (rev 82420)
@@ -422,6 +422,26 @@
                        throw new NotSupportedException ();
                }
 
+               internal void ExecBulkCopyMetaData (int timeout, bool 
wantResults)
+               {
+                       moreResults = true;
+                       Comm.SendPacket ();
+
+                       CheckForData (timeout);
+                       if (!wantResults) 
+                               SkipToEnd ();
+               }
+
+               internal void ExecBulkCopy (int timeout, bool wantResults)
+               {
+                       moreResults = true;
+                       Comm.SendPacket ();
+
+                       CheckForData (timeout);
+                       if (!wantResults) 
+                               SkipToEnd ();
+               }
+
                protected void ExecuteQuery (string sql, int timeout, bool 
wantResults)
                {
                        InitExec ();
@@ -1046,6 +1066,16 @@
                        return result;
                }
 
+                internal bool IsBlobType (TdsColumnType columnType)
+               {
+                       return (columnType == TdsColumnType.Text || columnType 
== TdsColumnType.Image || columnType == TdsColumnType.NText);
+               }
+
+                internal bool IsLargeType (TdsColumnType columnType)
+               {
+                       return ((byte) columnType > 128);
+               }
+
                internal static bool IsFixedSizeColumn (TdsColumnType 
columnType)
                {
                        switch (columnType) {
@@ -1239,7 +1269,6 @@
                        Comm.Skip (1);
 
                        int rowCount = comm.GetTdsInt ();
-
                        bool validRowCount = IsValidRowCount (status,op);
                        moreResults = ((status & 0x01) != 0);
                        bool cancelled = ((status & 0x20) != 0);

Modified: trunk/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/Tds42.cs
===================================================================
--- trunk/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/Tds42.cs       
2007-07-21 21:18:51 UTC (rev 82419)
+++ trunk/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/Tds42.cs       
2007-07-22 06:31:43 UTC (rev 82420)
@@ -238,9 +238,9 @@
                                        bytesRead += 1;
                                }
                                bool nullable = (flagData[2] & 0x01) > 0;
-                               bool caseSensitive = (flagData[2] & 0x02) > 0;
+                               //bool caseSensitive = (flagData[2] & 0x02) > 0;
                                bool writable = (flagData[2] & 0x0c) > 0;
-                               bool autoIncrement = (flagData[2] & 0x10) > 0;
+                               //bool autoIncrement = (flagData[2] & 0x10) > 0;
 
                                string tableName = String.Empty;
                                TdsColumnType columnType = (TdsColumnType) 
Comm.GetByte ();

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       
2007-07-21 21:18:51 UTC (rev 82419)
+++ trunk/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/Tds50.cs       
2007-07-22 06:31:43 UTC (rev 82420)
@@ -256,7 +256,7 @@
 
                        // length of tds packets
                        // 557-563
-                       tmp = Comm.Append (PacketSize.ToString (), 6, pad);
+                       tmp = Comm.Append (this.packetSize.ToString (), 6, pad);
                        Comm.Append ((byte) (tmp.Length < 6 ? tmp.Length : 6));
 
                        Comm.Append (empty, 8, pad);
@@ -438,7 +438,7 @@
                                idBuilder.Append ((char) (rand.Next (26) + 65));
                        string id = idBuilder.ToString ();
 
-                       StringBuilder declare = new StringBuilder ();
+                       //StringBuilder declare = new StringBuilder ();
 
                
                        sql = String.Format ("create proc {0} as\n{1}", id, 
sql);
@@ -465,7 +465,7 @@
                {
                        isSelectQuery = true; 
                        TdsDataColumnCollection result = new 
TdsDataColumnCollection ();
-                       int totalLength = Comm.GetTdsShort ();  
+                       /*int totalLength = */Comm.GetTdsShort ();      
                        int count = Comm.GetTdsShort ();
                        for (int i = 0; i < count; i += 1) {
                                string columnName = Comm.GetString 
(Comm.GetByte ());

Modified: trunk/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/Tds70.cs
===================================================================
--- trunk/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/Tds70.cs       
2007-07-21 21:18:51 UTC (rev 82419)
+++ trunk/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/Tds70.cs       
2007-07-22 06:31:43 UTC (rev 82420)
@@ -415,7 +415,6 @@
                        CheckForData (timeout);
                        if (!wantResults) 
                                SkipToEnd ();
-
                }
 
                private void WriteParameterInfo (TdsMetaParameter param)
@@ -517,16 +516,6 @@
                        ExecuteQuery (sql, timeout, wantResults);
                }
 
-                private bool IsBlobType (TdsColumnType columnType)
-               {
-                       return (columnType == TdsColumnType.Text || columnType 
== TdsColumnType.Image || columnType == TdsColumnType.NText);
-               }
-
-                private bool IsLargeType (TdsColumnType columnType)
-               {
-                       return ((byte) columnType > 128);
-               }
-
                private string FormatParameter (TdsMetaParameter parameter)
                {
                        string includeAt = "@";
@@ -626,7 +615,7 @@
                                        flagData[j] = Comm.GetByte ();
 
                                bool nullable = (flagData[2] & 0x01) > 0;
-                               bool caseSensitive = (flagData[2] & 0x02) > 0;
+                               //bool caseSensitive = (flagData[2] & 0x02) > 0;
                                bool writable = (flagData[2] & 0x0c) > 0;
                                bool autoIncrement = (flagData[2] & 0x10) > 0;
                                bool isIdentity = (flagData[2] & 0x10) > 0;

Added: trunk/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/TdsBulkCopy.cs
===================================================================
--- trunk/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/TdsBulkCopy.cs 
2007-07-21 21:18:51 UTC (rev 82419)
+++ trunk/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/TdsBulkCopy.cs 
2007-07-22 06:31:43 UTC (rev 82420)
@@ -0,0 +1,148 @@
+//
+// Mono.Data.Tds.Protocol.TdsBulkCopy.cs
+//
+// Author:
+//   Nagappan A ([EMAIL PROTECTED])
+//
+// Copyright (C) 2007 Novell Inc
+
+//
+// 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.
+//
+#if NET_2_0
+using Mono.Security.Protocol.Ntlm;
+using System;
+using System.Collections;
+using System.ComponentModel;
+using System.Diagnostics;
+using System.Net.Sockets;
+using System.Text;
+
+namespace Mono.Data.Tds.Protocol {
+        public class TdsBulkCopy
+       {
+               #region Fields
+
+               Tds tds;
+               #endregion
+
+               #region Constructors
+
+               public TdsBulkCopy (Tds tds)
+               {
+                       this.tds = tds;
+               }
+
+               #endregion
+
+               #region Methods
+               public bool SendColumnMetaData (string colMetaData)
+               {
+                       tds.Comm.StartPacket (TdsPacketType.Query);
+                       tds.Comm.Append (colMetaData);
+                       tds.ExecBulkCopyMetaData (30, false);
+                       return true;
+               }
+
+               public bool BulkCopyStart (TdsMetaParameterCollection 
parameters)
+               {
+                       tds.Comm.StartPacket (TdsPacketType.Bulk);
+                       tds.Comm.Append ((byte) 
TdsPacketSubType.ColumnMetadata);
+                       short count = 0;
+                       foreach (TdsMetaParameter param in parameters) {
+                               if (param.Value != null)
+                                       continue;
+                               count++;
+                       }
+                       tds.Comm.Append (count);
+                       if (parameters != null) {
+                               foreach (TdsMetaParameter param in parameters) {
+                                       if (param.Value != null)
+                                               continue;
+                                       tds.Comm.Append ((short) 0x00);
+                                       tds.Comm.Append ((short) 0x0a);
+                                       WriteParameterInfo (param);
+                                       tds.Comm.Append ((byte) 
param.ParameterName.Length);
+                                       tds.Comm.Append (param.ParameterName);
+                               }
+                       }
+                       return true;
+               }
+
+               public bool BulkCopyData (object o, int size, bool isNewRow)
+               {
+                       if (isNewRow) {
+                               tds.Comm.Append ((byte) TdsPacketSubType.Row);
+                       }
+                       if (size > 0) {
+                               tds.Comm.Append ((short) size);
+                       }
+                       tds.Comm.Append (o);
+                       return true;
+               }
+
+               public bool BulkCopyEnd ()
+               {
+                       tds.Comm.Append ((short) TdsPacketSubType.Done);
+                       tds.ExecBulkCopy (30, false);
+                       return true;
+               }
+
+               private void WriteParameterInfo (TdsMetaParameter param)
+               {
+                       /*
+                       Ms.net send non-nullable datatypes as nullable and 
allows setting null values
+                       to int/float etc.. So, using Nullable form of type for 
all data
+                       */
+                       param.IsNullable = true;
+                       TdsColumnType colType = param.GetMetaType ();
+                       param.IsNullable = false;
+
+                       tds.Comm.Append ((byte)colType); // type
+                               
+                       int size = 0;
+                       if (param.Size == 0)
+                               size = param.GetActualSize ();
+                       else
+                               size = param.Size;
+
+                       /*
+                         If column type is SqlDbType.NVarChar the size of 
parameter is multiplied by 2
+                         FIXME: Need to check for other types
+                        */
+                       if (colType == TdsColumnType.BigNVarChar)
+                               size <<= 1;
+                       if (tds.IsLargeType (colType))
+                               tds.Comm.Append ((short)size); // Parameter 
size passed in SqlParameter
+                       else if (tds.IsBlobType (colType))
+                               tds.Comm.Append (size); // Parameter size 
passed in SqlParameter
+                       else 
+                               tds.Comm.Append ((byte)size);
+
+                       // Precision and Scale are non-zero for only 
decimal/numeric
+                       if ( param.TypeName == "decimal" || param.TypeName == 
"numeric") {
+                               tds.Comm.Append 
((param.Precision!=0)?param.Precision:(byte)28);
+                               tds.Comm.Append (param.Scale);
+                       }
+               }
+               #endregion
+       }
+}
+#endif

Modified: trunk/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/TdsComm.cs
===================================================================
--- trunk/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/TdsComm.cs     
2007-07-21 21:18:51 UTC (rev 82419)
+++ trunk/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/TdsComm.cs     
2007-07-22 06:31:43 UTC (rev 82420)
@@ -91,7 +91,11 @@
                        
                        try {
                                socket = new Socket 
(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
-                               IPHostEntry hostEntry = Dns.Resolve 
(dataSource);
+#if NET_2_0
+                               IPHostEntry hostEntry = Dns.GetHostEntry 
(this.dataSource);
+#else
+                               IPHostEntry hostEntry = Dns.Resolve 
(this.dataSource);
+#endif
                                endPoint = new IPEndPoint 
(hostEntry.AddressList [0], port);
 
                                // This replaces the code below for now
@@ -345,7 +349,6 @@
                                // out of data, read another physical packet.
                                GetPhysicalPacket ();
                        }
-
                        result = inBuffer[inBufferIndex++];
                        return result;
                }
@@ -432,8 +435,9 @@
                public int GetTdsInt ()
                {
                        byte[] input = new byte[4];
-                       for (int i = 0; i < 4; i += 1)
+                       for (int i = 0; i < 4; i += 1) {
                                input[i] = GetByte ();
+                       }
                        if(!BitConverter.IsLittleEndian)
                                return (BitConverter.ToInt32 (Swap (input), 0));
                        else
@@ -473,7 +477,6 @@
 
                        // figure out how many bytes are remaining in this 
packet.
                        int len = Ntohs (tmpBuf, 2) - 8;
-
                        if (len >= inBuffer.Length) 
                                inBuffer = new byte[len];
 
@@ -492,7 +495,6 @@
                        while (nread < length) {
                                nread += stream.Read (inBuffer, nread, length - 
nread);
                        }
-
                        packetsReceived++;
 
                        // adjust the bookkeeping info about the incoming buffer

Modified: trunk/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/TdsPacketType.cs
===================================================================
--- trunk/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/TdsPacketType.cs       
2007-07-21 21:18:51 UTC (rev 82419)
+++ trunk/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/TdsPacketType.cs       
2007-07-22 06:31:43 UTC (rev 82420)
@@ -36,9 +36,10 @@
                None = 0x0,
                Query = 0x1,
                Logon = 0x2,
-               Proc = 0x3,                     
+               Proc = 0x3,
                Reply = 0x4,
                Cancel = 0x6,
+               Bulk = 0x7,
                Logon70 = 0x10,
                SspAuth = 0x11,
                Logoff = 0x71,

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

Reply via email to