using Mono.Data.Tds;
using System;
using System.Text;
+using System.Security;
-namespace Mono.Data.Tds.Protocol {
+namespace Mono.Data.Tds.Protocol
+{
[MonoTODO ("FIXME: Can packetsize be anything other than 512?")]
- public class Tds50 : Tds
+ public sealed class Tds50 : Tds
{
#region Fields
public static readonly TdsVersion Version = TdsVersion.tds50;
int packetSize;
- bool isSelectQuery = false;
+ bool isSelectQuery;
#endregion // Fields
StringBuilder set = new StringBuilder ();
StringBuilder declare = new StringBuilder ();
int count = 0;
- foreach (TdsMetaParameter p in Parameters) {
+ foreach (TdsMetaParameter p in Parameters) {
declare.Append (String.Format ("declare {0}\n", p.Prepare ()));
set.Append (String.Format ("select {0}=", p.ParameterName));
if (p.Direction == TdsParameterDirection.Input)
// password (offset 62 0x3e)
// 62-92
- tmp = Comm.Append (connectionParameters.Password, 30, pad);
+ tmp = Comm.Append (GetPlainPassword(connectionParameters.Password), 30, pad);
Comm.Append ((byte) (tmp.Length < 30 ? tmp.Length : 30));
// hostproc (offset 93 0x5d)
// remote passwords
// 202-457
Comm.Append (empty, 2, pad);
- tmp = Comm.Append (connectionParameters.Password, 253, pad);
+ tmp = Comm.Append (GetPlainPassword(connectionParameters.Password), 253, pad);
Comm.Append ((byte) (tmp.Length < 253 ? tmp.Length + 2 : 253 + 2));
// tds version
// length of tds packets
// 557-563
- tmp = Comm.Append (PacketSize.ToString (), 6, pad);
+ tmp = Comm.Append (this.packetSize.ToString (), 6, pad);
Comm.Append ((byte) (tmp.Length < 6 ? tmp.Length : 6));
Comm.Append (empty, 8, pad);
public override void Execute (string sql, TdsMetaParameterCollection parameters, int timeout, bool wantResults)
{
Parameters = parameters;
- string ex = BuildExec (sql);
+ string ex = BuildExec (sql);
ExecuteQuery (ex, timeout, wantResults);
}
Parameters = parameters;
ExecuteQuery (BuildProcedureCall (commandText), timeout, wantResults);
}
-
- private string BuildProcedureCall (string procedure)
+
+ private string BuildProcedureCall (string procedure)
{
string exec = String.Empty;
count += 1;
}
- if (p.Direction == TdsParameterDirection.ReturnValue) {
+ if (p.Direction == TdsParameterDirection.ReturnValue)
exec = p.ParameterName + "=";
- }
}
}
- exec = "exec " + exec;
-
- string sql = String.Format ("{0}{1}{2}{3} {4}\n{5}", declare.ToString (),
- set.ToString (),
- exec, procedure,
- BuildParameters (), select.ToString ());
+ exec = "exec " + exec;
+
+ string sql = String.Format ("{0}{1}{2}{3} {4}\n{5}", declare.ToString (),
+ set.ToString (),
+ exec, procedure,
+ BuildParameters (), select.ToString ());
return sql;
}
-
private string BuildParameters ()
{
if (Parameters == null || Parameters.Count == 0)
case "image":
case "binary":
case "varbinary":
- return String.Format ("0x{0}", BitConverter.ToString ((byte[]) parameter.Value).Replace ("-", "").ToLower ());
+ return String.Format ("0x{0}", BitConverter.ToString ((byte[]) parameter.Value).Replace ("-", string.Empty).ToLower ());
default:
return String.Format ("'{0}'", parameter.Value.ToString ().Replace ("'", "''"));
}
idBuilder.Append ((char) (rand.Next (26) + 65));
string id = idBuilder.ToString ();
- StringBuilder declare = new StringBuilder ();
+ //StringBuilder declare = new StringBuilder ();
sql = String.Format ("create proc {0} as\n{1}", id, sql);
return id;
}
- protected override TdsDataColumnCollection ProcessColumnInfo ()
+ protected override void ProcessColumnInfo ()
{
isSelectQuery = true;
- TdsDataColumnCollection result = new TdsDataColumnCollection ();
- int totalLength = Comm.GetTdsShort ();
+ /*int totalLength = */Comm.GetTdsShort ();
int count = Comm.GetTdsShort ();
for (int i = 0; i < count; i += 1) {
string columnName = Comm.GetString (Comm.GetByte ());
if (isBlob)
Comm.Skip (Comm.GetTdsShort ()); // Class ID
- int index = result.Add (new TdsDataColumn ());
- 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;
+ TdsDataColumn col = new TdsDataColumn ();
+ Columns.Add (col);
+#if NET_2_0
+ col.ColumnType = columnType;
+ col.ColumnName = columnName;
+ col.IsIdentity = isIdentity;
+ col.IsRowVersion = isRowVersion;
+ col.ColumnType = columnType;
+ col.ColumnSize = bufLength;
+ col.NumericPrecision = precision;
+ col.NumericScale = scale;
+ col.IsReadOnly = !isUpdatable;
+ col.IsKey = isKey;
+ col.AllowDBNull = allowDBNull;
+ col.IsHidden = hidden;
+#else
+ col ["ColumnType"] = columnType;
+ col ["ColumnName"] = columnName;
+ col ["IsIdentity"] = isIdentity;
+ col ["IsRowVersion"] = isRowVersion;
+ col ["ColumnType"] = columnType;
+ col ["ColumnSize"] = bufLength;
+ col ["NumericPrecision"] = precision;
+ col ["NumericScale"] = scale;
+ col ["IsReadOnly"] = !isUpdatable;
+ col ["IsKey"] = isKey;
+ col ["AllowDBNull"] = allowDBNull;
+ col ["IsHidden"] = hidden;
+#endif
}
- return result;
}
private void SendParamFormat ()
Comm.Append ((byte) parameterName.Length);
Comm.Append (parameterName);
- Comm.Append (status);
+ Comm.Append (status);
Comm.Append (userType);
- Comm.Append ((byte) metaType);
+ Comm.Append ((byte) metaType);
if (!IsFixedSizeColumn (metaType))
Comm.Append ((byte) p.Size); // MAXIMUM SIZE
protected override bool IsValidRowCount (byte status, byte op)
{
- if (isSelectQuery)
+ if (isSelectQuery)
return (isSelectQuery = false);
// TODO : Need to figure out how to calculate rowcount inside stored
// statements executing inside a StoredProcedure
if (((status & (byte)0x40) != 0) || ((status & (byte)0x10) == 0))
- return false ;
+ return false;
return true;
}