Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/Tds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,31 @@ private object GetColumnValue (
}

switch (colType) {
case TdsColumnType.Variant:
/* sql variant max size */
Comm.GetTdsInt ();
byte type = Comm.GetByte ();
byte propbyte = Comm.GetByte ();
TdsColumnType realType = (TdsColumnType)(type & 0xff);
if (realType == TdsColumnType.NVarChar ||
realType == TdsColumnType.BigNVarChar ||
realType == TdsColumnType.VarChar ||
realType == TdsColumnType.BigVarChar) {
byte[] collation = null;
collation = Comm.GetBytes (5, true);
lcid = TdsCollation.LCID (collation);
sortId = TdsCollation.SortId (collation);
#if NET_2_0
columns[ordinal].LCID = lcid;
columns[ordinal].SortOrder = sortId;
#else
columns[ordinal]["LCID"] = lcid;
columns[ordinal]["SortOrder"] = sortId;
#endif

}
element = GetColumnValue ((TdsColumnType)type, outParam, ordinal);
break;
case TdsColumnType.IntN :
if (outParam)
comm.Skip (1);
Expand Down Expand Up @@ -1248,7 +1273,7 @@ private object GetMoneyValue (
return DBNull.Value;
}
}

protected object GetStringValue (
TdsColumnType? colType,
bool wideChars, bool outputParam, Encoding encoder)
Expand Down
74 changes: 39 additions & 35 deletions mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/Tds80.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,24 +94,34 @@ protected override void ProcessColumnInfo ()
base.ProcessColumnInfo ();
return;
}

// VARADHAN: TDS 8 Debugging
//Console.WriteLine ("Tds80.cs: In ProcessColumnInfo... entry");
int numColumns = Comm.GetTdsShort ();

int columnSize = 0;
string tableName = null;
byte[] collation = null;
int lcid = 0, sortId = 0;

byte precision = 0;
byte scale = 0;

//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 ();
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
byte nextbyte = Comm.GetByte();
string columnName = "";

TdsColumnType columnType = (TdsColumnType) (nextbyte & 0xff);
//Console.WriteLine ("Actual ColumnType: {0}", columnType); // TDS 8 Debugging

if ((byte) columnType == 0xef)
columnType = TdsColumnType.NChar;
Expand All @@ -121,39 +131,33 @@ protected override void ProcessColumnInfo ()
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;
} else if (columnType == TdsColumnType.Variant) {
columnSize = Comm.GetTdsInt ();
} 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
}

switch (columnType) {
case TdsColumnType.NText:
Expand All @@ -171,7 +175,7 @@ protected override void ProcessColumnInfo ()
break;
}

string columnName = Comm.GetString (Comm.GetByte ());
columnName = Comm.GetString (Comm.GetByte ());

TdsDataColumn col = new TdsDataColumn ();
Columns.Add (col);
Expand Down
11 changes: 11 additions & 0 deletions mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/TdsComm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,17 @@ public bool IsConnected ()
{
return socket != null && socket.Connected && !(socket.Poll (0, SelectMode.SelectRead) && socket.Available == 0);
}

/* this two methods need to read sql variant type from database */
public int GetInBufferIndex()
{
return inBufferIndex;
}

public void SetInBufferIndex(int index)
{
inBufferIndex = index;
}

public byte GetByte ()
{
Expand Down