Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
//
// AssemblyInfo.cs
//
// Author:
// Andreas Nahr (ClassDevelopment@A-SoftTech.com)
//
// (C) 2003 Ximian, Inc. http://www.ximian.com
// (C) 2004 Novell (http://www.novell.com)
//
using System;
using System.Reflection;
using System.Runtime.InteropServices;
[assembly: AssemblyVersion (Consts.FxVersion)]
/* TODO COMPLETE INFORMATION
[assembly: AssemblyTitle ("")]
[assembly: AssemblyDescription ("")]
[assembly: CLSCompliant (true)]
[assembly: AssemblyFileVersion ("0.0.0.1")]
[assembly: ComVisible (false)]
*/
[assembly: AssemblyDelaySign (true)]
[assembly: AssemblyKeyFile ("../mono.pub")]

View File

@@ -0,0 +1,5 @@
2004-04-28 Sebastien Pouliot <sebastien@ximian.com>
* AssemblyInfo.cs: Added
* ChangeLog: Added
* Locale.cs: Added

View File

@@ -0,0 +1,197 @@
2008-06-09 Ankit Jain <jankit@novell.com>
* ITds.cs: Removed.
* Mono.Data.Tds.dll.sources: Update.
2007-07-22 Nagappan A <anagappan@novell.com>
* Mono.Data.Tds.dll.sources: Added
Mono.Data.Tds.Protocol/TdsBulkCopy.cs.
2005-09-21 Senganal T <tsenganal@novell.com>
* Mono.Data.Tds.Protocol/Tds.cs:
- Modified the way Server Version number is calculated
- Added a new varaible to remember the original database
connected to and to reset the Database property when the
connection to database is closed.
* Mono.Data.Tds.Protocol/Tds70.cs:
modified Reset() to Call the Reset() of base class which
in turn resets the database name.
2005-04-07 Sureshkumar T <tsureshkumar@novell.com>
* Mono.Data.Tds.dll.sources: In Mono.Data.Tds.Protocol
Added TdsAsyncResult.cs & TdsAsyncState.cs.
2004-08-14 Geoff Norton <gnorton@customerdna.com>
* Mono.Data.Tds.Protocol/TdsComm.cs:
Mono.Data.Tds.Protocol/Tds70.cs:
Make Tds70 work on Big Endian machines.
2004-04-28 Sebastien Pouliot <sebastien@ximian.com>
* Mono.Data.Tds.dll.sources: Added Assembly/AssemblyInfo.cs and
Locale.cs to the build.
2004-04-05 Lluis Sanchez Gual <lluis@ximian.com>
* Mono.Data.Tds.dll.sources: Added TdsConnectionPool.cs.
2004-04-01 Lluis Sanchez Gual <lluis@ximian.com>
* TdsMetaParameter.cs: When the size of the parameter is not specified,
use the same default sizes as in MS.NET.
2003-12-17 Sebastien Pouliot <spouliot@videotron.ca>
for Daniel Morgan <danielmorgan@verizon.net>
* Makefile: added Mono.Security.dll as a reference so we can get
NTLM support via Mono.Security.Protocol.Ntlm
2003-11-20 Joerg Rosenkranz <joergr@voelcker.com>
* Mono.Data.Tds/TdsMetaParameter.cs: Fixed Prepare to allow string
and binary parameters with Length == 0
2002-12-22 Tim Coleman <tim@timcoleman.com>
* Mono.Data.Tds.Protocol/TdsComm.cs:
Change GetString to NOT explicitly add a NUL
to the end of the string since Encoder.GetString ()
will do that.
2002-12-14 Daniel Morgan <danmorg@sc.rr.com>
* Mono.Data.Tds.Protocol/Tds70.cs: single quotes in SQL string
need to be escaped as two single quotes
2002-12-01 Tim Coleman <tim@timcoleman.com>
* list:
Remove more unnecessary files.
* Mono.Data.Tds.Protocol/TdsDataRow.cs:
* Mono.Data.Tds.Protocol/TdsDataColumn.cs:
* Mono.Data.Tds.Protocol/TdsDataColumnCollection.cs:
New classes
* Mono.Data.Tds.Protocol/TdsPacketColumnInfoResult.cs:
* Mono.Data.Tds.Protocol/TdsPacketColumnOrderResult.cs:
* Mono.Data.Tds.Protocol/TdsPacketControlResult.cs:
* Mono.Data.Tds.Protocol/TdsPacketOutputParam.cs:
* Mono.Data.Tds.Protocol/TdsPacketResult.cs:
* Mono.Data.Tds.Protocol/TdsPacketRowResult.cs:
* Mono.Data.Tds.Protocol/TdsSchemaInfo.cs:
Remove obsolete classes
* Mono.Data.Tds.Protocol/ITds.cs:
* Mono.Data.Tds.Protocol/Tds.cs:
* Mono.Data.Tds.Protocol/Tds42.cs:
* Mono.Data.Tds.Protocol/Tds50.cs:
* Mono.Data.Tds.Protocol/Tds70.cs:
* Mono.Data.Tds.Protocol/Tds80.cs:
Change Schema and ColumnValues
2002-11-30 Tim Coleman <tim@timcoleman.com>
* list:
Remove unnecessary files.
* Mono.Data.Tds.Protocol/TdsPacketEndTokenResult.cs:
* Mono.Data.Tds.Protocol/TdsMessage.cs:
* Mono.Data.Tds.Protocol/TdsPacketUnknown.cs:
* Mono.Data.Tds.Protocol/TdsPacketRetStatResult.cs:
Remove these classes as they are unused.
* Mono.Data.Tds.Protocol/TdsPacketColumnNamesResult.cs:
* Mono.Data.Tds.Protocol/TdsPacketTableNameResult.cs:
Remove these classes, since they are essentially just
ArrayLists.
* Mono.Data.Tds.Protocol/Tds.cs:
* Mono.Data.Tds.Protocol/Tds42.cs:
* Mono.Data.Tds.Protocol/Tds50.cs:
* Mono.Data.Tds.Protocol/Tds70.cs:
Make ProcessSubPacket return an enum instead of instantiating
useless classes. Remove the TdsPacketColumnNamesResult
and TdsPacketTableNameResult in favour of ArrayLists.
* Mono.Data.Tds.Protocol/TdsPacketColumnInfoResult.cs:
Add a Count property.
2002-11-26 Tim Coleman <tim@timcoleman.com>
* list:
* Mono.Data.Tds/TdsMetaParameter.cs:
* Mono.Data.Tds/TdsMetaParameterCollection.cs:
* Mono.Data.Tds/TdsParameterDirection.cs:
* Mono.Data.Tds.Protocol/ITds.cs:
* Mono.Data.Tds.Protocol/Tds.cs:
* Mono.Data.Tds.Protocol/Tds50.cs:
* Mono.Data.Tds.Protocol/Tds70.cs:
* Mono.Data.Tds.Protocol/Tds80.cs:
* Mono.Data.Tds.Protocol/TdsColumnType.cs:
* Mono.Data.Tds.Protocol/TdsComm.cs:
* Mono.Data.Tds.Protocol/TdsPacketColumnInfoResult.cs:
* Mono.Data.Tds.Protocol/TdsPacketColumnNamesResult.cs:
* Mono.Data.Tds.Protocol/TdsPacketColumnOrderResult.cs:
* Mono.Data.Tds.Protocol/TdsPacketSubType.cs:
* Mono.Data.Tds.Protocol/TdsPacketType.cs:
Restructuring around making Sybase and SQL Server
support both work with same interface. In particular,
the bulk of parameter work is moved into the meta
parameter objects from the native objects. The
Sybase TDS50 stuff needs intimate access to the parameters.
This will also allow me to eventually plonk output values
directly into parameters rather than through the current
klugey interface.
2002-11-24 Tim Coleman <tim@timcoleman.com>
* Mono.Data.Tds.Protocol/Tds.cs: Change error/
message conditions because they were
reversed (caused wrongful exceptions).
2002-11-21 Daniel Morgan <danmorg@sc.rr.com>
* Mono.Data.Tds.build: added missing file
for Windows build
2002-11-21 Tim Coleman <tim@timcoleman.com>
* list:
* ChangeLog:
* Mono.Data.Tds.build:
* makefile.gnu:
* Mono.Data.Tds.Protocol/ITds.cs:
* Mono.Data.Tds.Protocol/Tds.cs:
* Mono.Data.Tds.Protocol/Tds42.cs:
* Mono.Data.Tds.Protocol/Tds50.cs:
* Mono.Data.Tds.Protocol/Tds70.cs:
* Mono.Data.Tds.Protocol/Tds80.cs:
* Mono.Data.Tds.Protocol/TdsBigDecimal.cs:
* Mono.Data.Tds.Protocol/TdsColumnStatus.cs:
* Mono.Data.Tds.Protocol/TdsColumnType.cs:
* Mono.Data.Tds.Protocol/TdsComm.cs:
* Mono.Data.Tds.Protocol/TdsConnectionParameters.cs:
* Mono.Data.Tds.Protocol/TdsEnvPacketSubType.cs:
* Mono.Data.Tds.Protocol/TdsInternalError.cs:
* Mono.Data.Tds.Protocol/TdsInternalErrorCollection.cs:
* Mono.Data.Tds.Protocol/TdsInternalErrorMessageEventArgs.cs:
* Mono.Data.Tds.Protocol/TdsInternalErrorMessageEventHandler.cs:
* Mono.Data.Tds.Protocol/TdsInternalException.cs:
* Mono.Data.Tds.Protocol/TdsInternalInfoMessageEventArgs.cs:
* Mono.Data.Tds.Protocol/TdsInternalInfoMessageEventHandler.cs:
* Mono.Data.Tds.Protocol/TdsMessage.cs:
* Mono.Data.Tds.Protocol/TdsPacketColumnInfoResult.cs:
* Mono.Data.Tds.Protocol/TdsPacketColumnNamesResult.cs:
* Mono.Data.Tds.Protocol/TdsPacketColumnOrderResult.cs:
* Mono.Data.Tds.Protocol/TdsPacketControlResult.cs:
* Mono.Data.Tds.Protocol/TdsPacketEndTokenResult.cs:
* Mono.Data.Tds.Protocol/TdsPacketOutputParam.cs:
* Mono.Data.Tds.Protocol/TdsPacketResult.cs:
* Mono.Data.Tds.Protocol/TdsPacketRetStatResult.cs:
* Mono.Data.Tds.Protocol/TdsPacketRowResult.cs:
* Mono.Data.Tds.Protocol/TdsPacketSubType.cs:
* Mono.Data.Tds.Protocol/TdsPacketTableNameResult.cs:
* Mono.Data.Tds.Protocol/TdsPacketType.cs:
* Mono.Data.Tds.Protocol/TdsPacketUnknown.cs:
* Mono.Data.Tds.Protocol/TdsSchemaInfo.cs:
* Mono.Data.Tds.Protocol/TdsServerType.cs:
* Mono.Data.Tds.Protocol/TdsTimeoutException.cs:
* Mono.Data.Tds.Protocol/TdsVersion.cs:
* Mono.Data.Tds.Protocol/TODOAttribute.cs:
New assembly. The Protocol files came from
Mono.Data.TdsClient.Internal, and thus their
protection levels and namespaces have changed.

View File

@@ -0,0 +1,10 @@
thisdir = class/Mono.Data.Tds
SUBDIRS =
include ../../build/rules.make
LIBRARY = Mono.Data.Tds.dll
LIB_MCS_FLAGS = /r:$(corlib) /r:System.dll /r:System.Xml.dll /r:Mono.Security.dll
TEST_MCS_FLAGS = /r:System.dll /r:System.Net.dll
include ../../build/library.make

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,299 @@
//
// Mono.Data.Tds.Protocol.Tds42.cs
//
// Author:
// Tim Coleman (tim@timcoleman.com)
//
// Copyright (C) 2002 Tim Coleman
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
namespace Mono.Data.Tds.Protocol {
public sealed 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 ();
MoreResults = true;
SkipToEnd ();
return IsConnected;
}
protected override void ProcessColumnInfo ()
{
byte precision;
byte scale;
int totalLength = Comm.GetTdsShort ();
int bytesRead = 0;
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;
}
TdsDataColumn col = new TdsDataColumn ();
int index = Columns.Add (col);
#if NET_2_0
col.ColumnType = columnType;
col.ColumnSize = bufLength;
col.ColumnName = ColumnNames[index] as string;
col.NumericPrecision = precision;
col.NumericScale = scale;
col.IsReadOnly = !writable;
col.BaseTableName = tableName;
col.AllowDBNull = nullable;
#else
col["ColumnType"] = columnType;
col["ColumnSize"] = bufLength;
col["ColumnName"] = ColumnNames[index];
col["NumericPrecision"] = precision;
col["NumericScale"] = scale;
col["IsReadOnly"] = !writable;
col["BaseTableName"] = tableName;
col["AllowDBNull"] = nullable;
#endif
}
}
#endregion // Methods
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,268 @@
//
// Mono.Data.Tds.Protocol.Tds80.cs
//
// Author:
// Tim Coleman (tim@timcoleman.com)
// Veerapuram Varadhan (vvaradhan@novell.com)
//
// Copyright (C) 2002 Tim Coleman
// Copyright (C) 2008,2009 Novell Inc.
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using Mono.Data.Tds;
using System;
namespace Mono.Data.Tds.Protocol {
public class Tds80 : Tds70
{
#region Fields
public static readonly TdsVersion Version = TdsVersion.tds80;
#endregion // Fields
#region Constructors
[Obsolete ("Use the constructor that receives a lifetime parameter")]
public Tds80 (string server, int port)
: this (server, port, 512, 15, 0)
{
}
[Obsolete ("Use the constructor that receives a lifetime parameter")]
public Tds80 (string server, int port, int packetSize, int timeout)
: base (server, port, packetSize, timeout, 0, Version)
{
}
public Tds80 (string server, int port, int lifetime)
: this (server, port, 512, 15, lifetime)
{
}
public Tds80 (string server, int port, int packetSize, int timeout, int lifeTime)
: base (server, port, packetSize, timeout, lifeTime, Version)
{
}
#endregion // Constructors
#region Properties
protected override byte[] ClientVersion {
get { return new byte[] {0x00, 0x0, 0x0, 0x71};}
}
protected override byte Precision {
get { return 38; }
}
#endregion // Properties
#region Methods
public override bool Connect (TdsConnectionParameters connectionParameters)
{
//Console.WriteLine ("Tds80::Connect");
return base.Connect (connectionParameters);
}
protected override void ProcessColumnInfo ()
{
// We are connected to a Sql 7.0 server
if (TdsVersion < TdsVersion.tds80) {
base.ProcessColumnInfo ();
return;
}
// VARADHAN: TDS 8 Debugging
//Console.WriteLine ("Tds80.cs: In ProcessColumnInfo... entry");
int numColumns = Comm.GetTdsShort ();
//Console.WriteLine ("Column count={0}", numColumns); TDS 8 Debugging
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);
//Console.WriteLine ("Actual ColumnType: {0}", columnType); TDS 8 Debugging
if ((byte) columnType == 0xef)
columnType = TdsColumnType.NChar;
TdsColumnType xColumnType = columnType;
if (IsLargeType (columnType)) {
if (columnType != TdsColumnType.NChar)
columnType -= 128;
}
int columnSize;
string tableName = null;
byte[] collation = null;
int lcid = 0, sortId = 0;
if (IsBlobType (columnType)) {
columnSize = Comm.GetTdsInt ();
} else if (IsFixedSizeColumn (columnType)) {
columnSize = LookupBufferSize (columnType);
} else if (IsLargeType (xColumnType)) {
columnSize = Comm.GetTdsShort ();
} else {
columnSize = Comm.GetByte () & 0xff;
}
if (xColumnType == TdsColumnType.BigChar || xColumnType == TdsColumnType.BigNVarChar ||
xColumnType == TdsColumnType.BigVarChar || xColumnType == TdsColumnType.NChar ||
xColumnType == TdsColumnType.NVarChar || xColumnType == TdsColumnType.Text ||
xColumnType == TdsColumnType.NText) {
// Read collation for SqlServer 2000 and beyond
collation = Comm.GetBytes (5, true);
lcid = TdsCollation.LCID (collation);
sortId = TdsCollation.SortId (collation);
}
if (IsBlobType (columnType)) {
tableName = Comm.GetString (Comm.GetTdsShort ());
//Console.WriteLine ("Tablename: "+tableName); TDS 8 Debugging
}
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:
//Comm.Skip (1);
precision = Comm.GetByte ();
//Console.WriteLine ("Precision: {0}", precision); TDS 8 Debugging
scale = Comm.GetByte ();
//Console.WriteLine ("Scale: {0}", scale); TDS 8 Debugging
break;
}
string columnName = Comm.GetString (Comm.GetByte ());
TdsDataColumn col = new TdsDataColumn ();
Columns.Add (col);
#if NET_2_0
col.ColumnType = columnType;
col.ColumnName = columnName;
col.IsAutoIncrement = autoIncrement;
col.IsIdentity = isIdentity;
col.ColumnSize = columnSize;
col.NumericPrecision = precision;
col.NumericScale = scale;
col.IsReadOnly = !writable;
col.AllowDBNull = nullable;
col.BaseTableName = tableName;
col.LCID = lcid;
col.SortOrder = sortId;
#else
col ["ColumnType"] = columnType;
col ["ColumnName"] = columnName;
col ["IsAutoIncrement"] = autoIncrement;
col ["IsIdentity"] = isIdentity;
col ["ColumnSize"] = columnSize;
col ["NumericPrecision"] = precision;
col ["NumericScale"] = scale;
col ["IsReadOnly"] = !writable;
col ["AllowDBNull"] = nullable;
col ["BaseTableName"] = tableName;
col ["LCID"] = lcid;
col ["SortOrder"] = sortId;
#endif
}
//Console.WriteLine ("Tds80.cs: In ProcessColumnInfo... exit"); TDS 8 Debugging
}
protected override void ProcessOutputParam ()
{
// We are connected to a Sql 7.0 server
if (TdsVersion < TdsVersion.tds80) {
base.ProcessOutputParam ();
return;
}
GetSubPacketLength ();
Comm.Skip ((Comm.GetByte () & 0xff) <<1); // Parameter name
Comm.Skip (1); // Status: 0x01 - in case of OUTPUT parameter
// Status: 0x02 - in case of return value of UDF
Comm.Skip (4); // Usertype - sizeof (ULong)
TdsColumnType colType = (TdsColumnType) Comm.GetByte ();
object value = GetColumnValue (colType, true);
OutputParameters.Add (value);
}
public override void Execute (string commandText, TdsMetaParameterCollection parameters, int timeout, bool wantResults)
{
// We are connected to a Sql 7.0 server
if (TdsVersion < TdsVersion.tds80) {
base.Execute (commandText, parameters, timeout, wantResults);
return;
}
Parameters = parameters;
string sql = commandText;
if (Parameters != null && Parameters.Count > 0) {
ExecRPC (TdsRpcProcId.ExecuteSql, commandText, parameters, timeout, wantResults);
} else {
if (wantResults)
sql = BuildExec (commandText);
ExecuteQuery (sql, timeout, wantResults);
}
}
public override void ExecPrepared (string commandText, TdsMetaParameterCollection parameters, int timeout, bool wantResults)
{
Parameters = parameters;
// We are connected to a Sql 7.0 server
if (TdsVersion < TdsVersion.tds80 ||
Parameters == null || Parameters.Count < 1) {
base.ExecPrepared (commandText, parameters, timeout, wantResults);
return;
}
TdsMetaParameterCollection parms = new TdsMetaParameterCollection ();
parms.Add (new TdsMetaParameter ("@Handle", "int", Int32.Parse (commandText)));
foreach (TdsMetaParameter parm in Parameters)
parms.Add (parm);
ExecRPC ("sp_execute", parms, timeout, wantResults);
}
#endregion // Methods
}
}

View File

@@ -0,0 +1,128 @@
//
// Mono.Data.Tds.Protocol.TdsAsyncResult.cs
//
// Author:
// T Sureshkumar <tsureshkumar@novell.com>
// Ankit Jain <radical@corewars.org>
//
// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if NET_2_0
using System;
using System.Threading;
namespace Mono.Data.Tds.Protocol
{
internal class TdsAsyncResult : IAsyncResult
{
private TdsAsyncState _tdsState;
private WaitHandle _waitHandle;
private bool _completed = false;
private bool _completedSyncly = false;
private AsyncCallback _userCallback;
private object _retValue;
private Exception _exception = null;
public TdsAsyncResult (AsyncCallback userCallback, TdsAsyncState tdsState)
{
_tdsState = tdsState;
_userCallback = userCallback;
_waitHandle = new ManualResetEvent (false);
}
public TdsAsyncResult (AsyncCallback userCallback, object state)
{
_tdsState = new TdsAsyncState (state);
_userCallback = userCallback;
_waitHandle = new ManualResetEvent (false);
}
public object AsyncState
{
get { return _tdsState.UserState; }
}
internal TdsAsyncState TdsAsyncState
{
get { return _tdsState; }
}
public WaitHandle AsyncWaitHandle
{
get { return _waitHandle; }
}
public bool IsCompleted
{
get { return _completed; }
}
public bool IsCompletedWithException
{
get { return _exception != null; }
}
public Exception Exception
{
get { return _exception; }
}
public bool CompletedSynchronously
{
get { return _completedSyncly; }
}
internal object ReturnValue
{
get { return _retValue; }
set { _retValue = value; }
}
internal void MarkComplete ()
{
_completed = true;
_exception = null;
((ManualResetEvent)_waitHandle).Set ();
if (_userCallback != null)
_userCallback (this);
}
internal void MarkComplete (Exception e)
{
_completed = true;
_exception = e;
((ManualResetEvent)_waitHandle).Set ();
if (_userCallback != null)
_userCallback (this);
}
}
}
#endif // NET_2_0

View File

@@ -0,0 +1,63 @@
//
// Mono.Data.Tds.Protocol.TdsAsyncState.cs
//
// Author:
// T Sureshkumar <tsureshkumar@novell.com>
// Ankit Jain <radical@corewars.org>
//
//
// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if NET_2_0
using System;
using System.Net.Sockets;
namespace Mono.Data.Tds.Protocol {
internal class TdsAsyncState
{
object _userState;
bool _wantResults = false;
public TdsAsyncState (object userState)
{
_userState = userState;
}
public object UserState
{
get {return _userState;}
set {_userState = value;}
}
public bool WantResults
{
get {return _wantResults;}
set {_wantResults = value;}
}
}
}
#endif // NET_2_0

View File

@@ -0,0 +1,75 @@
//
// Mono.Data.Tds.Protocol.TdsBigDecimal.cs
//
// Author:
// Tim Coleman (tim@timcoleman.com)
//
// Copyright (C) Tim Coleman, 2002
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Data.Tds.Protocol {
public 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
}
}

View File

@@ -0,0 +1,223 @@
//
// Mono.Data.Tds.Protocol.TdsBulkCopy.cs
//
// Author:
// Nagappan A (anagappan@novell.com)
//
// Copyright (C) 2007 Novell Inc
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if NET_2_0
using System;
namespace Mono.Data.Tds.Protocol {
public class TdsBulkCopy
{
#region Fields
Tds tds;
#endregion
#region Constructors
public TdsBulkCopy (Tds tds)
{
this.tds = tds;
}
#endregion
#region Methods
public bool SendColumnMetaData (string colMetaData)
{
tds.Comm.StartPacket (TdsPacketType.Query);
tds.Comm.Append (colMetaData);
tds.ExecBulkCopyMetaData (30, false);
return true;
}
public bool BulkCopyStart (TdsMetaParameterCollection parameters)
{
tds.Comm.StartPacket (TdsPacketType.Bulk);
tds.Comm.Append ((byte) TdsPacketSubType.ColumnMetadata);
short count = 0;
foreach (TdsMetaParameter param in parameters) {
if (param.Value != null)
continue;
count++;
}
tds.Comm.Append (count);
if (parameters != null) {
foreach (TdsMetaParameter param in parameters) {
if (param.Value != null)
continue;
tds.Comm.Append ((short) 0x00);
if (param.IsNullable) {
// fNullable = true
// usUpdateable = Unused/Unkown
tds.Comm.Append ((short) 0x09);
} else {
// usUpdateable = Unused/Unkown
tds.Comm.Append ((short) 0x08);
}
WriteParameterInfo (param);
tds.Comm.Append ((byte) param.ParameterName.Length);
tds.Comm.Append (param.ParameterName);
}
}
return true;
}
public bool BulkCopyData (object o, bool isNewRow, int size, TdsMetaParameter parameter)
{
// First append a new row byte if needed
if (isNewRow)
tds.Comm.Append ((byte) TdsPacketSubType.Row);
// Push the null value if that is what was supplied
if (o == null || o == DBNull.Value) {
if (parameter.IsAnyVarCharMax) {
// So max varchar and nvarchar needs to contain all F's as a long value. Seems crazy
// but oh well
tds.Comm.Append(System.Convert.ToInt64("0xFFFFFFFFFFFFFFFF", 16));
} else if (parameter.IsTextType) {
tds.Comm.Append((byte)0XFF);
tds.Comm.Append((byte)0XFF);
}
else
tds.Comm.Append ((byte)0);
return true;
}
// Now we must put the size in if it is a VariableType
// The length of the size field varies based on what type it is
parameter.CalculateIsVariableType();
if (parameter.IsVariableSizeType) {
//int size = parameter.GetActualSize();
if (parameter.IsAnyVarCharMax) {
// So max varchar and nvarchar needs to contain the long value as well as size is specified as int
tds.Comm.Append(System.Convert.ToInt64("0xFFFFFFFFFFFFFFFE", 16));
tds.Comm.Append ((int) size);
}
else if (o.GetType() == typeof(string))
tds.Comm.Append ((short) size);
else
tds.Comm.Append ((byte) size);
}
// There are a few special cases for bulk insert that we will handle ourself
// Otherwise we can just pass the value down to the generic Append Object function
if (parameter.IsNonUnicodeText)
tds.Comm.AppendNonUnicode ((string)o);
else if (parameter.IsMoneyType)
tds.Comm.AppendMoney ((decimal)o, size);
else if (parameter.IsDateTimeType)
tds.Comm.Append((DateTime)o, size);
else if (parameter.IsDecimalType)
tds.Comm.AppendDecimal((decimal)o, size, parameter.Scale);
else
tds.Comm.Append (o);
// For some reason max varchar and nvarchar values need to have 4 bytes of 0 appended
if (parameter.IsAnyVarCharMax)
tds.Comm.Append ((int)0);
return true;
}
public bool BulkCopyEnd ()
{
tds.Comm.Append ((byte) TdsPacketSubType.Done);
// So the TDS spec calls for a Status (ushort), CurCmd (ushort) and DoneRowCount (long)
// all of which are 0.
// However it looks like MS .net is only sending 8 bytes not sure which parts they are leaving
// out but we are going with the TDS spec size
tds.Comm.Append ((short) 0x00);
tds.Comm.Append ((short) 0x00);
tds.Comm.Append ((long) 0x00);
tds.ExecBulkCopy (30, false);
return true;
}
private void WriteParameterInfo (TdsMetaParameter param)
{
TdsColumnType colType = param.GetMetaType ();
int size = 0;
if (param.Size == 0)
size = param.GetActualSize ();
else
size = param.Size;
/*
* If column type is SqlDbType.NVarChar the size of parameter is multiplied by 2
* FIXME: Need to check for other types
*/
if (colType == TdsColumnType.BigNVarChar)
size <<= 1;
// Total hack for varchar(max) and nvarchar(max)
// They are coming back as Text and not the correct values
// based on the size we can determine what the correct type is
// We need the size to come out to 0xFFFF on the wire.
if (param.IsVarNVarCharMax)
colType = TdsColumnType.BigNVarChar;
else if (param.IsVarCharMax)
colType = TdsColumnType.BigVarChar;
tds.Comm.Append ((byte)colType); // type
param.CalculateIsVariableType();
if (param.IsAnyVarCharMax) {
tds.Comm.Append ((byte)0xFF);
tds.Comm.Append ((byte)0xFF);
} else if (tds.IsLargeType (colType))
tds.Comm.Append ((short)size); // Parameter size passed in SqlParameter
else if (tds.IsBlobType (colType))
tds.Comm.Append (size); // Parameter size passed in SqlParameter
else if (param.IsVariableSizeType)
tds.Comm.Append ((byte)size);
// Precision and Scale are non-zero for only decimal/numeric
if ( param.TypeName == "decimal" || param.TypeName == "numeric") {
tds.Comm.Append ((param.Precision!=0)?param.Precision:(byte)29);
tds.Comm.Append (param.Scale);
}
// Documentation is basically 0 on these 5 bytes. But in a nutshell it seems during a bulk insert
// these are required for text types.
if (param.IsTextType) {
tds.Comm.Append ((byte)0x09);
tds.Comm.Append ((byte)0x04);
tds.Comm.Append ((byte)0xd0);
tds.Comm.Append ((byte)0x00);
tds.Comm.Append ((byte)0x34);
}
}
#endregion
}
}
#endif

View File

@@ -0,0 +1,321 @@
//
// Mono.Data.Tds.Protocol.TdsCollation.cs
//
// Authors:
// Veerapuram Varadhan <vvaradhan@novell.com>
// Dmitry S. Kataev <dmitryskey@hotmail.com>
//
// Charset parts - Copyright (C) 2006,2007 Dmitry S. Kataev
// Copyright (C) Novell Inc, 2009
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections;
using System.Text;
namespace Mono.Data.Tds {
internal static class TdsCollation
{
public static int LCID (byte[] collation)
{
if (collation == null)
return -1;
return (collation[0] | (collation[1] << 8) | ((collation[2] & 0x0F) << 16));
}
public static int CollationFlags (byte[] collation)
{
if (collation == null)
return -1;
return ((collation[2] & 0xF0) | ((collation[3] & 0x0F) << 4));
}
public static int Version (byte[] collation)
{
if (collation == null)
return -1;
return (collation[3] & 0xF0);
}
public static int SortId (byte[] collation)
{
if (collation == null)
return -1;
return (collation[4]);
}
}
internal static class TdsCharset
{
private static Hashtable lcidCodes = new Hashtable();
private static Hashtable sortCodes = new Hashtable();
static TdsCharset ()
{
lcidCodes[0x436] = 1252;
lcidCodes[0x41C] = 1250;
lcidCodes[0x401] = 1256;
lcidCodes[0x801] = 1256;
lcidCodes[0xC01] = 1256;
lcidCodes[0x1001] = 1256;
lcidCodes[0x1401] = 1256;
lcidCodes[0x1801] = 1256;
lcidCodes[0x1C01] = 1256;
lcidCodes[0x2001] = 1256;
lcidCodes[0x2401] = 1256;
lcidCodes[0x2801] = 1256;
lcidCodes[0x2C01] = 1256;
lcidCodes[0x3001] = 1256;
lcidCodes[0x3401] = 1256;
lcidCodes[0x3801] = 1256;
lcidCodes[0x3C01] = 1256;
lcidCodes[0x4001] = 1256;
lcidCodes[0x42D] = 1252;
lcidCodes[0x423] = 1251;
lcidCodes[0x402] = 1251;
lcidCodes[0x403] = 1252;
lcidCodes[0x30404] = 950;
lcidCodes[0x404] = 950;
lcidCodes[0x804] = 936;
lcidCodes[0x20804] = 936;
lcidCodes[0x1004] = 936;
lcidCodes[0x41a] = 1250;
lcidCodes[0x405] = 1250;
lcidCodes[0x406] = 1252;
lcidCodes[0x413] = 1252;
lcidCodes[0x813] = 1252;
lcidCodes[0x409] = 1252;
lcidCodes[0x809] = 1252;
lcidCodes[0x1009] = 1252;
lcidCodes[0x1409] = 1252;
lcidCodes[0xC09] = 1252;
lcidCodes[0x1809] = 1252;
lcidCodes[0x1C09] = 1252;
lcidCodes[0x2409] = 1252;
lcidCodes[0x2009] = 1252;
lcidCodes[0x425] = 1257;
lcidCodes[0x0438] = 1252;
lcidCodes[0x429] = 1256;
lcidCodes[0x40B] = 1252;
lcidCodes[0x40C] = 1252;
lcidCodes[0x80C] = 1252;
lcidCodes[0x100C] = 1252;
lcidCodes[0xC0C] = 1252;
lcidCodes[0x140C] = 1252;
lcidCodes[0x10437] = 1252;
lcidCodes[0x10407] = 1252;
lcidCodes[0x407] = 1252;
lcidCodes[0x807] = 1252;
lcidCodes[0xC07] = 1252;
lcidCodes[0x1007] = 1252;
lcidCodes[0x1407] = 1252;
lcidCodes[0x408] = 1253;
lcidCodes[0x40D] = 1255;
lcidCodes[0x439] = 65001;
lcidCodes[0x40E] = 1250;
lcidCodes[0x104E] = 1250;
lcidCodes[0x40F] = 1252;
lcidCodes[0x421] = 1252;
lcidCodes[0x410] = 1252;
lcidCodes[0x810] = 1252;
lcidCodes[0x411] = 932;
lcidCodes[0x10411] = 932;
lcidCodes[0x412] = 949;
lcidCodes[0x412] = 949;
lcidCodes[0x426] = 1257;
lcidCodes[0x427] = 1257;
lcidCodes[0x827] = 1257;
lcidCodes[0x41C] = 1251;
lcidCodes[0x414] = 1252;
lcidCodes[0x814] = 1252;
lcidCodes[0x415] = 1250;
lcidCodes[0x816] = 1252;
lcidCodes[0x416] = 1252;
lcidCodes[0x418] = 1250;
lcidCodes[0x419] = 1251;
lcidCodes[0x81A] = 1251;
lcidCodes[0xC1A] = 1251;
lcidCodes[0x41B] = 1250;
lcidCodes[0x424] = 1250;
lcidCodes[0x80A] = 1252;
lcidCodes[0x40A] = 1252;
lcidCodes[0xC0A] = 1252;
lcidCodes[0x100A] = 1252;
lcidCodes[0x140A] = 1252;
lcidCodes[0x180A] = 1252;
lcidCodes[0x1C0A] = 1252;
lcidCodes[0x200A] = 1252;
lcidCodes[0x240A] = 1252;
lcidCodes[0x280A] = 1252;
lcidCodes[0x2C0A] = 1252;
lcidCodes[0x300A] = 1252;
lcidCodes[0x340A] = 1252;
lcidCodes[0x380A] = 1252;
lcidCodes[0x3C0A] = 1252;
lcidCodes[0x400A] = 1252;
lcidCodes[0x41D] = 1252;
lcidCodes[0x41E] = 874;
lcidCodes[0x41F] = 1254;
lcidCodes[0x422] = 1251;
lcidCodes[0x420] = 1256;
lcidCodes[0x42A] = 1258;
sortCodes[30] = 437;
sortCodes[31] = 437;
sortCodes[32] = 437;
sortCodes[33] = 437;
sortCodes[34] = 437;
sortCodes[40] = 850;
sortCodes[41] = 850;
sortCodes[42] = 850;
sortCodes[43] = 850;
sortCodes[44] = 850;
sortCodes[49] = 850;
sortCodes[50] = 1252;
sortCodes[51] = 1252;
sortCodes[52] = 1252;
sortCodes[53] = 1252;
sortCodes[54] = 1252;
sortCodes[55] = 850;
sortCodes[56] = 850;
sortCodes[57] = 850;
sortCodes[58] = 850;
sortCodes[59] = 850;
sortCodes[60] = 850;
sortCodes[61] = 850;
sortCodes[71] = 1252;
sortCodes[72] = 1252;
sortCodes[73] = 1252;
sortCodes[74] = 1252;
sortCodes[75] = 1252;
sortCodes[80] = 1250;
sortCodes[81] = 1250;
sortCodes[82] = 1250;
sortCodes[83] = 1250;
sortCodes[84] = 1250;
sortCodes[85] = 1250;
sortCodes[86] = 1250;
sortCodes[87] = 1250;
sortCodes[88] = 1250;
sortCodes[89] = 1250;
sortCodes[90] = 1250;
sortCodes[91] = 1250;
sortCodes[92] = 1250;
sortCodes[93] = 1250;
sortCodes[94] = 1250;
sortCodes[95] = 1250;
sortCodes[96] = 1250;
sortCodes[97] = 1250;
sortCodes[98] = 1250;
sortCodes[104] = 1251;
sortCodes[105] = 1251;
sortCodes[106] = 1251;
sortCodes[107] = 1251;
sortCodes[108] = 1251;
sortCodes[112] = 1253;
sortCodes[113] = 1253;
sortCodes[114] = 1253;
sortCodes[120] = 1253;
sortCodes[121] = 1253;
sortCodes[124] = 1253;
sortCodes[128] = 1254;
sortCodes[129] = 1254;
sortCodes[130] = 1254;
sortCodes[136] = 1255;
sortCodes[137] = 1255;
sortCodes[138] = 1255;
sortCodes[144] = 1256;
sortCodes[145] = 1256;
sortCodes[146] = 1256;
sortCodes[152] = 1257;
sortCodes[153] = 1257;
sortCodes[154] = 1257;
sortCodes[155] = 1257;
sortCodes[156] = 1257;
sortCodes[157] = 1257;
sortCodes[158] = 1257;
sortCodes[159] = 1257;
sortCodes[160] = 1257;
sortCodes[183] = 1252;
sortCodes[184] = 1252;
sortCodes[185] = 1252;
sortCodes[186] = 1252;
sortCodes[192] = 932;
sortCodes[193] = 932;
sortCodes[194] = 949;
sortCodes[195] = 949;
sortCodes[196] = 950;
sortCodes[197] = 950;
sortCodes[198] = 936;
sortCodes[199] = 936;
sortCodes[200] = 932;
sortCodes[201] = 949;
sortCodes[202] = 950;
sortCodes[203] = 936;
sortCodes[204] = 874;
sortCodes[205] = 874;
sortCodes[206] = 874;
}
public static Encoding GetEncoding (byte[] collation)
{
if (TdsCollation.SortId (collation) != 0)
return GetEncodingFromSortOrder (collation);
else
return GetEncodingFromLCID (collation);
}
public static Encoding GetEncodingFromLCID (byte[] collation)
{
int lcid = TdsCollation.LCID (collation);
return GetEncodingFromLCID (lcid);
}
public static Encoding GetEncodingFromLCID (int lcid)
{
if (lcidCodes[lcid] != null)
return Encoding.GetEncoding ((int)lcidCodes[lcid]);
else
return null;
}
public static Encoding GetEncodingFromSortOrder(byte[] collation)
{
int sortId = TdsCollation.SortId (collation);
return GetEncodingFromSortOrder (sortId);
}
public static Encoding GetEncodingFromSortOrder (int sortId)
{
if (sortCodes[sortId] != null)
return Encoding.GetEncoding ((int)sortCodes[sortId]);
else
return null;
}
}
}

View File

@@ -0,0 +1,38 @@
//
// Mono.Data.Tds.Protocol.TdsColumnStatus.cs
//
// Author:
// Tim Coleman (tim@timcoleman.com)
//
// Copyright (C) Tim Coleman, 2002
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Data.Tds.Protocol {
public enum TdsColumnStatus {
IsExpression = 0x04,
IsKey = 0x08,
Hidden = 0x10,
Rename = 0x20
}
}

View File

@@ -0,0 +1,70 @@
//
// Mono.Data.Tds.Protocol.TdsColumnType.cs
//
// Author:
// Tim Coleman (tim@timcoleman.com)
//
// Copyright (C) Tim Coleman, 2002
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Mono.Data.Tds.Protocol {
public enum TdsColumnType {
Binary = 0x2d, // SYBBINARY
Bit = 0x32, // SYBBIT
Char = 0x2f, // SYBCHAR
DateTime = 0x3d, // SYBDATETIME
DateTime4 = 0x3a, // SYBDATETIME4
DateTimeN = 0x6f, // SYBDATETIMN
Decimal = 0x6a, // SYBDECIMAL
Real = 0x3b, // SYBREAL
Float8 = 0x3e, // SYBFLT8
FloatN = 0x6d, // SYBFLTN
Image = 0x22, // SYBIMAGE
Int1 = 0x30, // SYBINT1
Int2 = 0x34, // SYBINT2
Int4 = 0x38, // SYBINT4
IntN = 0x26, // SYBINTN
Void = 0x1f, // SYBVOID
Text = 0x23, // SYBTEXT
UniqueIdentifier = 0x24,// SYBUNIQUE
VarBinary = 0x25, // SYBVARBINARY
VarChar = 0x27, // SYBVARCHAR
Money = 0x3c, // SYBMONEY
NText = 0x63, // SYBNTEXT
NVarChar = 0x67, // SYBNVARCHAR
BitN = 0x68, // SYBBITN
Numeric = 0x6c, // SYBNUMERIC
MoneyN = 0x6e, // SYBMONEYN
Money4 = 0x70,
NChar = 0xef, // XSYBNCHAR
BigBinary = 0xad, // XSYBBINARY
BigVarBinary = 0xa5, // XSYBVARBINARY
BigVarChar = 0xa7, // XSYBVARCHAR
BigNVarChar = 0xe7, // XSYBNVARCHAR
BigChar = 0xaf, // XSYBCHAR
SmallMoney = 0x7a, // SYBMONEY4
Variant = 0x62, // SYBVARIANT
BigInt = 0x7F // SYBINT8
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,73 @@
//
// Mono.Data.Tds.Protocol.TdsConnectionParameters.cs
//
// Author:
// Tim Coleman (tim@timcoleman.com)
// Daniel Morgan (danielmorgan@verizon.net)
//
// Copyright (C) 2002 Tim Coleman
// Portions (C) 2003 Daniel Morgan
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
namespace Mono.Data.Tds.Protocol
{
public class TdsConnectionParameters
{
public string ApplicationName;
public string Database;
public string Charset;
public string Hostname;
public string Language;
public string LibraryName;
public string Password;
public string ProgName;
public string User;
public bool DomainLogin;
public string DefaultDomain;
public string AttachDBFileName;
public TdsConnectionParameters ()
{
Reset ();
}
public void Reset ()
{
ApplicationName = "Mono";
Database = String.Empty;
Charset = String.Empty;
Hostname = System.Net.Dns.GetHostName();
Language = String.Empty;
LibraryName = "Mono";
Password = String.Empty;
ProgName = "Mono";
User = String.Empty;
DomainLogin = false;
DefaultDomain = String.Empty;
AttachDBFileName = String.Empty;
}
}
}

View File

@@ -0,0 +1,291 @@
//
// Mono.Data.TdsClient.TdsConnectionPool.cs
//
// Author:
// Lluis Sanchez Gual (lluis@ximian.com)
// Christian Hergert (christian.hergert@gmail.com)
// Gonzalo Paniagua Javier (gonzalo@novell.com)
//
// Copyright (C) 2004 Novell, Inc.
// Copyright (C) 2009 Novell, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections;
using System.Text;
using System.Threading;
namespace Mono.Data.Tds.Protocol
{
public class TdsConnectionPoolManager
{
Hashtable pools = Hashtable.Synchronized (new Hashtable ());
TdsVersion version;
public TdsConnectionPoolManager (TdsVersion version)
{
this.version = version;
}
public TdsConnectionPool GetConnectionPool (string connectionString, TdsConnectionInfo info)
{
TdsConnectionPool pool = (TdsConnectionPool) pools [connectionString];
if (pool == null) {
pools [connectionString] = new TdsConnectionPool (this, info);
pool = (TdsConnectionPool) pools [connectionString];
}
return pool;
}
public TdsConnectionPool GetConnectionPool (string connectionString)
{
return (TdsConnectionPool) pools [connectionString];
}
public virtual Tds CreateConnection (TdsConnectionInfo info)
{
//Console.WriteLine ("CreateConnection: TdsVersion:{0}", version);
switch (version)
{
case TdsVersion.tds42:
return new Tds42 (info.DataSource, info.Port, info.PacketSize, info.Timeout);
case TdsVersion.tds50:
return new Tds50 (info.DataSource, info.Port, info.PacketSize, info.Timeout);
case TdsVersion.tds70:
return new Tds70 (info.DataSource, info.Port, info.PacketSize, info.Timeout, info.LifeTime);
case TdsVersion.tds80:
return new Tds80 (info.DataSource, info.Port, info.PacketSize, info.Timeout, info.LifeTime);
}
throw new NotSupportedException ();
}
public IDictionary GetConnectionPool ()
{
return pools;
}
}
public class TdsConnectionInfo
{
[Obsolete ("Use the constructor that receives a lifetime parameter")]
public TdsConnectionInfo (string dataSource, int port, int packetSize, int timeout, int minSize, int maxSize)
: this (dataSource, port, packetSize, timeout, minSize, maxSize, 0)
{
}
public TdsConnectionInfo (string dataSource, int port, int packetSize, int timeout, int minSize, int maxSize, int lifeTime)
{
DataSource = dataSource;
Port = port;
PacketSize = packetSize;
Timeout = timeout;
PoolMinSize = minSize;
PoolMaxSize = maxSize;
LifeTime = lifeTime;
}
public string DataSource;
public int Port;
public int PacketSize;
public int Timeout;
public int LifeTime;
public int PoolMinSize;
public int PoolMaxSize;
public override string ToString ()
{
StringBuilder sb = new StringBuilder ();
sb.AppendFormat ("DataSouce: {0}\n", DataSource);
sb.AppendFormat ("Port: {0}\n", Port);
sb.AppendFormat ("PacketSize: {0}\n", PacketSize);
sb.AppendFormat ("Timeout: {0}\n", Timeout);
sb.AppendFormat ("PoolMinSize: {0}\n", PoolMinSize);
sb.AppendFormat ("PoolMaxSize: {0}", PoolMaxSize);
return sb.ToString ();
}
}
public class TdsConnectionPool
{
TdsConnectionInfo info;
bool no_pooling;
TdsConnectionPoolManager manager;
Queue available;
ArrayList conns;
public TdsConnectionPool (TdsConnectionPoolManager manager, TdsConnectionInfo info)
{
this.info = info;
this.manager = manager;
conns = new ArrayList (info.PoolMaxSize);
available = new Queue (info.PoolMaxSize);
InitializePool ();
}
void InitializePool ()
{
/* conns.Count might not be 0 when we are resetting the connection pool */
for (int i = conns.Count; i < info.PoolMinSize; i++) {
try {
Tds t = manager.CreateConnection (info);
conns.Add (t);
available.Enqueue (t);
} catch {
// Ignore. GetConnection will throw again.
}
}
}
public bool Pooling {
get { return !no_pooling; }
set { no_pooling = !value; }
}
#region Methods
int in_progress;
public Tds GetConnection ()
{
if (no_pooling)
return manager.CreateConnection (info);
Tds result = null;
bool create_new;
int retries = info.PoolMaxSize * 2;
retry:
while (result == null) {
create_new = false;
lock (available) {
if (available.Count > 0) {
result = (Tds) available.Dequeue ();
break; // .. and do the reset out of the loop
}
Monitor.Enter (conns);
try {
if (conns.Count >= info.PoolMaxSize - in_progress) {
Monitor.Exit (conns);
bool got_lock = Monitor.Wait (available, info.Timeout * 1000);
if (!got_lock) {
throw new InvalidOperationException (
"Timeout expired. The timeout period elapsed before a " +
"connection could be obtained. A possible explanation " +
"is that all the connections in the pool are in use, " +
"and the maximum pool size is reached.");
} else if (available.Count > 0) {
result = (Tds) available.Dequeue ();
break; // .. and do the reset out of the loop
}
continue;
} else {
create_new = true;
in_progress++;
}
} finally {
Monitor.Exit (conns); // Exiting if not owned is ok < 2.x
}
}
if (create_new) {
try {
result = manager.CreateConnection (info);
lock (conns)
conns.Add (result);
return result;
} finally {
lock (available)
in_progress--;
}
}
}
bool remove_cnc = true;
Exception exc = null;
try {
remove_cnc = (!result.IsConnected || !result.Reset ());
} catch (Exception e) {
remove_cnc = true;
exc = e;
}
if (remove_cnc) {
lock (conns)
conns.Remove (result);
result.Disconnect ();
retries--;
if (retries == 0)
throw exc;
result = null;
goto retry;
}
return result;
}
public void ReleaseConnection (Tds connection)
{
if (connection == null)
return;
if (no_pooling) {
connection.Disconnect ();
return;
}
if (connection.poolStatus == 2 || connection.Expired) {
lock (conns)
conns.Remove (connection);
connection.Disconnect ();
connection = null;
}
lock (available) {
if (connection != null) // connection is still open
available.Enqueue (connection);
// We pulse even if we don't queue, because null means that there's a slot
// available in 'conns'
Monitor.Pulse (available);
}
}
#if NET_2_0
public void ResetConnectionPool ()
{
lock (available) {
lock (conns) {
Tds tds;
int i;
for (i = conns.Count - 1; i >= 0; i--) {
tds = (Tds) conns [i];
tds.poolStatus = 2; // 2 -> disconnect me upon release
}
for (i = available.Count - 1; i >= 0; i--) {
tds = (Tds) available.Dequeue ();
tds.Disconnect ();
conns.Remove (tds);
}
available.Clear ();
InitializePool ();
}
Monitor.PulseAll (available);
}
}
#endif
#endregion // Methods
}
}

Some files were not shown because too many files have changed in this diff Show More