diff options
author | Tim Coleman <tim@mono-cvs.ximian.com> | 2002-11-21 21:14:49 +0300 |
---|---|---|
committer | Tim Coleman <tim@mono-cvs.ximian.com> | 2002-11-21 21:14:49 +0300 |
commit | 5715ac36a50bbe9a97bdecf2e2e59493ba0f53ac (patch) | |
tree | 741bbe14ed14748f8a14fd3eafa2c839dc5f5fe7 /mcs/class/Mono.Data.TdsClient | |
parent | bc16469907ae12ebf94874090bddb3bf12f7d780 (diff) |
2002-11-21 Tim Coleman <tim@timcoleman.com>
* ChangeLog:
* *.cs:
These files have been moved to Mono.Data.Tds.Protocol.
svn path=/trunk/mcs/; revision=9140
Diffstat (limited to 'mcs/class/Mono.Data.TdsClient')
39 files changed, 0 insertions, 4225 deletions
diff --git a/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/ChangeLog b/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/ChangeLog deleted file mode 100644 index 32577aaa5d5..00000000000 --- a/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/ChangeLog +++ /dev/null @@ -1,233 +0,0 @@ -2002-11-04 Tim Coleman (tim@timcoleman.com) - * TdsBigDecimal.cs: - New class added to handle (potentially) large - decimal values - * Tds.cs: - Modified to use TdsBigDecimal instead of - decimal for transit of (potentially) large - decimal values - -2002-11-03 Tim Coleman (tim@timcoleman.com) - * TdsColumnStatus.cs: - Newly added to handle column metadata - * Tds.cs - Handle table name and column detail results - * Tds42.cs - * Tds50.cs - * Tds70.cs - rename TableName BaseTableName for consistency - * TdsPacketSubType.cs: - We now know what subtype 0xa5 is - * TdsPacketTableNameResult.cs: - Add means to store table names - * TdsSchemaInfo.cs: - Add new schema information - -2002-11-01 Tim Coleman (tim@timcoleman.com) - * ITds.cs: - Add DoneProc property - * Tds.cs: - *Lots*. Some stuff to get binary types - to work, other stuff to get new prepares - working. - * TdsPacketEndTokenResult.cs: - Add Packetsubtype property - * TdsPacketRowResult: - Now implements ICollection and IList. - -2002-10-31 Tim Coleman (tim@timcoleman.com) - * TdsSchemaInfo.cs: - Added because I can't really use SchemaInfo - * ITds.cs: - * Tds.cs : - * TdsPacketColumnInfoResult.cs : - ChangeDefinition of schema - * Tds42.cs : - * Tds50.cs : - * Tds70.cs : - Add new information to schema - - -2002-10-30 Tim Coleman (tim@timcoleman.com) - * TdsColumnSchema.cs: - Ditch this in favor of System.Data.Common.SchemaInfo - * ITds.cs: - Change ColumnInfo to Schema - * Tds.cs: - Uses new SchemaInfo object - Supports TEXT now. - * Tds42.cs: - * Tds50.cs: - * Tds70.cs: - * TdsPacketColumnInfoResult.cs: - * TdsPacketRowResult.cs: - Uses new SchemaInfo object - - -2002-10-29 Tim Coleman (tim@timcoleman.com) - * ITds.cs: - Add OutputParameters collection - * Tds.cs: - Much reformatting, added handling for dates, - fixed handling of output parameters, and a - whole lot more - * TdsPacketEndTokenResult.cs: - Remove incorrect exception - * TdsPacketType.cs: - Add Logoff packet type. - -2002-10-28 Tim Coleman (tim@timcoleman.com) - * Tds.cs: - Add much handling to get the following types - working in queries: string, int, decimal - All sorts of other bug fixing and general - purpose hackery. - * Tds42.cs: - * Tds50.cs: - * Tds70.cs: - ProcessColumnInfo was abstracted in Tds.cs - and subclassed, because 7.0 provides the information - in a different format. - * TdsColumnSchema.cs: - Added size, precision, scale - * TdsComm.cs: - Fixed GetString because it wasn't working properly - with TDS 7.0. - * TdsMessage.cs: - Change state and severity to byte instead of int - because that is more consitent. - - -2002-10-25 Tim Coleman (tim@timcoleman.com) - * TdsPacketErrorResultCollection.cs: - New class added for exporting errors - * ITds.cs: - * Tds.cs: - * Tds70.cs: - * TdsComm.cs: - * TdsPacketEndTokenResult.cs: - * TdsPacketRowResult.cs: - Changes to make SqlClient build. - -2002-10-24 Tim Coleman (tim@timcoleman.com) - * ITds.cs: - Added column info, and NextResult/NextRow - to interface - * TdsColumnSchema.cs: - New class added to keep track of column info - * Tds.cs: - Many, many changes to get queries working - for the most part. - * TdsPacketColumnInfoResult.cs: - * TdsPacketColumnNamesResult.cs: - Doesn't use a DataColumnCollection anymore - Also more complete. - * TdsPacketRowResult.cs: - Added Add() method. - -2002-10-23 Tim Coleman (tim@timcoleman.com) - * ITds.cs: - * Tds42.cs: - * Tds50.cs: - * Tds70.cs: - * Tds80.cs: - New classes added. Functionality - is split up because different protocols - have slight differences. - * Tds.cs: - Remove some unnecessary code after - the above split, and add in a whole - lot more stuff for completeness. - * TdsColumnType.cs: - Fix Int4. Wrong enum value. - * TdsComm.cs: - Move the encoder out of constructor - because we don't know the charset at - that point - * TdsConnectionParameters.cs: - Small changes - * TdsPacketEndTokenResult.cs: - Implement ToString () - - -2002-10-22 Tim Coleman (tim@timcoleman.com) - * Tds.cs : - More implementation. Does some - query stuff now. Can also change - database. - * TdsConnectionParameters.cs: - Rename Host to DataSource, and - add Hostname for the local hostname. - * TdsPacketEndTokenResult.cs: - Change TODO attribute - * TODOAttribute.cs: - New class added - - -2002-10-21 Tim Coleman (tim@timcoleman.com) - * Tds.cs - * TdsComm.cs: - A whole slew of changes to get logon - to work (it now works in both TDS 7.0 - and TDS 4.2) ... danmorg can test with - 8.0 if he likes. - TdsComm has some simplifications too, - because C# has some features not present - in the Java implementation. - * TdsConnectionParameters.cs: - Change a few default values. - * TdsMessage.cs: - Implement this class. - -2002-10-20 Tim Coleman (tim@timcoleman.com) - * TdsColumnType.cs: - * TdsContext.cs: - * TdsEnvPacketSubType.cs: - * TdsMessage.cs: - * TdsPacketColumnInfoResult.cs: - * TdsPacketColumnNamesResult.cs: - * TdsPacketColumnOrderResult.cs: - * TdsPacketControlResult.cs: - * TdsPacketEndTokenResult.cs: - * TdsPacketErrorResult.cs: - * TdsPacketMessageResult.cs: - * TdsPacketOutputParam.cs: - * TdsPacketResult.cs: - * TdsPacketRetStatResult.cs: - * TdsPacketRowResult.cs: - * TdsPacketSubType.cs: - * TdsPacketTableNameResult.cs: - * TdsPacketUnknown.cs: - New classes added as part of TDS internal implementation. - * Tds.cs: - Some work on receiving and interpreting packages received from - SQL Server. Still doesn't work completely. - * TdsComm.cs: - Add some methods as part of the ongoing work with Tds.cs - * TdsConnectionParameters.cs: - Add default values for Encoding ("iso-8859-1"), Port (1433), - TDS Version (4.2). - -2002-10-18 Tim Coleman (tim@timcoleman.com) - * TdsConnectionInternal: - Add some implementation details - * TdsCommInternal: - New class, which will handle the low-level - communication with the database - * TdsPacketTypeInternal: - Add new packet type, TdsPacketTypeInternal.None - which is used when no packet is being constructed. - The value is 0. - -2002-10-17 Tim Coleman (tim@timcoleman.com) - * ChangeLog: - New changelog added - * TdsCommandInternal.cs: - * TdsConnectionInternal.cs: - * TdsPacketTypeInternal.cs: - * TdsServerTypeInternal.cs: - * TdsTransactionInternal.cs: - * TdsVersionInternal.cs: - New classes added. These are the - internal implementations, meant for - "wrapping" from other locations. diff --git a/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/ITds.cs b/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/ITds.cs deleted file mode 100644 index 1ec1fbaab67..00000000000 --- a/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/ITds.cs +++ /dev/null @@ -1,79 +0,0 @@ -// -// Mono.Data.TdsClient.Internal.ITds.cs -// -// Author: -// Tim Coleman (tim@timcoleman.com) -// -// Copyright (C) 2002 Tim Coleman -// - -using System; -using System.Collections; - -namespace Mono.Data.TdsClient.Internal { - internal interface ITds - { - #region Properties - - string Database { - get; - } - - bool DoneProc { - get; - } - - bool IsConnected { - get; - } - - string ServerVersion { - get; - } - - TdsPacketColumnInfoResult Schema { - get; - } - - TdsPacketRowResult ColumnValues { - get; - } - - ArrayList OutputParameters { - get; - set; - } - - int RecordsAffected { - get; - set; - } - - #endregion // Properties - - #region Methods - - void Cancel (); - bool Connect (TdsConnectionParameters connectionParameters); - void Disconnect (); - - int ExecuteNonQuery (string sql); - int ExecuteNonQuery (string sql, int timeout); - - void ExecuteQuery (string sql); - void ExecuteQuery (string sql, int timeout); - - bool NextResult (); - bool NextRow (); - void SkipToEnd (); - - #endregion - - #region Events - - event TdsInternalErrorMessageEventHandler TdsErrorMessage; - event TdsInternalInfoMessageEventHandler TdsInfoMessage; - - #endregion // Events - } -} diff --git a/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TODOAttribute.cs b/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TODOAttribute.cs deleted file mode 100644 index 6bc03fb776f..00000000000 --- a/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TODOAttribute.cs +++ /dev/null @@ -1,33 +0,0 @@ -// -// TODOAttribute.cs -// -// Author: -// Ravi Pratap (ravi@ximian.com) -// -// (C) Ximian, Inc. http://www.ximian.com -// -using System; - -namespace Mono.Data.TdsClient.Internal { - - /// <summary> - /// The TODO attribute is used to flag all incomplete bits in our class libraries - /// </summary> - /// - /// <remarks> - /// Use this to decorate any element which you think is not complete - /// </remarks> - [AttributeUsage (AttributeTargets.All)] - internal class MonoTODOAttribute : Attribute { - - string comment; - - public MonoTODOAttribute () - {} - - public MonoTODOAttribute (string comment) - { - this.comment = comment; - } - } -} diff --git a/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/Tds.cs b/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/Tds.cs deleted file mode 100644 index e97040c71d6..00000000000 --- a/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/Tds.cs +++ /dev/null @@ -1,1225 +0,0 @@ -// -// Mono.Data.TdsClient.Internal.Tds.cs -// -// Author: -// Tim Coleman (tim@timcoleman.com) -// -// Copyright (C) 2002 Tim Coleman -// - -using System; -using System.Collections; -using System.ComponentModel; -using System.Diagnostics; -using System.Net.Sockets; -using System.Text; - -namespace Mono.Data.TdsClient.Internal { - internal abstract class Tds : Component, ITds - { - #region Fields - - TdsComm comm; - TdsVersion tdsVersion; - - int packetSize; - string dataSource; - string database; - string databaseProductName; - string databaseProductVersion; - int databaseMajorVersion; - - string charset; - string language; - - bool connected = false; - bool moreResults; - - Encoding encoder; - TdsServerType serverType; - bool autoCommit; - - bool doneProc; - TdsPacketRowResult currentRow = null; - TdsPacketColumnNamesResult columnNames; - TdsPacketColumnInfoResult columnInfo; - TdsPacketTableNameResult tableNames; - - bool queryInProgress; - int cancelsRequested; - int cancelsProcessed; - - bool isDone; - bool isDoneInProc; - - ArrayList outputParameters = new ArrayList (); - protected TdsInternalErrorCollection messages = new TdsInternalErrorCollection (); - - int recordsAffected = 0; - - #endregion // Fields - - #region Properties - - protected string Charset { - get { return charset; } - } - - public bool DoneProc { - get { return doneProc; } - } - - protected string Language { - get { return language; } - } - - protected TdsPacketColumnNamesResult ColumnNames { - get { return columnNames; } - } - - public TdsPacketRowResult ColumnValues { - get { return currentRow; } - } - - protected TdsComm Comm { - get { return comm; } - } - - public string Database { - get { return database; } - } - - public string DataSource { - get { return dataSource; } - } - - public bool IsConnected { - get { return connected; } - set { connected = value; } - } - - public bool MoreResults { - get { return moreResults; } - } - - public int PacketSize { - get { return packetSize; } - } - - public int RecordsAffected { - get { return recordsAffected; } - set { recordsAffected = value; } - } - - public string ServerVersion { - get { return databaseProductVersion; } - } - - public TdsPacketColumnInfoResult Schema { - get { return columnInfo; } - } - - public TdsVersion TdsVersion { - get { return tdsVersion; } - } - - public ArrayList OutputParameters { - get { return outputParameters; } - set { outputParameters = value; } - } - - #endregion // Properties - - #region Events - - public event TdsInternalErrorMessageEventHandler TdsErrorMessage; - public event TdsInternalInfoMessageEventHandler TdsInfoMessage; - - #endregion // Events - - #region Constructors - - public Tds (string dataSource, int port, int packetSize, int timeout, TdsVersion tdsVersion) - { - this.tdsVersion = tdsVersion; - this.packetSize = packetSize; - this.dataSource = dataSource; - - comm = new TdsComm (dataSource, port, packetSize, timeout, tdsVersion); - } - - #endregion // Constructors - - #region Public Methods - - public void Cancel () - { - if (queryInProgress) { - if (cancelsRequested == cancelsProcessed) { - comm.StartPacket (TdsPacketType.Cancel); - comm.SendPacket (); - cancelsRequested += 1; - } - } - } - - public abstract bool Connect (TdsConnectionParameters connectionParameters); - - public static TdsTimeoutException CreateTimeoutException (string dataSource, string method) - { - string message = "Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding."; - return new TdsTimeoutException (0, 0, message, -2, method, dataSource, "Mono TdsClient Data Provider", 0); - } - - public void Disconnect () - { - TdsPacketResult result = null; - - comm.StartPacket (TdsPacketType.Logoff); - comm.Append ((byte) 0); - comm.SendPacket (); - - bool done = false; - do { - result = ProcessSubPacket (); - if (result != null) { - switch (result.GetType ().ToString ()) { - case "Mono.Data.TdsClient.Internal.TdsPacketEndTokenResult" : - done = !((TdsPacketEndTokenResult) result).MoreResults; - break; - } - } - } while (!done); - } - - public int ExecuteNonQuery (string sql) - { - return ExecuteNonQuery (sql, 0); - } - - public int ExecuteNonQuery (string sql, int timeout) - { - TdsPacketResult result = null; - messages.Clear (); - doneProc = false; - - if (sql.Length > 0) { - comm.StartPacket (TdsPacketType.Query); - comm.Append (sql); - comm.SendPacket (); - } - - CheckForData (timeout); - - bool done = false; - while (!done) { - result = ProcessSubPacket (); - - if (result != null) { - switch (result.GetType ().ToString ()) { - case "Mono.Data.TdsClient.Internal.TdsPacketColumnNamesResult" : - columnNames = (TdsPacketColumnNamesResult) result; - break; - case "Mono.Data.TdsClient.Internal.TdsPacketColumnInfoResult" : - columnInfo = (TdsPacketColumnInfoResult) result; - break; - case "Mono.Data.TdsClient.Internal.TdsPacketRowResult" : - currentRow = (TdsPacketRowResult) result; - break; - case "Mono.Data.TdsClient.Internal.TdsPacketTableNameResult" : - tableNames = (TdsPacketTableNameResult) result; - break; - case "Mono.Data.TdsClient.Internal.TdsPacketEndTokenResult" : - done = !((TdsPacketEndTokenResult) result).MoreResults; - break; - } - } - } - if (sql.Trim ().ToUpper ().StartsWith ("SELECT")) - recordsAffected = -1; - else - recordsAffected = ((TdsPacketEndTokenResult) result).RowCount; - return recordsAffected; - - } - - public void ExecuteQuery (string sql) - { - ExecuteQuery (sql, 0); - } - - public void ExecuteQuery (string sql, int timeout) - { - moreResults = true; - doneProc = false; - outputParameters.Clear (); - - if (sql.Length > 0) { - comm.StartPacket (TdsPacketType.Query); - comm.Append (sql); - comm.SendPacket (); - } - - CheckForData (timeout); - } - - public bool NextResult () - { - if (!moreResults) - return false; - TdsPacketResult result = null; - - bool done = false; - while (!done) { - result = ProcessSubPacket (); - - if (result != null) { - switch (result.GetType ().ToString ()) { - case "Mono.Data.TdsClient.Internal.TdsPacketColumnNamesResult" : - columnNames = (TdsPacketColumnNamesResult) result; - break; - case "Mono.Data.TdsClient.Internal.TdsPacketColumnInfoResult" : - columnInfo = (TdsPacketColumnInfoResult) result; - if (comm.Peek () != (byte) TdsPacketSubType.TableName) { - return true; - } - break; - case "Mono.Data.TdsClient.Internal.TdsPacketRowResult" : - currentRow = (TdsPacketRowResult) result; - break; - case "Mono.Data.TdsClient.Internal.TdsPacketTableNameResult" : - tableNames = (TdsPacketTableNameResult) result; - break; - case "Mono.Data.TdsClient.Internal.TdsPacketEndTokenResult" : - done = !((TdsPacketEndTokenResult) result).MoreResults; - break; - } - } - } - - return false; - } - - public bool NextRow () - { - TdsPacketResult result = null; - bool done = false; - do { - result = ProcessSubPacket (); - if (result != null) { - switch (result.GetType ().ToString ()) { - case "Mono.Data.TdsClient.Internal.TdsPacketRowResult" : - currentRow = (TdsPacketRowResult) result; - return true; - case "Mono.Data.TdsClient.Internal.TdsPacketEndTokenResult" : - return false; - } - } - } while (!done); - - return false; - } - - public void SkipToEnd () - { - while (moreResults) - NextResult (); - } - - #endregion // Public Methods - - #region // Private Methods - - [MonoTODO ("Is cancel enough, or do we need to drop the connection?")] - private void CheckForData (int timeout) - { - if (timeout > 0 && !comm.Poll (timeout, SelectMode.SelectRead)) { - Cancel (); - throw CreateTimeoutException (dataSource, "CheckForData()"); - } - } - - protected TdsInternalInfoMessageEventArgs CreateTdsInfoMessageEvent (TdsInternalErrorCollection errors) - { - return new TdsInternalInfoMessageEventArgs (errors); - } - - protected TdsInternalErrorMessageEventArgs CreateTdsErrorMessageEvent (byte theClass, int lineNumber, string message, int number, string procedure, string server, string source, byte state) - { - return new TdsInternalErrorMessageEventArgs (new TdsInternalError (theClass, lineNumber, message, number, procedure, server, source, state)); - } - - private void FinishQuery (bool wasCancelled, bool moreResults) - { - if (!moreResults) - queryInProgress = false; - if (wasCancelled) - cancelsProcessed += 1; - if (messages.Count > 0 && !moreResults) - OnTdsInfoMessage (CreateTdsInfoMessageEvent (messages)); - } - - private object GetColumnValue (TdsColumnType colType, bool outParam) - { - return GetColumnValue (colType, outParam, -1); - } - - private object GetColumnValue (TdsColumnType colType, bool outParam, int ordinal) - { - int len; - object element = null; - - switch (colType) { - case TdsColumnType.IntN : - if (outParam) - comm.Skip (1); - element = GetIntValue (colType); - break; - case TdsColumnType.Int1 : - case TdsColumnType.Int2 : - case TdsColumnType.Int4 : - element = GetIntValue (colType); - break; - case TdsColumnType.Image : - if (outParam) - comm.Skip (1); - element = GetImageValue (); - break; - case TdsColumnType.Text : - if (outParam) - comm.Skip (1); - element = GetTextValue (false); - break; - case TdsColumnType.NText : - if (outParam) - comm.Skip (1); - element = GetTextValue (true); - break; - case TdsColumnType.Char : - case TdsColumnType.VarChar : - if (outParam) - comm.Skip (1); - element = GetStringValue (false, false); - break; - case TdsColumnType.BigVarBinary : - comm.GetTdsShort (); - len = comm.GetTdsShort (); - element = comm.GetBytes (len, true); - break; - case TdsColumnType.BigVarChar : - comm.Skip (2); - element = GetStringValue (false, false); - break; - case TdsColumnType.NChar : - case TdsColumnType.NVarChar : - if (outParam) - comm.Skip (1); - element = GetStringValue (true, false); - break; - case TdsColumnType.Real : - case TdsColumnType.Float8 : - element = GetFloatValue (colType); - break; - case TdsColumnType.FloatN : - if (outParam) - comm.Skip (1); - element = GetFloatValue (colType); - break; - case TdsColumnType.SmallMoney : - case TdsColumnType.Money : - element = GetMoneyValue (colType); - break; - case TdsColumnType.MoneyN : - if (outParam) - comm.Skip (1); - element = GetMoneyValue (colType); - break; - case TdsColumnType.Numeric : - case TdsColumnType.Decimal : - byte precision; - byte scale; - if (outParam) { - comm.Skip (1); - precision = comm.GetByte (); - scale = comm.GetByte (); - } - else { - precision = (byte) columnInfo[ordinal]["NumericPrecision"]; - scale = (byte) columnInfo[ordinal]["NumericScale"]; - } - - element = GetDecimalValue (precision, scale); - break; - case TdsColumnType.DateTimeN : - if (outParam) - comm.Skip (1); - element = GetDateTimeValue (colType); - break; - case TdsColumnType.DateTime4 : - case TdsColumnType.DateTime : - element = GetDateTimeValue (colType); - break; - case TdsColumnType.VarBinary : - case TdsColumnType.Binary : - if (outParam) - comm.Skip (1); - element = GetBinaryValue (); - break; - case TdsColumnType.BitN : - if (outParam) - comm.Skip (1); - if (comm.GetByte () == 0) - element = null; - else - element = (comm.GetByte() != 0); - break; - case TdsColumnType.Bit : - int columnSize = comm.GetByte (); - element = (columnSize != 0); - break; - case TdsColumnType.UniqueIdentifier : - if (comm.Peek () != 16) // If it's null, then what to do? - break; - - len = comm.GetByte () & 0xff; - if (len > 0) { - byte[] guidBytes = comm.GetBytes (len, true); - element = new Guid (guidBytes); - } - break; - default : - return null; - } - - return element; - } - - private object GetBinaryValue () - { - int len; - object result = null; - if (tdsVersion == TdsVersion.tds70) { - len = comm.GetTdsShort (); - if (len != 0xffff && len > 0) - result = comm.GetBytes (len, true); - } - else { - len = (comm.GetByte () & 0xff); - if (len != 0) - result = comm.GetBytes (len, true); - } - return result; - } - - private object GetDateTimeValue (TdsColumnType type) - { - int len = 0; - object result = null; - - switch (type) { - case TdsColumnType.DateTime4: - len = 4; - break; - case TdsColumnType.DateTime: - len = 8; - break; - case TdsColumnType.DateTimeN: - byte tmp = comm.Peek (); - if (tmp != 0 && tmp != 4 && tmp != 8) - break; - len = comm.GetByte (); - break; - } - - DateTime epoch = new DateTime (1900, 1, 1); - - switch (len) { - case 8 : - result = epoch.AddDays (comm.GetTdsInt ()); - int seconds = comm.GetTdsInt (); - long millis = ((((long) seconds) % 300L) * 1000L) / 300L; - if (seconds != 0 || millis != 0) { - result = ((DateTime) result).AddSeconds (seconds / 300); - result = ((DateTime) result).AddMilliseconds (millis); - } - break; - case 4 : - result = epoch.AddDays ((int) comm.GetTdsShort ()); - short minutes = comm.GetTdsShort (); - if (minutes != 0) - result = ((DateTime) result).AddMinutes ((int) minutes); - break; - } - - return result; - } - - private object GetDecimalValue (byte precision, byte scale) - { - int[] bits = new int[4] {0,0,0,0}; - - int len = (comm.GetByte() & 0xff) - 1; - bool positive = (comm.GetByte () == 1); - - if (len < 0) - return null; - if (len > 16) - throw new OverflowException (); - - for (int i = 0, index = 0; i < len && i < 16; i += 4, index += 1) - bits[index] = comm.GetTdsInt (); - - if (bits [3] != 0) - return new TdsBigDecimal (precision, scale, !positive, bits); - else - return new Decimal (bits[0], bits[1], bits[2], !positive, scale); - } - - private object GetFloatValue (TdsColumnType columnType) - { - int columnSize = 0; - object result = null; - - switch (columnType) { - case TdsColumnType.Real: - columnSize = 4; - break; - case TdsColumnType.Float8: - columnSize = 8; - break; - case TdsColumnType.FloatN: - columnSize = comm.GetByte (); - break; - } - - switch (columnSize) { - case 8 : - result = BitConverter.Int64BitsToDouble (comm.GetTdsInt64 ()); - break; - case 4 : - result = BitConverter.ToSingle (BitConverter.GetBytes (comm.GetTdsInt ()), 0); - break; - } - - return result; - } - - private object GetImageValue () - { - byte hasValue = comm.GetByte (); - - if (hasValue == 0) - return null; - - comm.Skip (24); - int len = comm.GetTdsInt (); - - if (len < 0) - return null; - - return (comm.GetBytes (len, true)); - } - - private object GetIntValue (TdsColumnType type) - { - int len; - - switch (type) { - case TdsColumnType.IntN : - len = comm.GetByte (); - break; - case TdsColumnType.Int4 : - len = 4; - break; - case TdsColumnType.Int2 : - len = 2; - break; - case TdsColumnType.Int1 : - len = 1; - break; - default: - return null; - } - - switch (len) { - case 4 : - return (comm.GetTdsInt ()); - case 2 : - return (comm.GetTdsShort ()); - case 1 : - return (comm.GetByte ()); - default: - return null; - } - } - - [MonoTODO] - private object GetMoneyValue (TdsColumnType type) - { - int len; - object result = null; - - switch (type) { - case TdsColumnType.SmallMoney : - case TdsColumnType.Money4 : - len = 4; - break; - case TdsColumnType.Money : - len = 8; - break; - case TdsColumnType.MoneyN : - len = comm.GetByte (); - break; - default: - return null; - } - - long rawValue = 0; - - switch (len) { - case 4: - rawValue = comm.GetTdsInt (); - break; - case 8: - byte[] bits = new byte[8]; - bits[4] = comm.GetByte (); - bits[5] = comm.GetByte (); - bits[6] = comm.GetByte (); - bits[7] = comm.GetByte (); - bits[0] = comm.GetByte (); - bits[1] = comm.GetByte (); - bits[2] = comm.GetByte (); - bits[3] = comm.GetByte (); - rawValue = BitConverter.ToInt64 (bits, 0); - break; - default: - return null; - } - - result = new Decimal (rawValue); - - return (((decimal) result) / 10000); - } - - private object GetStringValue (bool wideChars, bool outputParam) - { - object result = null; - bool shortLen = (tdsVersion == TdsVersion.tds70) && (wideChars || !outputParam); - - int len = shortLen ? comm.GetTdsShort () : (comm.GetByte () & 0xff); - - if ((tdsVersion < TdsVersion.tds70 && len == 0) || (tdsVersion == TdsVersion.tds70 && len == 0xff)) - result = null; - else if (len >= 0) { - if (wideChars) - result = comm.GetString (len / 2); - else - result = comm.GetString (len, false); - if (tdsVersion < TdsVersion.tds70 && ((string) result).Equals (" ")) - result = ""; - } - else - result = null; - return result; - } - - protected int GetSubPacketLength () - { - return comm.GetTdsShort (); - } - - private object GetTextValue (bool wideChars) - { - string result = null; - byte hasValue = comm.GetByte (); - - if (hasValue != 16) - return null; - - // 16 Byte TEXTPTR, 8 Byte TIMESTAMP - comm.Skip (24); - - int len = comm.GetTdsInt (); - - if (len == 0) - return null; - - if (wideChars) - result = comm.GetString (len / 2); - else - result = comm.GetString (len, false); - len /= 2; - - if ((byte) tdsVersion < (byte) TdsVersion.tds70 && result == " ") - result = ""; - - return result; - } - - protected bool IsFixedSizeColumn (TdsColumnType columnType) - { - switch (columnType) { - case TdsColumnType.Int1 : - case TdsColumnType.Int2 : - case TdsColumnType.Int4 : - case TdsColumnType.Float8 : - case TdsColumnType.DateTime : - case TdsColumnType.Bit : - case TdsColumnType.Money : - case TdsColumnType.Money4 : - case TdsColumnType.SmallMoney : - case TdsColumnType.Real : - case TdsColumnType.DateTime4 : - return true; - case TdsColumnType.IntN : - case TdsColumnType.MoneyN : - case TdsColumnType.VarChar : - case TdsColumnType.NVarChar : - case TdsColumnType.DateTimeN : - case TdsColumnType.FloatN : - case TdsColumnType.Char : - case TdsColumnType.NChar : - case TdsColumnType.NText : - case TdsColumnType.Image : - case TdsColumnType.VarBinary : - case TdsColumnType.Binary : - case TdsColumnType.Decimal : - case TdsColumnType.Numeric : - case TdsColumnType.BitN : - case TdsColumnType.UniqueIdentifier : - return false; - default : - return false; - } - } - - protected TdsPacketRowResult LoadRow () - { - TdsPacketRowResult result = new TdsPacketRowResult (); - - int i = 0; - foreach (TdsSchemaInfo schema in columnInfo) { - object o = GetColumnValue ((TdsColumnType) schema["ColumnType"], false, i); - result.Add (o); - if (o is TdsBigDecimal && result.BigDecimalIndex < 0) - result.BigDecimalIndex = i; - i += 1; - } - - return result; - } - - protected int LookupBufferSize (TdsColumnType columnType) - { - switch (columnType) { - case TdsColumnType.Int1 : - case TdsColumnType.Bit : - return 1; - case TdsColumnType.Int2 : - return 2; - case TdsColumnType.Int4 : - case TdsColumnType.Real : - case TdsColumnType.DateTime4 : - case TdsColumnType.Money4 : - case TdsColumnType.SmallMoney : - return 4; - case TdsColumnType.Float8 : - case TdsColumnType.DateTime : - case TdsColumnType.Money : - return 8; - default : - return 0; - } - } - - private int LookupDisplaySize (TdsColumnType columnType) - { - switch (columnType) { - case TdsColumnType.Int1 : - return 3; - case TdsColumnType.Int2 : - return 6; - case TdsColumnType.Int4 : - return 11; - case TdsColumnType.Real : - return 14; - case TdsColumnType.Float8 : - return 24; - case TdsColumnType.DateTime : - return 23; - case TdsColumnType.DateTime4 : - return 16; - case TdsColumnType.Bit : - return 1; - case TdsColumnType.Money : - return 21; - case TdsColumnType.Money4 : - case TdsColumnType.SmallMoney : - return 12; - default: - return 0; - } - } - - protected TdsPacketColumnInfoResult ProcessColumnDetail () - { - TdsPacketColumnInfoResult result = columnInfo; - int len = GetSubPacketLength (); - byte[] values = new byte[3]; - int columnNameLength; - string baseColumnName = String.Empty; - int position = 0; - - while (position < len) { - for (int j = 0; j < 3; j += 1) - values[j] = comm.GetByte (); - position += 3; - - if ((values[2] & (byte) TdsColumnStatus.Rename) != 0) { - if (tdsVersion == TdsVersion.tds70) { - columnNameLength = comm.GetByte (); - position += 2 * len + 1; - } - else { - columnNameLength = comm.GetByte (); - position += len + 1; - } - baseColumnName = comm.GetString (columnNameLength); - } - - if ((values[2] & (byte) TdsColumnStatus.Hidden) == 0) { - byte index = (byte) (values[0] - (byte) 1); - byte tableIndex = (byte) (values[1] - (byte) 1); - - result [index]["IsExpression"] = ((values[2] & (byte) TdsColumnStatus.IsExpression) != 0); - result [index]["IsKey"] = ((values[2] & (byte) TdsColumnStatus.IsKey) != 0); - - if ((values[2] & (byte) TdsColumnStatus.Rename) != 0) - result [index]["BaseColumnName"] = baseColumnName; - result [index]["BaseTableName"] = tableNames [tableIndex]; - } - } - - return result; - } - - protected abstract TdsPacketColumnInfoResult ProcessColumnInfo (); - - protected TdsPacketColumnNamesResult ProcessColumnNames () - { - TdsPacketColumnNamesResult result = new TdsPacketColumnNamesResult (); - - int totalLength = comm.GetTdsShort (); - int bytesRead = 0; - int i = 0; - - while (bytesRead < totalLength) { - int columnNameLength = comm.GetByte (); - string columnName = comm.GetString (columnNameLength); - bytesRead = bytesRead + 1 + columnNameLength; - result.Add (columnName); - i += 1; - } - - return result; - } - - [MonoTODO ("Make sure counting works right, especially with multiple resultsets.")] - protected TdsPacketEndTokenResult ProcessEndToken (TdsPacketSubType type) - { - byte status = comm.GetByte (); - comm.GetByte (); - byte op = comm.GetByte (); - comm.GetByte (); - int rowCount = comm.GetTdsInt (); - if (op == (byte) 0xc1) - rowCount = 0; - if (type == TdsPacketSubType.DoneInProc) - rowCount = -1; - - TdsPacketEndTokenResult result = new TdsPacketEndTokenResult (type, status, rowCount); - - if (type == TdsPacketSubType.DoneProc) { - doneProc = true; - if (result.RowCount > 0) - recordsAffected += result.RowCount; - } - - moreResults = result.MoreResults; - FinishQuery (result.Cancelled, result.MoreResults); - - return result; - } - - protected TdsPacketResult ProcessEnvChange () - { - int len = GetSubPacketLength (); - TdsEnvPacketSubType type = (TdsEnvPacketSubType) comm.GetByte (); - int cLen; - - switch (type) { - case TdsEnvPacketSubType.BlockSize : - string blockSize; - cLen = comm.GetByte () & 0xff; - blockSize = comm.GetString (cLen); - - if (tdsVersion == TdsVersion.tds70) - comm.Skip (len - 2 - cLen * 2); - else - comm.Skip (len - 2 - cLen); - - comm.ResizeOutBuf (Int32.Parse (blockSize)); - break; - case TdsEnvPacketSubType.CharSet : - cLen = comm.GetByte () & 0xff; - if (tdsVersion == TdsVersion.tds70) { - //this.language = comm.GetString (cLen); // FIXME - comm.GetString (cLen); - comm.Skip (len - 2 - cLen * 2); - } - else { - SetCharset (comm.GetString (cLen)); - comm.Skip (len - 2 - cLen); - } - - break; - case TdsEnvPacketSubType.Database : - cLen = comm.GetByte () & 0xff; - string newDB = comm.GetString (cLen); - cLen = comm.GetByte () & 0xff; - string oldDB = comm.GetString (cLen); - database = newDB; - break; - default: - comm.Skip (len - 1); - break; - } - - return new TdsPacketResult (TdsPacketSubType.EnvChange); - } - - protected TdsPacketResult ProcessLoginAck () - { - GetSubPacketLength (); - - if (tdsVersion == TdsVersion.tds70) { - comm.Skip (5); - int nameLength = comm.GetByte (); - databaseProductName = comm.GetString (nameLength); - databaseMajorVersion = comm.GetByte (); - databaseProductVersion = String.Format ("0{0}.0{1}.0{2}", databaseMajorVersion, comm.GetByte (), ((256 * (comm.GetByte () + 1)) + comm.GetByte ())); - } - else { - comm.Skip (5); - short nameLength = comm.GetByte (); - databaseProductName = comm.GetString (nameLength); - comm.Skip (1); - databaseMajorVersion = comm.GetByte (); - databaseProductVersion = String.Format ("{0}.{1}", databaseMajorVersion, comm.GetByte ()); - comm.Skip (1); - } - - if (databaseProductName.Length > 1 && -1 != databaseProductName.IndexOf ('\0')) { - int last = databaseProductName.IndexOf ('\0'); - databaseProductName = databaseProductName.Substring (0, last); - } - - connected = true; - - return new TdsPacketResult (TdsPacketSubType.LoginAck); - } - - protected void OnTdsErrorMessage (TdsInternalErrorMessageEventArgs e) - { - if (TdsErrorMessage != null) - TdsErrorMessage (this, e); - } - - protected void OnTdsInfoMessage (TdsInternalInfoMessageEventArgs e) - { - if (TdsInfoMessage != null) - TdsInfoMessage (this, e); - messages.Clear (); - } - - protected void ProcessMessage (TdsPacketSubType subType) - { - GetSubPacketLength (); - - int number = comm.GetTdsInt (); - byte state = comm.GetByte (); - byte theClass = comm.GetByte (); - string message; - string server; - string procedure; - byte lineNumber; - string source; - bool isError = false; - - if (subType == TdsPacketSubType.EED) { - isError = (theClass <= 10); - comm.Skip (comm.GetByte ()); // SQL State - comm.Skip (1); // Status - comm.Skip (2); // TranState - } else - isError = (subType == TdsPacketSubType.Error); - - message = comm.GetString (comm.GetTdsShort ()); - server = comm.GetString (comm.GetByte ()); - procedure = comm.GetString (comm.GetByte ()); - lineNumber = comm.GetByte (); - comm.Skip (1); - source = String.Empty; // FIXME - - if (isError) - messages.Add (new TdsInternalError (theClass, lineNumber, message, number, procedure, server, source, state)); - else - OnTdsErrorMessage (CreateTdsErrorMessageEvent (theClass, lineNumber, message, number, procedure, server, source, state)); - } - - protected TdsPacketOutputParam ProcessOutputParam () - { - GetSubPacketLength (); - comm.GetString (comm.GetByte () & 0xff); - comm.Skip (5); - - TdsColumnType colType = (TdsColumnType) comm.GetByte (); - object value = GetColumnValue (colType, true); - - outputParameters.Add (value); - return null; - } - - protected TdsPacketResult ProcessProcId () - { - comm.Skip (8); - return new TdsPacketResult (TdsPacketSubType.ProcId); - } - - protected TdsPacketRetStatResult ProcessReturnStatus () - { - return new TdsPacketRetStatResult (comm.GetTdsInt ()); - } - - protected virtual TdsPacketResult ProcessSubPacket () - { - TdsPacketResult result = null; - moreResults = false; - - TdsPacketSubType subType = (TdsPacketSubType) comm.GetByte (); - - switch (subType) { - case TdsPacketSubType.EnvChange: - result = ProcessEnvChange (); - break; - case TdsPacketSubType.Info: // TDS 4.2/7.0 - case TdsPacketSubType.EED: // TDS 5.0 - case TdsPacketSubType.Error: // TDS 4.2/7.0 - ProcessMessage (subType); - break; - case TdsPacketSubType.Param: - result = ProcessOutputParam (); - break; - case TdsPacketSubType.LoginAck: - result = ProcessLoginAck (); - break; - case TdsPacketSubType.ReturnStatus : - result = ProcessReturnStatus (); - break; - case TdsPacketSubType.ProcId: - result = ProcessProcId (); - break; - case TdsPacketSubType.Done: - case TdsPacketSubType.DoneProc: - case TdsPacketSubType.DoneInProc: - result = ProcessEndToken (subType); - break; - case TdsPacketSubType.ColumnNameToken: - result = ProcessProcId (); - result = ProcessColumnNames (); - break; - case TdsPacketSubType.ColumnInfoToken: // TDS 4.2 - case TdsPacketSubType.ColumnMetadata: // TDS 7.0 - case TdsPacketSubType.RowFormat: // TDS 5.0 - result = ProcessColumnInfo (); - break; - case TdsPacketSubType.ColumnDetail: - result = ProcessColumnDetail (); - break; - case TdsPacketSubType.Unknown0xA7: - case TdsPacketSubType.Unknown0xA8: - comm.Skip (comm.GetTdsShort ()); - result = new TdsPacketUnknown (subType); - break; - case TdsPacketSubType.TableName: - result = ProcessTableName (); - break; - case TdsPacketSubType.Order: - comm.Skip (comm.GetTdsShort ()); - result = new TdsPacketColumnOrderResult (); - break; - case TdsPacketSubType.Control: - comm.Skip (comm.GetTdsShort ()); - result = new TdsPacketControlResult (); - break; - case TdsPacketSubType.Row: - result = LoadRow (); - break; - default: - return null; - } - - return result; - } - - protected TdsPacketTableNameResult ProcessTableName () - { - TdsPacketTableNameResult result = new TdsPacketTableNameResult (); - int totalLength = comm.GetTdsShort (); - int position = 0; - int len; - - while (position < totalLength) { - if (tdsVersion == TdsVersion.tds70) { - len = comm.GetTdsShort (); - position += 2 * (len + 1); - } - else { - len = comm.GetByte (); - position += len + 1; - } - result.Add (comm.GetString (len)); - } - return result; - } - - protected void SetCharset (string charset) - { - if (charset == null || charset.Length > 30) - charset = "iso_1"; - - if (this.charset != null && this.charset != charset) - return; - - if (charset.StartsWith ("cp")) { - encoder = Encoding.GetEncoding (Int32.Parse (charset.Substring (2))); - this.charset = charset; - } - else { - encoder = Encoding.GetEncoding ("iso-8859-1"); - this.charset = "iso_1"; - } - comm.Encoder = encoder; - } - - protected void SetLanguage (string language) - { - if (language == null || language.Length > 30) - language = "us_english"; - - this.language = language; - } - - #endregion // Private Methods - } -} diff --git a/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/Tds42.cs b/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/Tds42.cs deleted file mode 100644 index b7a85ea9523..00000000000 --- a/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/Tds42.cs +++ /dev/null @@ -1,274 +0,0 @@ -// -// Mono.Data.TdsClient.Internal.Tds42.cs -// -// Author: -// Tim Coleman (tim@timcoleman.com) -// -// Copyright (C) 2002 Tim Coleman -// - -using System; - -namespace Mono.Data.TdsClient.Internal { - internal class Tds42 : Tds - { - #region Fields - - public static readonly TdsVersion Version = TdsVersion.tds42; - - #endregion // Fields - - #region Constructors - - public Tds42 (string server, int port) - : this (server, port, 512, 15) - { - } - - public Tds42 (string server, int port, int packetSize, int timeout) - : base (server, port, packetSize, timeout, Version) - { - } - - #endregion // Constructors - - #region Methods - - public override bool Connect (TdsConnectionParameters connectionParameters) - { - if (IsConnected) - throw new InvalidOperationException ("The connection is already open."); - - SetCharset (connectionParameters.Charset); - SetLanguage (connectionParameters.Language); - - byte pad = (byte) 0; - byte[] empty = new byte[0]; - - Comm.StartPacket (TdsPacketType.Logon); - - // hostname (offset 0) - byte[] tmp = Comm.Append (connectionParameters.Hostname, 30, pad); - Comm.Append ((byte) (tmp.Length < 30 ? tmp.Length : 30)); - - // username (offset 31 0x1f) - tmp = Comm.Append (connectionParameters.User, 30, pad); - Comm.Append ((byte) (tmp.Length < 30 ? tmp.Length : 30)); - - // password (offset 62 0x3e) - tmp = Comm.Append (connectionParameters.Password, 30, pad); - Comm.Append ((byte) (tmp.Length < 30 ? tmp.Length : 30)); - - // hostproc (offset 93 0x5d) - Comm.Append ("00000116", 8, pad); - - // unused (offset 109 0x6d) - Comm.Append (empty, (30-14), pad); - - // apptype - Comm.Append ((byte) 0x0); - Comm.Append ((byte) 0xa0); - Comm.Append ((byte) 0x24); - Comm.Append ((byte) 0xcc); - Comm.Append ((byte) 0x50); - Comm.Append ((byte) 0x12); - - // hostproc length - Comm.Append ((byte) 8); - - // Byte order of 2 byte ints - // 2 = <MSB, LSB>, 3 = <LSB, MSB> - Comm.Append ((byte) 3); - - // Byte order of 4 byte ints - // 0 = <MSB, LSB>, 1 = <LSB, MSB> - Comm.Append ((byte) 1); - - // Character representation - // (6 = ASCII, 7 = EBCDIC) - Comm.Append ((byte) 6); - - // Eight byte floating point representation - // 4 = IEEE <MSB, ..., LSB> - // 5 = VAX 'D' - // 10 = IEEE <LSB, ..., MSB> - // 11 = ND5000 - Comm.Append ((byte) 10); - - // Eight byte date format - // 8 = <MSB, ..., LSB> - Comm.Append ((byte) 9); - - // notify of use db - Comm.Append ((byte) 1); - - // disallow dump/load and bulk insert - Comm.Append ((byte) 1); - - // sql interface type - Comm.Append ((byte) 0); - - // type of network connection - Comm.Append ((byte) 0); - - - // spare [7] - Comm.Append (empty, 7, pad); - // appname - tmp = Comm.Append (connectionParameters.ApplicationName, 30, pad); - Comm.Append ((byte) (tmp.Length < 30 ? tmp.Length : 30)); - - // server name - tmp = Comm.Append (DataSource, 30, pad); - Comm.Append ((byte) (tmp.Length < 30 ? tmp.Length : 30)); - - // remote passwords - Comm.Append (empty, 2, pad); - tmp = Comm.Append (connectionParameters.Password, 253, pad); - Comm.Append ((byte) (tmp.Length < 253 ? tmp.Length + 2 : 253 + 2)); - - // tds version - Comm.Append ((byte) (((byte) Version) / 10)); - Comm.Append ((byte) (((byte) Version) % 10)); - Comm.Append ((byte) 0); - Comm.Append ((byte) 0); - - // prog name - tmp = Comm.Append (connectionParameters.ProgName, 10, pad); - Comm.Append ((byte) (tmp.Length < 10 ? tmp.Length : 10)); - - // prog version - Comm.Append ((byte) 6); - - // Tell the server we can handle SQLServer version 6 - Comm.Append ((byte) 0); - - // Send zero to tell the server we can't handle any other version - Comm.Append ((byte) 0); - Comm.Append ((byte) 0); - - // auto convert short - Comm.Append ((byte) 0); - - // type of flt4 - Comm.Append ((byte) 0x0d); - - // type of date4 - Comm.Append ((byte) 0x11); - - // language - tmp = Comm.Append (Language, 30, pad); - Comm.Append ((byte) (tmp.Length < 30 ? tmp.Length : 30)); - - // notify on lang change - Comm.Append ((byte) 1); - - // security label hierarchy - Comm.Append ((short) 0); - - // security components - Comm.Append (empty, 8, pad); - - // security spare - Comm.Append ((short) 0); - - // security login role - Comm.Append ((byte) 0); - - // charset - tmp = Comm.Append (Charset, 30, pad); - Comm.Append ((byte) (tmp.Length < 30 ? tmp.Length : 30)); - - // notify on charset change - Comm.Append ((byte) 1); - - // length of tds packets - tmp = Comm.Append (PacketSize.ToString (), 6, pad); - Comm.Append ((byte) 3); - - // pad out to a longword - Comm.Append (empty, 8, pad); - - Comm.SendPacket (); - - TdsPacketResult result; - bool done = false; - - while (!done) { - result = ProcessSubPacket (); - done = (result is TdsPacketEndTokenResult); - } - return IsConnected; - } - - protected override TdsPacketColumnInfoResult ProcessColumnInfo () - { - byte precision; - byte scale; - int totalLength = Comm.GetTdsShort (); - int bytesRead = 0; - - TdsPacketColumnInfoResult result = new TdsPacketColumnInfoResult (); - - while (bytesRead < totalLength) { - scale = 0; - precision = 0; - - int bufLength = -1; - byte[] flagData = new byte[4]; - for (int i = 0; i < 4; i += 1) { - flagData[i] = Comm.GetByte (); - bytesRead += 1; - } - bool nullable = (flagData[2] & 0x01) > 0; - bool caseSensitive = (flagData[2] & 0x02) > 0; - bool writable = (flagData[2] & 0x0c) > 0; - bool autoIncrement = (flagData[2] & 0x10) > 0; - - string tableName = String.Empty; - TdsColumnType columnType = (TdsColumnType) Comm.GetByte (); - - bytesRead += 1; - - if (columnType == TdsColumnType.Text || columnType == TdsColumnType.Image) { - Comm.Skip (4); - bytesRead += 4; - - int tableNameLength = Comm.GetTdsShort (); - bytesRead += 2; - tableName = Comm.GetString (tableNameLength); - bytesRead += tableNameLength; - bufLength = 2 << 31 - 1; - } - else if (columnType == TdsColumnType.Decimal || columnType == TdsColumnType.Numeric) { - bufLength = Comm.GetByte (); - bytesRead += 1; - precision = Comm.GetByte (); - bytesRead += 1; - scale = Comm.GetByte (); - bytesRead += 1; - } - else if (IsFixedSizeColumn (columnType)) - bufLength = LookupBufferSize (columnType); - else { - bufLength = (int) Comm.GetByte () & 0xff; - 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; - } - - return result; - } - - #endregion // Methods - } -} diff --git a/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/Tds50.cs b/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/Tds50.cs deleted file mode 100644 index a2e3eb539bc..00000000000 --- a/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/Tds50.cs +++ /dev/null @@ -1,289 +0,0 @@ -// -// Mono.Data.TdsClient.Internal.Tds50.cs -// -// Author: -// Tim Coleman (tim@timcoleman.com) -// -// Copyright (C) 2002 Tim Coleman -// - -using System; - -namespace Mono.Data.TdsClient.Internal { - internal class Tds50 : Tds - { - #region Fields - - public static readonly TdsVersion Version = TdsVersion.tds50; - - #endregion // Fields - - #region Constructors - - public Tds50 (string server, int port) - : this (server, port, 8192, 15) - { - } - - public Tds50 (string server, int port, int packetSize, int timeout) - : base (server, port, packetSize, timeout, Version) - { - } - - #endregion // Constructors - - #region Methods - - public override bool Connect (TdsConnectionParameters connectionParameters) - { - if (IsConnected) - throw new InvalidOperationException ("The connection is already open."); - - // some voodoo magic here. - byte[] capabilities = {0x01,0x07,0x03,109,127,0xFF,0xFF,0xFF,0xFE,0x02,0x07,0x00,0x00,0x0A,104,0x00,0x00,0x00}; - - SetCharset (connectionParameters.Charset); - SetLanguage (connectionParameters.Language); - - byte pad = (byte) 0; - byte[] empty = new byte[0]; - - Comm.StartPacket (TdsPacketType.Logon); - - // hostname (offset 0) - // 0-30 - byte[] tmp = Comm.Append (connectionParameters.Hostname, 30, pad); - Comm.Append ((byte) (tmp.Length < 30 ? tmp.Length : 30)); - - // username (offset 31 0x1f) - // 31-61 - tmp = Comm.Append (connectionParameters.User, 30, pad); - Comm.Append ((byte) (tmp.Length < 30 ? tmp.Length : 30)); - - // password (offset 62 0x3e) - // 62-92 - tmp = Comm.Append (connectionParameters.Password, 30, pad); - Comm.Append ((byte) (tmp.Length < 30 ? tmp.Length : 30)); - - // hostproc (offset 93 0x5d) - // 93-123 - tmp = Comm.Append ("37876", 30, pad); - Comm.Append ((byte) (tmp.Length < 30 ? tmp.Length : 30)); - - // Byte order of 2 byte ints - // 2 = <MSB, LSB>, 3 = <LSB, MSB> - // 124 - Comm.Append ((byte) 3); - - // Byte order of 4 byte ints - // 0 = <MSB, LSB>, 1 = <LSB, MSB> - // 125 - Comm.Append ((byte) 1); - - // Character representation - // (6 = ASCII, 7 = EBCDIC) - // 126 - Comm.Append ((byte) 6); - - // Eight byte floating point representation - // 4 = IEEE <MSB, ..., LSB> - // 5 = VAX 'D' - // 10 = IEEE <LSB, ..., MSB> - // 11 = ND5000 - // 127 - Comm.Append ((byte) 10); - - // Eight byte date format - // 8 = <MSB, ..., LSB> - // 128 - Comm.Append ((byte) 9); - - // notify of use db - // 129 - Comm.Append ((byte) 1); - - // disallow dump/load and bulk insert - // 130 - Comm.Append ((byte) 1); - - // sql interface type - // 131 - Comm.Append ((byte) 0); - - // type of network connection - // 132 - Comm.Append ((byte) 0); - - // spare [7] - // 133-139 - Comm.Append (empty, 7, pad); - - // appname - // 140-170 - tmp = Comm.Append (connectionParameters.ApplicationName, 30, pad); - Comm.Append ((byte) (tmp.Length < 30 ? tmp.Length : 30)); - - // server name - // 171-201 - tmp = Comm.Append (DataSource, 30, pad); - Comm.Append ((byte) (tmp.Length < 30 ? tmp.Length : 30)); - - // remote passwords - // 202-457 - Comm.Append (empty, 2, pad); - tmp = Comm.Append (connectionParameters.Password, 253, pad); - Comm.Append ((byte) (tmp.Length < 253 ? tmp.Length + 2 : 253 + 2)); - - // tds version - // 458-461 - Comm.Append ((byte) 5); - Comm.Append ((byte) 0); - Comm.Append ((byte) 0); - Comm.Append ((byte) 0); - - // prog name - // 462-472 - tmp = Comm.Append (connectionParameters.ProgName, 10, pad); - Comm.Append ((byte) (tmp.Length < 10 ? tmp.Length : 10)); - - // prog version - // 473-476 - Comm.Append ((byte) 6); - Comm.Append ((byte) 0); - Comm.Append ((byte) 0); - Comm.Append ((byte) 0); - - // auto convert short - // 477 - Comm.Append ((byte) 0); - - // type of flt4 - // 478 - Comm.Append ((byte) 0x0d); - - // type of date4 - // 479 - Comm.Append ((byte) 0x11); - - // language - // 480-510 - tmp = Comm.Append (Language, 30, pad); - Comm.Append ((byte) (tmp.Length < 30 ? tmp.Length : 30)); - - // notify on lang change - // 511 - Comm.Append ((byte) 1); - - // security label hierarchy - // 512-513 - Comm.Append ((short) 0); - - // security components - // 514-521 - Comm.Append (empty, 8, pad); - - // security spare - // 522-523 - Comm.Append ((short) 0); - - // security login role - // 524 - Comm.Append ((byte) 0); - - // charset - // 525-555 - tmp = Comm.Append (Charset, 30, pad); - Comm.Append ((byte) (tmp.Length < 30 ? tmp.Length : 30)); - - // notify on charset change - // 556 - Comm.Append ((byte) 1); - - // length of tds packets - // 557-563 - tmp = Comm.Append (PacketSize.ToString (), 6, pad); - Comm.Append ((byte) (tmp.Length < 6 ? tmp.Length : 6)); - - Comm.Append (empty, 8, pad); - // Padding... - // 564-567 - //Comm.Append (empty, 4, pad); - - // Capabilities - //Comm.Append ((byte) TdsPacketType.Capability); - //Comm.Append ((short) 18); - //Comm.Append (capabilities, 18, pad); - - Comm.SendPacket (); - - bool done = false; - while (!done) { - TdsPacketResult result = ProcessSubPacket (); - done = (result is TdsPacketEndTokenResult); - } - return IsConnected; - } - - protected override TdsPacketColumnInfoResult ProcessColumnInfo () - { - TdsPacketColumnInfoResult result = new TdsPacketColumnInfoResult (); - int totalLength = Comm.GetTdsShort (); - int count = Comm.GetTdsShort (); - for (int i = 0; i < count; i += 1) { - string columnName = Comm.GetString (Comm.GetByte ()); - int status = Comm.GetByte (); - bool hidden = (status & 0x01) > 0; - bool isKey = (status & 0x02) > 0; - bool isRowVersion = (status & 0x04) > 0; - bool isUpdatable = (status & 0x10) > 0; - bool allowDBNull = (status & 0x20) > 0; - bool isIdentity = (status & 0x40) > 0; - - Comm.Skip (4); // User type - - byte type = Comm.GetByte (); - bool isBlob = (type == 0x24); - - TdsColumnType columnType = (TdsColumnType) type; - int bufLength = 0; - - byte precision = 0; - byte scale = 0; - - if (columnType == TdsColumnType.Text || columnType == TdsColumnType.Image) { - bufLength = Comm.GetTdsInt (); - Comm.Skip (Comm.GetTdsShort ()); - } - else if (IsFixedSizeColumn (columnType)) - bufLength = LookupBufferSize (columnType); - else - bufLength = Comm.GetTdsShort (); - - if (columnType == TdsColumnType.Decimal || columnType == TdsColumnType.Numeric) { - precision = Comm.GetByte (); - scale = Comm.GetByte (); - } - - Comm.Skip (Comm.GetByte ()); // Locale - if (isBlob) - Comm.Skip (Comm.GetTdsShort ()); // Class ID - - int index = result.Add (new TdsSchemaInfo ()); - result[index]["NumericPrecision"] = precision; - result[index]["NumericScale"] = scale; - result[index]["ColumnSize"] = bufLength; - result[index]["ColumnName"] = columnName; - result[index]["AllowDBNull"] = allowDBNull; - result[index]["IsReadOnly"] = !isUpdatable; - result[index]["IsIdentity"] = isIdentity; - result[index]["IsRowVersion"] = isRowVersion; - result[index]["IsKey"] = isKey; - result[index]["Hidden"] = hidden; - result[index]["ColumnType"] = columnType; - } - return result; - } - - #endregion // Methods - } -} diff --git a/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/Tds70.cs b/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/Tds70.cs deleted file mode 100644 index ba4ec34dee5..00000000000 --- a/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/Tds70.cs +++ /dev/null @@ -1,258 +0,0 @@ -// -// Mono.Data.TdsClient.Internal.Tds70.cs -// -// Author: -// Tim Coleman (tim@timcoleman.com) -// -// Copyright (C) 2002 Tim Coleman -// - -using System; - -namespace Mono.Data.TdsClient.Internal { - internal class Tds70 : Tds - { - #region Fields - - public readonly static TdsVersion Version = TdsVersion.tds70; - - #endregion // Fields - - #region Constructors - - public Tds70 (string server, int port) - : this (server, port, 512, 15) - { - } - - public Tds70 (string server, int port, int packetSize, int timeout) - : base (server, port, packetSize, timeout, Version) - { - } - - #endregion // Constructors - - #region Methods - - public override bool Connect (TdsConnectionParameters connectionParameters) - { - if (IsConnected) - throw new InvalidOperationException ("The connection is already open."); - - SetLanguage (connectionParameters.Language); - SetCharset ("utf-8"); - - byte[] empty = new byte[0]; - byte pad = (byte) 0; - - byte[] magic1 = {0x06, 0x83, 0xf2, 0xf8, 0xff, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x03, 0x00, 0x00, 0x88, 0xff, 0xff, 0xff, 0x36, 0x04, 0x00, 0x00}; - byte[] magic2 = {0x00, 0x40, 0x33, 0x9a, 0x6b, 0x50}; - byte[] magic3 = {0x4e, 0x54, 0x4c, 0x4d, 0x53, 0x53, 0x50}; // NTLMSSP - short partialPacketSize = (short) (86 + 2 * ( - connectionParameters.Hostname.Length + - connectionParameters.User.Length + - connectionParameters.ApplicationName.Length + - connectionParameters.Password.Length + - DataSource.Length + - connectionParameters.LibraryName.Length + - Language.Length + - connectionParameters.Database.Length)); - short totalPacketSize = (short) (partialPacketSize + 48); - Comm.StartPacket (TdsPacketType.Logon70); - Comm.Append (totalPacketSize); - Comm.Append (empty, 5, pad); - - Comm.Append ((byte) 0x70); // TDS VERSION 7 - Comm.Append (empty, 7, pad); - Comm.Append (magic1); - - short curPos = 86; - - // Hostname - Comm.Append (curPos); - Comm.Append ((short) connectionParameters.Hostname.Length); - curPos += (short) (connectionParameters.Hostname.Length * 2); - - // Username - Comm.Append (curPos); - Comm.Append ((short) connectionParameters.User.Length); - curPos += (short) (connectionParameters.User.Length * 2); - - // Password - Comm.Append (curPos); - Comm.Append ((short) connectionParameters.Password.Length); - curPos += (short) (connectionParameters.Password.Length * 2); - - // AppName - Comm.Append (curPos); - Comm.Append ((short) connectionParameters.ApplicationName.Length); - curPos += (short) (connectionParameters.ApplicationName.Length * 2); - - // Server Name - Comm.Append (curPos); - Comm.Append ((short) DataSource.Length); - curPos += (short) (DataSource.Length * 2); - - // Unknown - Comm.Append ((short) 0); - Comm.Append ((short) 0); - - // Library Name - Comm.Append (curPos); - Comm.Append ((short) connectionParameters.LibraryName.Length); - curPos += (short) (connectionParameters.LibraryName.Length * 2); - - // Language - Comm.Append (curPos); - Comm.Append ((short) Language.Length); - curPos += (short) (Language.Length * 2); - - // Database - Comm.Append (curPos); - Comm.Append ((short) connectionParameters.Database.Length); - curPos += (short) (connectionParameters.Database.Length * 2); - - Comm.Append (magic2); - Comm.Append (partialPacketSize); - Comm.Append ((short) 48); - Comm.Append (totalPacketSize); - Comm.Append ((short) 0); - - string scrambledPwd = EncryptPassword (connectionParameters.Password); - - Comm.Append (connectionParameters.Hostname); - Comm.Append (connectionParameters.User); - Comm.Append (scrambledPwd); - Comm.Append (connectionParameters.ApplicationName); - Comm.Append (DataSource); - Comm.Append (connectionParameters.LibraryName); - Comm.Append (Language); - Comm.Append (connectionParameters.Database); - Comm.Append (magic3); - - Comm.Append ((byte) 0x0); - Comm.Append ((byte) 0x1); - Comm.Append (empty, 3, pad); - Comm.Append ((byte) 0x6); - Comm.Append ((byte) 0x82); - Comm.Append (empty, 22, pad); - Comm.Append ((byte) 0x30); - Comm.Append (empty, 7, pad); - Comm.Append ((byte) 0x30); - Comm.Append (empty, 3, pad); - Comm.SendPacket (); - - TdsPacketResult result; - - bool done = false; - while (!done) { - result = ProcessSubPacket (); - done = (result is TdsPacketEndTokenResult); - } - return IsConnected; - } - - private static string EncryptPassword (string pass) - { - int xormask = 0x5a5a; - int len = pass.Length; - char[] chars = new char[len]; - - for (int i = 0; i < len; ++i) { - int c = ((int) (pass[i])) ^ xormask; - int m1 = (c >> 4) & 0x0f0f; - int m2 = (c << 4) & 0xf0f0; - chars[i] = (char) (m1 | m2); - } - - return new String (chars); - } - - private bool IsBlobType (TdsColumnType columnType) - { - return (columnType == TdsColumnType.Text || columnType == TdsColumnType.Image || columnType == TdsColumnType.NText); - } - - private bool IsLargeType (TdsColumnType columnType) - { - return (columnType == TdsColumnType.NChar || (byte) columnType > 128); - } - - protected override TdsPacketColumnInfoResult ProcessColumnInfo () - { - TdsPacketColumnInfoResult result = new TdsPacketColumnInfoResult (); - int numColumns = Comm.GetTdsShort (); - - for (int i = 0; i < numColumns; i += 1) { - byte[] flagData = new byte[4]; - for (int j = 0; j < 4; j += 1) - flagData[j] = Comm.GetByte (); - - bool nullable = (flagData[2] & 0x01) > 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; - - TdsColumnType columnType = (TdsColumnType) (Comm.GetByte () & 0xff); - if ((byte) columnType == 0xef) - columnType = TdsColumnType.NChar; - - byte xColumnType = 0; - if (IsLargeType (columnType)) { - xColumnType = (byte) columnType; - if (columnType != TdsColumnType.NChar) - columnType -= 128; - } - - int columnSize; - string tableName = null; - - if (IsBlobType (columnType)) { - columnSize = Comm.GetTdsInt (); - tableName = Comm.GetString (Comm.GetTdsShort ()); - } - - else if (IsFixedSizeColumn (columnType)) - columnSize = LookupBufferSize (columnType); - else if (IsLargeType ((TdsColumnType) xColumnType)) - columnSize = Comm.GetTdsShort (); - else - columnSize = Comm.GetByte () & 0xff; - - byte precision = 0; - byte scale = 0; - - switch (columnType) { - case TdsColumnType.NText: - case TdsColumnType.NChar: - case TdsColumnType.NVarChar: - columnSize /= 2; - break; - case TdsColumnType.Decimal: - case TdsColumnType.Numeric: - precision = Comm.GetByte (); - scale = Comm.GetByte (); - break; - } - - string columnName = Comm.GetString (Comm.GetByte ()); - - int index = result.Add (new TdsSchemaInfo ()); - result[index]["AllowDBNull"] = nullable; - result[index]["ColumnName"] = columnName; - result[index]["ColumnSize"] = columnSize; - result[index]["ColumnType"] = columnType; - result[index]["IsIdentity"] = isIdentity; - result[index]["IsReadOnly"] = !writable; - result[index]["NumericPrecision"] = precision; - result[index]["NumericScale"] = scale; - result[index]["BaseTableName"] = tableName; - } - - return result; - } - - #endregion // Methods - } -} diff --git a/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/Tds80.cs b/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/Tds80.cs deleted file mode 100644 index 414f42d86bd..00000000000 --- a/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/Tds80.cs +++ /dev/null @@ -1,49 +0,0 @@ -// -// Mono.Data.TdsClient.Internal.Tds80.cs -// -// Author: -// Tim Coleman (tim@timcoleman.com) -// -// Copyright (C) 2002 Tim Coleman -// - -using System; - -namespace Mono.Data.TdsClient.Internal { - internal class Tds80 : Tds - { - #region Fields - - public static readonly TdsVersion Version = TdsVersion.tds80; - - #endregion // Fields - - #region Constructors - - public Tds80 (string server, int port) - : this (server, port, 512, 15) - { - } - - public Tds80 (string server, int port, int packetSize, int timeout) - : base (server, port, packetSize, timeout, Version) - { - } - - #endregion // Constructors - - #region Methods - - public override bool Connect (TdsConnectionParameters connectionParameters) - { - throw new NotImplementedException (); - } - - protected override TdsPacketColumnInfoResult ProcessColumnInfo () - { - throw new NotImplementedException (); - } - - #endregion // Methods - } -} diff --git a/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsBigDecimal.cs b/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsBigDecimal.cs deleted file mode 100644 index 36fb38f4c15..00000000000 --- a/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsBigDecimal.cs +++ /dev/null @@ -1,54 +0,0 @@ -// -// Mono.Data.TdsClient.Internal.TdsBigDecimal.cs -// -// Author: -// Tim Coleman (tim@timcoleman.com) -// -// Copyright (C) Tim Coleman, 2002 -// - -namespace Mono.Data.TdsClient.Internal { - internal class TdsBigDecimal - { - #region Fields - - bool isNegative; - byte precision; - byte scale; - int[] data; - - #endregion // Fields - - #region Constructors - - public TdsBigDecimal (byte precision, byte scale, bool isNegative, int[] data) - { - this.isNegative = isNegative; - this.precision = precision; - this.scale = scale; - this.data = data; - } - - #endregion // Constructors - - #region Properties - - public int[] Data { - get { return data; } - } - - public byte Precision { - get { return precision; } - } - - public byte Scale { - get { return scale; } - } - - public bool IsNegative { - get { return isNegative; } - } - - #endregion // Properties - } -} diff --git a/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsColumnStatus.cs b/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsColumnStatus.cs deleted file mode 100644 index 4d728116a63..00000000000 --- a/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsColumnStatus.cs +++ /dev/null @@ -1,17 +0,0 @@ -// -// Mono.Data.TdsClient.Internal.TdsColumnStatus.cs -// -// Author: -// Tim Coleman (tim@timcoleman.com) -// -// Copyright (C) Tim Coleman, 2002 -// - -namespace Mono.Data.TdsClient.Internal { - internal enum TdsColumnStatus { - IsExpression = 0x04, - IsKey = 0x08, - Hidden = 0x10, - Rename = 0x20 - } -} diff --git a/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsColumnType.cs b/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsColumnType.cs deleted file mode 100644 index f5d2b9321b7..00000000000 --- a/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsColumnType.cs +++ /dev/null @@ -1,46 +0,0 @@ -// -// Mono.Data.TdsClient.Internal.TdsColumnType.cs -// -// Author: -// Tim Coleman (tim@timcoleman.com) -// -// Copyright (C) Tim Coleman, 2002 -// - -namespace Mono.Data.TdsClient.Internal { - internal enum TdsColumnType { - Void = 0x1f, - Image = 0x22, - Text = 0x23, - UniqueIdentifier = 0x24, - VarBinary = 0x25, - IntN = 0x26, - VarChar = 0x27, - Binary = 0x2d, - Char = 0x2f, - Int1 = 0x30, - Bit = 0x32, - Int2 = 0x34, - Int4 = 0x38, - DateTime4 = 0x3a, - Real = 0x3b, - Money = 0x3c, - DateTime = 0x3d, - Float8 = 0x3e, - NText = 0x63, - NVarChar = 0x67, - BitN = 0x68, - Decimal = 0x6a, - Numeric = 0x6c, - FloatN = 0x6d, - MoneyN = 0x6e, - DateTimeN = 0x6f, - Money4 = 0x70, - NChar = 0xef, - BigVarBinary = 0xa5, - BigVarChar = 0xa7, - BigBinary = 0xad, - BigChar = 0xaf, - SmallMoney = 0x7a - } -} diff --git a/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsComm.cs b/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsComm.cs deleted file mode 100644 index 8572d7f62b0..00000000000 --- a/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsComm.cs +++ /dev/null @@ -1,466 +0,0 @@ -// -// Mono.Data.TdsClient.Internal.TdsComm.cs -// -// Author: -// Tim Coleman (tim@timcoleman.com) -// -// Copyright (C) 2002 Tim Coleman -// - -using System; -using System.Net; -using System.Net.Sockets; -using System.Text; -using System.Threading; - -namespace Mono.Data.TdsClient.Internal { - internal sealed class TdsComm - { - #region Fields - - NetworkStream stream; - int packetSize; - TdsPacketType packetType = TdsPacketType.None; - Encoding encoder; - - string dataSource; - int commandTimeout; - int connectionTimeout; - - byte[] outBuffer; - int outBufferLength; - int nextOutBufferIndex = 0; - - byte[] inBuffer; - int inBufferLength; - int inBufferIndex = 0; - - static int headerLength = 8; - - byte[] tmpBuf = new byte[8]; - byte[] resBuffer = new byte[256]; - - int packetsSent = 0; - int packetsReceived = 0; - - Socket socket; - TdsVersion tdsVersion; - - ManualResetEvent connected = new ManualResetEvent (false); - - #endregion // Fields - - #region Constructors - - [MonoTODO ("Fix when asynchronous socket connect works on Linux.")] - public TdsComm (string dataSource, int port, int packetSize, int timeout, TdsVersion tdsVersion) - { - this.packetSize = packetSize; - this.tdsVersion = tdsVersion; - this.dataSource = dataSource; - this.connectionTimeout = timeout; - - outBuffer = new byte[packetSize]; - inBuffer = new byte[packetSize]; - - outBufferLength = packetSize; - inBufferLength = packetSize; - - socket = new Socket (AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); - IPHostEntry hostEntry = Dns.Resolve (dataSource); - IPEndPoint endPoint; - endPoint = new IPEndPoint (hostEntry.AddressList [0], port); - - // This replaces the code below for now - socket.Connect (endPoint); - - /* - FIXME: Asynchronous socket connection doesn't work right on linux, so comment - this out for now. This *does* do the right thing on windows - - connected.Reset (); - IAsyncResult asyncResult = socket.BeginConnect (endPoint, new AsyncCallback (ConnectCallback), socket); - - if (timeout > 0 && !connected.WaitOne (new TimeSpan (0, 0, timeout), true)) - throw Tds.CreateTimeoutException (dataSource, "Open()"); - else if (timeout > 0 && !connected.WaitOne ()) - throw Tds.CreateTimeoutException (dataSource, "Open()"); - */ - - stream = new NetworkStream (socket); - } - - #endregion // Constructors - - #region Properties - - public int CommandTimeout { - get { return commandTimeout; } - set { commandTimeout = value; } - } - - internal Encoding Encoder { - set { encoder = value; } - } - - public int PacketSize { - get { return packetSize; } - set { packetSize = value; } - } - - #endregion // Properties - - #region Methods - - public void Append (byte b) - { - if (nextOutBufferIndex == outBufferLength) { - SendPhysicalPacket (false); - nextOutBufferIndex = headerLength; - } - Store (nextOutBufferIndex, b); - nextOutBufferIndex++; - } - - public void Append (byte[] b) - { - Append (b, b.Length, (byte) 0); - } - - public void Append (byte[] b, int len, byte pad) - { - int i = 0; - for ( ; i < b.Length && i < len; i++) - Append (b[i]); - - for ( ; i < len; i++) - Append (pad); - } - - public void Append (short s) - { - if (tdsVersion < TdsVersion.tds70) { - Append ((byte) (((byte) (s >> 8)) & 0xff)); - Append ((byte) (((byte) (s >> 0)) & 0xff)); - } - else - Append (BitConverter.GetBytes (s)); - } - - public void Append (int i) - { - if (tdsVersion < TdsVersion.tds70) { - Append ((byte) (((byte) (i >> 24)) & 0xff)); - Append ((byte) (((byte) (i >> 16)) & 0xff)); - Append ((byte) (((byte) (i >> 8)) & 0xff)); - Append ((byte) (((byte) (i >> 0)) & 0xff)); - } - else - Append (BitConverter.GetBytes (i)); - } - - public void Append (string s) - { - if (tdsVersion < TdsVersion.tds70) - Append (encoder.GetBytes (s)); - else - foreach (char c in s) - Append (BitConverter.GetBytes (c)); - } - - // Appends with padding - public byte[] Append (string s, int len, byte pad) - { - if (s == null) - return new byte[0]; - - byte[] result = encoder.GetBytes (s); - Append (result, len, pad); - return result; - } - - public void Append (double value) - { - Append (BitConverter.DoubleToInt64Bits (value)); - } - - public void Append (long l) - { - if (tdsVersion < TdsVersion.tds70) { - Append ((byte) (((byte) (l >> 56)) & 0xff)); - Append ((byte) (((byte) (l >> 48)) & 0xff)); - Append ((byte) (((byte) (l >> 40)) & 0xff)); - Append ((byte) (((byte) (l >> 32)) & 0xff)); - Append ((byte) (((byte) (l >> 24)) & 0xff)); - Append ((byte) (((byte) (l >> 16)) & 0xff)); - Append ((byte) (((byte) (l >> 8)) & 0xff)); - Append ((byte) (((byte) (l >> 0)) & 0xff)); - } - else - Append (BitConverter.GetBytes (l)); - } - - private void ConnectCallback (IAsyncResult ar) - { - Socket s = (Socket) ar.AsyncState; - if (Poll (s, connectionTimeout, SelectMode.SelectWrite)) { - socket.EndConnect (ar); - connected.Set (); - } - } - - public byte GetByte () - { - byte result; - - if (inBufferIndex >= inBufferLength) { - // out of data, read another physical packet. - GetPhysicalPacket (); - } - - result = inBuffer[inBufferIndex++]; - return result; - } - - public byte[] GetBytes (int len, bool exclusiveBuffer) - { - byte[] result = null; - int i; - - // Do not keep an internal result buffer larger than 16k. - // This would unnecessarily use up memory. - if (exclusiveBuffer || len > 16384) - result = new byte[len]; - else - { - if (resBuffer.Length < len) - resBuffer = new byte[len]; - result = resBuffer; - } - - for (i = 0; i<len; ) - { - if (inBufferIndex >= inBufferLength) - GetPhysicalPacket (); - - int avail = inBufferLength - inBufferIndex; - avail = avail>len-i ? len-i : avail; - - System.Array.Copy (inBuffer, inBufferIndex, result, i, avail); - i += avail; - inBufferIndex += avail; - } - - return result; - } - - public string GetString (int len) - { - if (tdsVersion == TdsVersion.tds70) - return GetString (len, true); - else - return GetString (len, false); - } - - public string GetString (int len, bool wide) - { - if (wide) { - char[] chars = new char[len]; - for (int i = 0; i < len; ++i) { - int lo = ((byte) GetByte ()) & 0xFF; - int hi = ((byte) GetByte ()) & 0xFF; - chars[i] = (char) (lo | ( hi << 8)); - } - return new String (chars); - } - else { - byte[] result = new byte[len + 1]; - Array.Copy (GetBytes (len, false), result, len); - result[len] = (byte) 0; - return (encoder.GetString (result)); - } - } - - public int GetNetShort () - { - byte[] tmp = new byte[2]; - tmp[0] = GetByte (); - tmp[1] = GetByte (); - return Ntohs (tmp, 0); - } - - public short GetTdsShort () - { - byte[] input = new byte[2]; - - for (int i = 0; i < 2; i += 1) - input[i] = GetByte (); - - return (BitConverter.ToInt16 (input, 0)); - } - - - public int GetTdsInt () - { - byte[] input = new byte[4]; - for (int i = 0; i < 4; i += 1) - input[i] = GetByte (); - return (BitConverter.ToInt32 (input, 0)); - } - - public long GetTdsInt64 () - { - byte[] input = new byte[8]; - for (int i = 0; i < 8; i += 1) - input[i] = GetByte (); - return (BitConverter.ToInt64 (input, 0)); - } - - private void GetPhysicalPacket () - { - int nread = 0; - - // read the header - while (nread < 8) - nread += stream.Read (tmpBuf, nread, 8 - nread); - - TdsPacketType packetType = (TdsPacketType) tmpBuf[0]; - if (packetType != TdsPacketType.Logon && packetType != TdsPacketType.Query && packetType != TdsPacketType.Reply) - { - throw new Exception (String.Format ("Unknown packet type {0}", tmpBuf[0])); - } - - // figure out how many bytes are remaining in this packet. - int len = Ntohs (tmpBuf, 2) - 8; - - if (len >= inBuffer.Length) - inBuffer = new byte[len]; - - if (len < 0) { - throw new Exception (String.Format ("Confused by a length of {0}", len)); - } - - // now get the data - nread = 0; - while (nread < len) { - nread += stream.Read (inBuffer, nread, len - nread); - } - - packetsReceived++; - - // adjust the bookkeeping info about the incoming buffer - inBufferLength = len; - inBufferIndex = 0; - } - - private static int Ntohs (byte[] buf, int offset) - { - int lo = ((int) buf[offset + 1] & 0xff); - int hi = (((int) buf[offset] & 0xff ) << 8); - - return hi | lo; - // return an int since we really want an _unsigned_ - } - - public byte Peek () - { - // If out of data, read another physical packet. - if (inBufferIndex >= inBufferLength) - GetPhysicalPacket (); - - return inBuffer[inBufferIndex]; - } - - public bool Poll (int seconds, SelectMode selectMode) - { - return Poll (socket, seconds, selectMode); - } - - private bool Poll (Socket s, int seconds, SelectMode selectMode) - { - long uSeconds = seconds * 1000000; - bool bState = false; - - while (uSeconds > (long) Int32.MaxValue) { - bState = s.Poll (Int32.MaxValue, selectMode); - if (bState) - return true; - uSeconds -= Int32.MaxValue; - } - return s.Poll ((int) uSeconds, selectMode); - } - - internal void ResizeOutBuf (int newSize) - { - if (newSize > outBufferLength) { - byte[] newBuf = new byte [newSize]; - Array.Copy (outBuffer, 0, newBuf, 0, outBufferLength); - outBufferLength = newSize; - outBuffer = newBuf; - } - } - - public void SendPacket () - { - SendPhysicalPacket (true); - nextOutBufferIndex = 0; - packetType = TdsPacketType.None; - } - - private void SendPhysicalPacket (bool isLastSegment) - { - if (nextOutBufferIndex > headerLength || packetType == TdsPacketType.Cancel) { - // packet type - Store (0, (byte) packetType); - Store (1, (byte) (isLastSegment ? 1 : 0)); - Store (2, (short) nextOutBufferIndex ); - Store (4, (byte) 0); - Store (5, (byte) 0); - Store (6, (byte) (tdsVersion == TdsVersion.tds70 ? 0x1 : 0x0)); - Store (7, (byte) 0); - - stream.Write (outBuffer, 0, nextOutBufferIndex); - stream.Flush (); - packetsSent++; - } - } - - public void Skip (int i) - { - for ( ; i > 0; i--) - GetByte (); - } - - public void StartPacket (TdsPacketType type) - { - if (type != TdsPacketType.Cancel && inBufferIndex != inBufferLength) - { - // SAfe It's ok to throw this exception so that we will know there - // is a design flaw somewhere, but we should empty the buffer - // however. Otherwise the connection will never close (e.g. if - // SHOWPLAN_ALL is ON, a resultset will be returned by commit - // or rollback and we will never get rid of it). It's true - // that we should find a way to actually process these packets - // but for now, just dump them (we have thrown an exception). - inBufferIndex = inBufferLength; - } - - packetType = type; - nextOutBufferIndex = headerLength; - } - - private void Store (int index, byte value) - { - outBuffer[index] = value; - } - - private void Store (int index, short value) - { - outBuffer[index] = (byte) (((byte) (value >> 8)) & 0xff); - outBuffer[index + 1] = (byte) (((byte) (value >> 0)) & 0xff); - } - - #endregion // Methods - } - -} diff --git a/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsConnectionParameters.cs b/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsConnectionParameters.cs deleted file mode 100644 index 4b9ae41d5e1..00000000000 --- a/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsConnectionParameters.cs +++ /dev/null @@ -1,23 +0,0 @@ -// -// Mono.Data.TdsClient.Internal.TdsConnectionParameters.cs -// -// Author: -// Tim Coleman (tim@timcoleman.com) -// -// Copyright (C) 2002 Tim Coleman -// - -namespace Mono.Data.TdsClient.Internal { - internal class TdsConnectionParameters - { - public string ApplicationName = "Mono"; - public string Database; - public string Charset; - public string Hostname = "localhost"; - public string Language; - public string LibraryName = "Mono"; - public string Password; - public string ProgName = "Mono"; - public string User; - } -} diff --git a/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsEnvPacketSubType.cs b/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsEnvPacketSubType.cs deleted file mode 100644 index 029b0282b6c..00000000000 --- a/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsEnvPacketSubType.cs +++ /dev/null @@ -1,16 +0,0 @@ -// -// Mono.Data.TdsClient.Internal.TdsEnvPacketSubType.cs -// -// Author: -// Tim Coleman (tim@timcoleman.com) -// -// Copyright (C) Tim Coleman, 2002 -// - -namespace Mono.Data.TdsClient.Internal { - internal enum TdsEnvPacketSubType { - Database = 0x1, - CharSet = 0x3, - BlockSize = 0x4 - } -} diff --git a/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsInternalError.cs b/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsInternalError.cs deleted file mode 100644 index 5bdf974aa93..00000000000 --- a/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsInternalError.cs +++ /dev/null @@ -1,89 +0,0 @@ -// -// Mono.Data.TdsClient.Internal.TdsInternalError.cs -// -// Authors: -// Tim Coleman (tim@timcoleman.com) -// -// Copyright (C) Tim Coleman, 2002 -// - -using System; - -namespace Mono.Data.TdsClient.Internal { - internal sealed class TdsInternalError - { - #region Fields - - byte theClass; - int lineNumber; - string message; - int number; - string procedure; - string server; - string source; - byte state; - - #endregion // Fields - - #region Constructors - - public TdsInternalError (byte theClass, int lineNumber, string message, int number, string procedure, string server, string source, byte state) - { - this.theClass = theClass; - this.lineNumber = lineNumber; - this.message = message; - this.number = number; - this.procedure = procedure; - this.server = server; - this.source = source; - this.state = state; - } - - #endregion // Constructors - - #region Properties - - public Byte Class { - get { return theClass; } - set { theClass = value; } - } - - public int LineNumber { - get { return lineNumber; } - set { lineNumber = value; } - } - - public string Message { - get { return message; } - set { message = value; } - } - - public int Number { - get { return number; } - set { number = value; } - } - - public string Procedure { - get { return procedure; } - set { procedure = value; } - } - - public string Server { - get { return server; } - set { server = value;} - } - - public string Source { - get { return source; } - set { source = value; } - } - - public byte State { - get { return state; } - set { state = value; } - } - - #endregion // Properties - } -} - diff --git a/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsInternalErrorCollection.cs b/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsInternalErrorCollection.cs deleted file mode 100644 index bd885a03cd6..00000000000 --- a/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsInternalErrorCollection.cs +++ /dev/null @@ -1,64 +0,0 @@ -// -// Mono.Data.TdsClient.Internal.TdsInternalErrorCollection.cs -// -// Authors: -// Tim Coleman (tim@timcoleman.com) -// -// Copyright (C) Tim Coleman, 2002 -// - -using System; -using System.Collections; - -namespace Mono.Data.TdsClient.Internal { - internal sealed class TdsInternalErrorCollection : IEnumerable - { - #region Fields - - ArrayList list; - - #endregion // Fields - - #region Constructors - - public TdsInternalErrorCollection () - { - list = new ArrayList (); - } - - #endregion // Constructors - - #region Properties - - public int Count { - get { return list.Count; } - } - - public TdsInternalError this [int index] { - get { return (TdsInternalError) list[index]; } - set { list[index] = value; } - } - - #endregion // Properties - - #region Methods - - public int Add (TdsInternalError error) - { - return list.Add (error); - } - - public void Clear () - { - list.Clear (); - } - - IEnumerator IEnumerable.GetEnumerator () - { - return list.GetEnumerator (); - } - - #endregion // Methods - } -} - diff --git a/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsInternalErrorMessageEventArgs.cs b/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsInternalErrorMessageEventArgs.cs deleted file mode 100644 index 551f50705d2..00000000000 --- a/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsInternalErrorMessageEventArgs.cs +++ /dev/null @@ -1,24 +0,0 @@ -// -// Mono.Data.TdsClient.Internal.TdsInternalErrorMessageEventArgs.cs -// -// Authors: -// Tim Coleman (tim@timcoleman.com) -// -// Copyright (C) Tim Coleman, 2002 -// - -using System; - -namespace Mono.Data.TdsClient.Internal { - internal sealed class TdsInternalErrorMessageEventArgs : TdsInternalInfoMessageEventArgs - { - #region Constructors - - public TdsInternalErrorMessageEventArgs (TdsInternalError error) - : base (error) - { - } - - #endregion // Constructors - } -} diff --git a/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsInternalErrorMessageEventHandler.cs b/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsInternalErrorMessageEventHandler.cs deleted file mode 100644 index 97fd7012b49..00000000000 --- a/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsInternalErrorMessageEventHandler.cs +++ /dev/null @@ -1,14 +0,0 @@ -// -// Mono.Data.TdsClient.Internal.TdsInternalErrorMessageEventHandler.cs -// -// Authors: -// Tim Coleman (tim@timcoleman.com) -// -// Copyright (C) Tim Coleman, 2002 -// - -using System; - -namespace Mono.Data.TdsClient.Internal { - internal delegate void TdsInternalErrorMessageEventHandler (object sender, TdsInternalErrorMessageEventArgs e); -} diff --git a/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsInternalException.cs b/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsInternalException.cs deleted file mode 100644 index d99a7187664..00000000000 --- a/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsInternalException.cs +++ /dev/null @@ -1,98 +0,0 @@ -// -// Mono.Data.TdsClient.TdsInternalException.cs -// -// Author: -// Tim Coleman (tim@timcoleman.com) -// -// Copyright (C) 2002 Tim Coleman -// - -using Mono.Data.TdsClient; -using System; -using System.Runtime.Serialization; - -namespace Mono.Data.TdsClient.Internal { - internal class TdsInternalException : SystemException - { - #region Fields - - byte theClass; - int lineNumber; - string message; - int number; - string procedure; - string server; - string source; - byte state; - - #endregion // Fields - - #region Constructors - - internal TdsInternalException () - : base ("a TDS Exception has occurred.") - { - } - - internal TdsInternalException (byte theClass, int lineNumber, string message, int number, string procedure, string server, string source, byte state) - : base (message) - { - this.theClass = theClass; - this.lineNumber = lineNumber; - this.message = message; - this.number = number; - this.procedure = procedure; - this.server = server; - this.source = source; - this.state = state; - } - - #endregion // Constructors - - #region Properties - - public byte Class { - get { return theClass; } - } - - public int LineNumber { - get { return lineNumber; } - } - - public override string Message { - get { return message; } - } - - public int Number { - get { return number; } - } - - public string Procedure { - get { return procedure; } - } - - public string Server { - get { return server; } - } - - public override string Source { - get { return source; } - } - - public byte State { - get { return state; } - } - - #endregion // Properties - - #region Methods - - [MonoTODO] - public override void GetObjectData (SerializationInfo si, StreamingContext context) - { - throw new NotImplementedException (); - } - - #endregion // Methods - } -} diff --git a/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsInternalInfoMessageEventArgs.cs b/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsInternalInfoMessageEventArgs.cs deleted file mode 100644 index b6f204002a7..00000000000 --- a/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsInternalInfoMessageEventArgs.cs +++ /dev/null @@ -1,85 +0,0 @@ -// -// Mono.Data.TdsClient.Internal.TdsInternalInfoMessageEventArgs.cs -// -// Authors: -// Tim Coleman (tim@timcoleman.com) -// -// Copyright (C) Tim Coleman, 2002 -// - -using System; - -namespace Mono.Data.TdsClient.Internal { - internal class TdsInternalInfoMessageEventArgs : EventArgs - { - #region Fields - - TdsInternalErrorCollection errors; - - #endregion // Fields - - #region Constructors - - public TdsInternalInfoMessageEventArgs (TdsInternalErrorCollection errors) - { - this.errors = errors; - } - - public TdsInternalInfoMessageEventArgs (TdsInternalError error) - { - this.errors = new TdsInternalErrorCollection (); - errors.Add (error); - } - - #endregion // Constructors - - #region Properties - - public TdsInternalErrorCollection Errors { - get { return errors; } - } - - public byte Class { - get { return errors[0].Class; } - } - - public int LineNumber { - get { return errors[0].LineNumber; } - } - - public string Message { - get { return errors[0].Message; } - } - - public int Number { - get { return errors[0].Number; } - } - - public string Procedure { - get { return errors[0].Procedure; } - } - - public string Server { - get { return errors[0].Server; } - } - - public string Source { - get { return errors[0].Source; } - } - - public byte State { - get { return errors[0].State; } - } - - #endregion // Properties - - #region Methods - - public int Add (byte theClass, int lineNumber, string message, int number, string procedure, string server, string source, byte state) - { - return errors.Add (new TdsInternalError (theClass, lineNumber, message, number, procedure, server, source, state)); - } - - #endregion // Methods - } -} diff --git a/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsInternalInfoMessageEventHandler.cs b/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsInternalInfoMessageEventHandler.cs deleted file mode 100644 index e8fd9500152..00000000000 --- a/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsInternalInfoMessageEventHandler.cs +++ /dev/null @@ -1,14 +0,0 @@ -// -// Mono.Data.TdsClient.Internal.TdsInternalInfoMessageEventHandler.cs -// -// Authors: -// Tim Coleman (tim@timcoleman.com) -// -// Copyright (C) Tim Coleman, 2002 -// - -using System; - -namespace Mono.Data.TdsClient.Internal { - internal delegate void TdsInternalInfoMessageEventHandler (object sender, TdsInternalInfoMessageEventArgs e); -} diff --git a/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsMessage.cs b/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsMessage.cs deleted file mode 100644 index 08a375e8456..00000000000 --- a/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsMessage.cs +++ /dev/null @@ -1,91 +0,0 @@ -// -// Mono.Data.TdsClient.Internal.TdsMessage.cs -// -// Author: -// Tim Coleman (tim@timcoleman.com) -// -// Copyright (C) Tim Coleman, 2002 -// - -using System; -using System.Text; - -namespace Mono.Data.TdsClient.Internal { - internal class TdsMessage - { - #region Fields - - int number = 0; - byte state = 0; - byte severity = 0; - string message = String.Empty; - string server = String.Empty; - string procName = String.Empty; - int line = 0; - - #endregion // Fields - - #region Properties - - public int Line { - get { return line; } - set { line = value; } - } - - public string Message { - get { return message; } - set { message = value; } - } - - public int Number { - get { return number; } - set { number = value; } - } - - public string ProcName { - get { return procName; } - set { procName = value; } - } - - public byte State { - get { return state; } - set { state = value; } - } - - public string Server { - get { return server; } - set { server = value; } - } - - public byte Severity { - get { return severity; } - set { severity = value; } - } - - #endregion // Properties - - #region Methods - - public override string ToString () - { - StringBuilder sb = new StringBuilder (); - sb.Append ("Server: "); - if (server != String.Empty) - sb.Append (String.Format ("{0}, ", server)); - if (number != 0) - sb.Append (String.Format ("Msg {0}, ", number)); - if (severity != 0) - sb.Append (String.Format ("Level {0}, ", severity)); - if (state != 0) - sb.Append (String.Format ("State {0}, ", state)); - if (procName != String.Empty) - sb.Append (String.Format ("Procedure {0}, ", procName)); - if (line != 0) - sb.Append (String.Format ("Line {0} ", line)); - sb.Append (message); - return sb.ToString (); - } - - #endregion // Methods - } -} diff --git a/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsPacketColumnInfoResult.cs b/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsPacketColumnInfoResult.cs deleted file mode 100644 index 7cc210e6360..00000000000 --- a/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsPacketColumnInfoResult.cs +++ /dev/null @@ -1,58 +0,0 @@ -// -// Mono.Data.TdsClient.Internal.TdsPacketColumnInfoResult.cs -// -// Author: -// Tim Coleman (tim@timcoleman.com) -// -// Copyright (C) Tim Coleman, 2002 -// - -using Mono.Data.TdsClient.Internal; -using System.Collections; - -namespace Mono.Data.TdsClient.Internal { - internal class TdsPacketColumnInfoResult : TdsPacketResult, IEnumerable - { - #region Fields - - ArrayList list; - - #endregion // Fields - - #region Constructors - - public TdsPacketColumnInfoResult () - : base (TdsPacketSubType.ColumnNameToken) - { - list = new ArrayList (); - } - - #endregion // Constructors - - #region Properties - - public TdsSchemaInfo this [int index] { - get { return (TdsSchemaInfo) list[index]; } - set { list[index] = value; } - } - - #endregion // Properties - - #region Methods - - public int Add (TdsSchemaInfo schema) - { - int index; - index = list.Add (schema); - schema["ColumnOrdinal"] = index; - return index; - } - - public IEnumerator GetEnumerator () - { - return list.GetEnumerator (); - } - - #endregion // Methods - } -} diff --git a/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsPacketColumnNamesResult.cs b/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsPacketColumnNamesResult.cs deleted file mode 100644 index f3f26e3d0d7..00000000000 --- a/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsPacketColumnNamesResult.cs +++ /dev/null @@ -1,54 +0,0 @@ -// -// Mono.Data.TdsClient.Internal.TdsPacketColumnNamesResult.cs -// -// Author: -// Tim Coleman (tim@timcoleman.com) -// -// Copyright (C) Tim Coleman, 2002 -// - -using System.Collections; - -namespace Mono.Data.TdsClient.Internal { - internal class TdsPacketColumnNamesResult : TdsPacketResult, IEnumerable - { - #region Fields - - ArrayList list; - - #endregion // Fields - - #region Constructors - - public TdsPacketColumnNamesResult () - : base (TdsPacketSubType.ColumnNameToken) - { - this.list = new ArrayList (); - } - - #endregion // Constructors - - #region Properties - - public string this[int index] { - get { return (string) list[index]; } - set { list[index] = value; } - } - - #endregion // Properties - - #region Methods - - public int Add (string columnName) - { - return list.Add (columnName); - } - - public IEnumerator GetEnumerator () - { - return list.GetEnumerator (); - } - - #endregion // Methods - } -} diff --git a/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsPacketColumnOrderResult.cs b/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsPacketColumnOrderResult.cs deleted file mode 100644 index ec708adb988..00000000000 --- a/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsPacketColumnOrderResult.cs +++ /dev/null @@ -1,22 +0,0 @@ -// -// Mono.Data.TdsClient.Internal.TdsPacketColumnOrderResult.cs -// -// Author: -// Tim Coleman (tim@timcoleman.com) -// -// Copyright (C) Tim Coleman, 2002 -// - -namespace Mono.Data.TdsClient.Internal { - internal class TdsPacketColumnOrderResult : TdsPacketResult - { - #region Constructors - - public TdsPacketColumnOrderResult () - : base (TdsPacketSubType.Order) - { - } - - #endregion // Constructors - } -} diff --git a/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsPacketControlResult.cs b/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsPacketControlResult.cs deleted file mode 100644 index 43f0ad2c509..00000000000 --- a/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsPacketControlResult.cs +++ /dev/null @@ -1,22 +0,0 @@ -// -// Mono.Data.TdsClient.Internal.TdsPacketControlResult.cs -// -// Author: -// Tim Coleman (tim@timcoleman.com) -// -// Copyright (C) Tim Coleman, 2002 -// - -namespace Mono.Data.TdsClient.Internal { - internal class TdsPacketControlResult : TdsPacketResult - { - #region Constructors - - public TdsPacketControlResult () - : base (TdsPacketSubType.Control) - { - } - - #endregion // Constructors - } -} diff --git a/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsPacketEndTokenResult.cs b/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsPacketEndTokenResult.cs deleted file mode 100644 index 463796f9da9..00000000000 --- a/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsPacketEndTokenResult.cs +++ /dev/null @@ -1,81 +0,0 @@ -// -// Mono.Data.TdsClient.Internal.TdsPacketEndTokenResult.cs -// -// Author: -// Tim Coleman (tim@timcoleman.com) -// -// Copyright (C) Tim Coleman, 2002 -// - -using System; - -namespace Mono.Data.TdsClient.Internal { - internal class TdsPacketEndTokenResult : TdsPacketResult - { - - #region Fields - - byte status; - int rowCount; - bool isRetStatSet; - int retStat; - TdsPacketSubType type; - - #endregion // Fields - - #region Constructors - - public TdsPacketEndTokenResult (TdsPacketSubType type, byte status, int rowCount) - : base (type) - { - this.type = type; - this.status = status; - this.rowCount = rowCount; - this.isRetStatSet = false; - } - - #endregion // Constructors - - #region Properties - - public int RowCount { - get { return rowCount; } - } - - public bool MoreResults { - get { return (status & 0x01) != 0; } - } - - public bool Cancelled { - get { return (status & 0x20) != 0; } - } - - public bool ReturnStatusExists { - get { return isRetStatSet; } - } - - public int ReturnStatus { - get { return retStat; } - set { - isRetStatSet = true; - retStat = value; - } - } - - public TdsPacketSubType Type { - get { return type; } - } - - #endregion // Properties - - #region Methods - - [MonoTODO] - public override string ToString () - { - return String.Format ("token type: {0}, row count: {1}, more results: {2}, was cancelled? {3}, return status: {4}", type, RowCount, MoreResults, Cancelled, (ReturnStatusExists ? ReturnStatus.ToString () : "No return status")); - } - - #endregion // Methods - } -} diff --git a/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsPacketOutputParam.cs b/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsPacketOutputParam.cs deleted file mode 100644 index 65f80d1fa7c..00000000000 --- a/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsPacketOutputParam.cs +++ /dev/null @@ -1,37 +0,0 @@ -// -// Mono.Data.TdsClient.Internal.TdsPacketOutputParam.cs -// -// Author: -// Tim Coleman (tim@timcoleman.com) -// -// Copyright (C) Tim Coleman, 2002 -// - -namespace Mono.Data.TdsClient.Internal { - internal class TdsPacketOutputParam : TdsPacketResult - { - #region Fields - - object value; - - #endregion // Fields - - #region Constructors - - public TdsPacketOutputParam (object value) - : base (TdsPacketSubType.Param) - { - this.value = value; - } - - #endregion // Constructors - - #region Properties - - public object Value { - get { return value; } - } - - #endregion // Properties - } -} diff --git a/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsPacketResult.cs b/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsPacketResult.cs deleted file mode 100644 index e8e20176eb2..00000000000 --- a/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsPacketResult.cs +++ /dev/null @@ -1,25 +0,0 @@ -// -// Mono.Data.TdsClient.Internal.TdsPacketResult.cs -// -// Author: -// Tim Coleman (tim@timcoleman.com) -// -// Copyright (C) Tim Coleman, 2002 -// - -namespace Mono.Data.TdsClient.Internal { - internal class TdsPacketResult - { - TdsPacketSubType packetType; - - public TdsPacketResult (TdsPacketSubType packetType) - { - PacketType = packetType; - } - - public TdsPacketSubType PacketType { - get { return packetType; } - set { packetType = value; } - } - } -} diff --git a/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsPacketRetStatResult.cs b/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsPacketRetStatResult.cs deleted file mode 100644 index 07ff40aefb2..00000000000 --- a/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsPacketRetStatResult.cs +++ /dev/null @@ -1,25 +0,0 @@ -// -// Mono.Data.TdsClient.Internal.TdsPacketRetStatResult.cs -// -// Author: -// Tim Coleman (tim@timcoleman.com) -// -// Copyright (C) Tim Coleman, 2002 -// - -namespace Mono.Data.TdsClient.Internal { - internal class TdsPacketRetStatResult : TdsPacketResult - { - int status; - - public TdsPacketRetStatResult (int status) - : base (TdsPacketSubType.ReturnStatus) - { - this.status = status; - } - - public int Status { - get { return status; } - } - } -} diff --git a/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsPacketRowResult.cs b/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsPacketRowResult.cs deleted file mode 100644 index 362f6867833..00000000000 --- a/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsPacketRowResult.cs +++ /dev/null @@ -1,126 +0,0 @@ -// -// Mono.Data.TdsClient.Internal.TdsPacketRowResult.cs -// -// Author: -// Tim Coleman (tim@timcoleman.com) -// -// Copyright (C) Tim Coleman, 2002 -// - -using System; -using System.Collections; - -namespace Mono.Data.TdsClient.Internal { - internal class TdsPacketRowResult : TdsPacketResult, IList, ICollection, IEnumerable - { - #region Fields - - ArrayList list; - int bigDecimalIndex; - - #endregion // Fields - - #region Constructors - - public TdsPacketRowResult () - : base (TdsPacketSubType.Row) - { - list = new ArrayList (); - bigDecimalIndex = -1; - } - - #endregion // Constructors - - #region Properties - - public int BigDecimalIndex { - get { return bigDecimalIndex; } - set { bigDecimalIndex = value; } - } - - public int Count { - get { return list.Count; } - } - - public bool IsFixedSize { - get { return false; } - } - - public bool IsReadOnly { - get { return false; } - } - - public bool IsSynchronized { - get { return list.IsSynchronized; } - } - - public object SyncRoot { - get { return list.SyncRoot; } - } - - public object this[int index] { - get { - if (index > list.Count) - throw new IndexOutOfRangeException (); - return list[index]; - } - set { list[index] = value; } - } - - #endregion // Properties - - #region Methods - - public int Add (object value) - { - return list.Add (value); - } - - public void Clear () - { - list.Clear (); - } - - public bool Contains (object value) - { - return list.Contains (value); - } - - public void CopyTo (Array array, int index) - { - list.CopyTo (array, index); - } - - public void CopyTo (int index, Array array, int arrayIndex, int count) - { - list.CopyTo (index, array, arrayIndex, count); - } - - public IEnumerator GetEnumerator () - { - return list.GetEnumerator (); - } - - public int IndexOf (object value) - { - return list.IndexOf (value); - } - - public void Insert (int index, object value) - { - list.Insert (index, value); - } - - public void Remove (object value) - { - list.Remove (value); - } - - public void RemoveAt (int index) - { - list.RemoveAt (index); - } - - #endregion // Methods - } -} diff --git a/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsPacketSubType.cs b/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsPacketSubType.cs deleted file mode 100644 index d230e2a3063..00000000000 --- a/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsPacketSubType.cs +++ /dev/null @@ -1,35 +0,0 @@ -// -// Mono.Data.TdsClient.Internal.TdsPacketSubType.cs -// -// Author: -// Tim Coleman (tim@timcoleman.com) -// -// Copyright (C) Tim Coleman, 2002 -// - -namespace Mono.Data.TdsClient.Internal { - internal enum TdsPacketSubType { - EnvChange = 0xe3, - Error = 0xaa, - Info = 0xab, - EED = 0xe5, - Param = 0xac, - LoginAck = 0xad, - ReturnStatus = 0x79, - ProcId = 0x7c, - Done = 0xfd, - DoneProc = 0xfe, - DoneInProc = 0xff, - ColumnNameToken = 0xa0, - ColumnInfoToken = 0xa1, - ColumnDetail = 0xa5, - Unknown0xA7 = 0xa7, - Unknown0xA8 = 0xa8, - TableName = 0xa4, - Order = 0xa9, - Control = 0xae, - Row = 0xd1, - ColumnMetadata = 0x81, - RowFormat = 0xee - } -} diff --git a/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsPacketTableNameResult.cs b/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsPacketTableNameResult.cs deleted file mode 100644 index 1328e49a010..00000000000 --- a/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsPacketTableNameResult.cs +++ /dev/null @@ -1,54 +0,0 @@ -// -// Mono.Data.TdsClient.Internal.TdsPacketTableNameResult.cs -// -// Author: -// Tim Coleman (tim@timcoleman.com) -// -// Copyright (C) Tim Coleman, 2002 -// - -using System; -using System.Collections; - -namespace Mono.Data.TdsClient.Internal { - internal class TdsPacketTableNameResult : TdsPacketResult, IEnumerable - { - #region Fields - - ArrayList list = new ArrayList (); - - #endregion // Fields - - #region Constructors - - public TdsPacketTableNameResult () - : base (TdsPacketSubType.TableName) - { - } - - #endregion // Constructors - - #region Properties - - public string this [int index] { - get { return (string) list [index]; } - set { list [index] = value; } - } - - #endregion // Properties - - #region Methods - - public int Add (string tableName) - { - return list.Add (tableName); - } - - IEnumerator IEnumerable.GetEnumerator () - { - return list.GetEnumerator (); - } - - #endregion // Methods - } -} diff --git a/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsPacketType.cs b/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsPacketType.cs deleted file mode 100644 index 3c7d7afa19c..00000000000 --- a/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsPacketType.cs +++ /dev/null @@ -1,23 +0,0 @@ -// -// Mono.Data.TdsClient.Internal.TdsPacketType.cs -// -// Author: -// Tim Coleman (tim@timcoleman.com) -// -// Copyright (C) 2002 Tim Coleman -// - -namespace Mono.Data.TdsClient.Internal { - internal enum TdsPacketType - { - None = 0x0, - Query = 0x1, - Logon = 0x2, - Proc = 0x3, - Reply = 0x4, - Cancel = 0x6, - Logon70 = 0x10, - Logoff = 0x71, - Capability = 0xe2 - } -} diff --git a/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsPacketUnknown.cs b/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsPacketUnknown.cs deleted file mode 100644 index 998273c55e1..00000000000 --- a/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsPacketUnknown.cs +++ /dev/null @@ -1,22 +0,0 @@ -// -// Mono.Data.TdsClient.Internal.TdsPacketUnknown.cs -// -// Author: -// Tim Coleman (tim@timcoleman.com) -// -// Copyright (C) Tim Coleman, 2002 -// - -namespace Mono.Data.TdsClient.Internal { - internal class TdsPacketUnknown : TdsPacketResult - { - #region Constructors - - public TdsPacketUnknown (TdsPacketSubType type) - : base (type) - { - } - - #endregion // Constructors - } -} diff --git a/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsSchemaInfo.cs b/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsSchemaInfo.cs deleted file mode 100644 index bb0333bcf2a..00000000000 --- a/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsSchemaInfo.cs +++ /dev/null @@ -1,45 +0,0 @@ -// -// System.Data.Common.TdsSchemaInfo.cs -// -// Author: -// Tim Coleman (tim@timcoleman.com) -// -// Copyright (C) Tim Coleman, 2002 -// - -using System.Collections; - -namespace Mono.Data.TdsClient.Internal { - internal class TdsSchemaInfo : Hashtable - { - #region Fields - - Hashtable table; - - #endregion // Fields - - #region Constructors - - public TdsSchemaInfo () - : base () - { - SetDefaultValues (); - } - - #endregion // Constructors - - #region Methods - - private void SetDefaultValues () - { - Add ("AllowDBNull", true); - Add ("ColumnOrdinal", 0); - Add ("IsAutoIncrement", false); - Add ("IsIdentity", false); - Add ("IsReadOnly", false); - Add ("IsRowVersion", false); - } - - #endregion // Methods - } -} diff --git a/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsServerType.cs b/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsServerType.cs deleted file mode 100644 index 459baad0394..00000000000 --- a/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsServerType.cs +++ /dev/null @@ -1,17 +0,0 @@ -// -// Mono.Data.TdsClient.Internal.TdsServerType.cs -// -// Author: -// Tim Coleman (tim@timcoleman.com) -// -// Copyright (C) 2002 Tim Coleman -// - -namespace Mono.Data.TdsClient.Internal { - internal enum TdsServerType - { - Generic, // use TDS version 4.2 - SqlServer, // use TDS version 4.2, 7.0, 8.0 - Sybase // use TDS version 4,2, 5.0 - } -} diff --git a/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsTimeoutException.cs b/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsTimeoutException.cs deleted file mode 100644 index 41cc88f8caf..00000000000 --- a/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsTimeoutException.cs +++ /dev/null @@ -1,20 +0,0 @@ -// -// Mono.Data.TdsClient.TdsTimeoutException.cs -// -// Author: -// Tim Coleman (tim@timcoleman.com) -// -// Copyright (C) 2002 Tim Coleman -// - -using System; - -namespace Mono.Data.TdsClient.Internal { - internal class TdsTimeoutException : TdsInternalException - { - internal TdsTimeoutException (byte theClass, int lineNumber, string message, int number, string procedure, string server, string source, byte state) - : base (theClass, lineNumber, message, number, procedure, server, source, state) - { - } - } -} diff --git a/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsVersion.cs b/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsVersion.cs deleted file mode 100644 index b215fa5a5fb..00000000000 --- a/mcs/class/Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsVersion.cs +++ /dev/null @@ -1,18 +0,0 @@ -// -// Mono.Data.TdsClient.Internal.TdsVersionInternal.cs -// -// Author: -// Daniel Morgan <danmorg@sc.rr.com> -// -// Copyright (C) 2002 Daniel Morgan -// - -namespace Mono.Data.TdsClient.Internal { - public enum TdsVersion - { - tds42 = 42, // used by older Sybase and Microsoft SQL (< 7.0) servers - tds50 = 50, // used by Sybase - tds70 = 70, // used by Microsoft SQL server 7.0/2000 - tds80 = 80 // used by Microsoft SQL server 2000 - } -} |