2 // Mono.Data.Tds.Protocol.Tds70.cs
5 // Tim Coleman (tim@timcoleman.com)
6 // Diego Caravana (diego@toth.it)
7 // Sebastien Pouliot (sebastien@ximian.com)
8 // Daniel Morgan (danielmorgan@verizon.net)
9 // Gert Driesen (drieseng@users.sourceforge.net)
10 // Veerapuram Varadhan (vvaradhan@novell.com)
12 // Copyright (C) 2002 Tim Coleman
13 // Portions (C) 2003 Motus Technologies Inc. (http://www.motus.com)
14 // Portions (C) 2003 Daniel Morgan
17 // Permission is hereby granted, free of charge, to any person obtaining
18 // a copy of this software and associated documentation files (the
19 // "Software"), to deal in the Software without restriction, including
20 // without limitation the rights to use, copy, modify, merge, publish,
21 // distribute, sublicense, and/or sell copies of the Software, and to
22 // permit persons to whom the Software is furnished to do so, subject to
23 // the following conditions:
25 // The above copyright notice and this permission notice shall be
26 // included in all copies or substantial portions of the Software.
28 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
32 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
33 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
34 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
38 using System.Globalization;
41 using Mono.Security.Protocol.Ntlm;
43 namespace Mono.Data.Tds.Protocol
45 public class Tds70 : Tds
49 //public readonly static TdsVersion Version = TdsVersion.tds70;
50 static readonly decimal SMALLMONEY_MIN = -214748.3648m;
51 static readonly decimal SMALLMONEY_MAX = 214748.3647m;
57 public Tds70 (string server, int port)
58 : this (server, port, 512, 15)
62 public Tds70 (string server, int port, int packetSize, int timeout)
63 : base (server, port, packetSize, timeout, TdsVersion.tds70)
67 public Tds70 (string server, int port, int packetSize, int timeout, TdsVersion version)
68 : base (server, port, packetSize, timeout, version)
72 #endregion // Constructors
76 protected virtual byte[] ClientVersion {
77 get { return new byte[] {0x00, 0x0, 0x0, 0x70};}
79 #endregion // Properties
83 private string BuildExec (string sql)
85 string esql = sql.Replace ("'", "''"); // escape single quote
86 if (Parameters != null && Parameters.Count > 0)
87 return BuildProcedureCall (String.Format ("sp_executesql N'{0}', N'{1}', ", esql, BuildPreparedParameters ()));
89 return BuildProcedureCall (String.Format ("sp_executesql N'{0}'", esql));
92 private string BuildParameters ()
94 if (Parameters == null || Parameters.Count == 0)
97 StringBuilder result = new StringBuilder ();
98 foreach (TdsMetaParameter p in Parameters) {
99 string parameterName = p.ParameterName;
100 if (parameterName [0] == '@') {
101 parameterName = parameterName.Substring (1);
103 if (p.Direction != TdsParameterDirection.ReturnValue) {
104 if (result.Length > 0)
105 result.Append (", ");
106 if (p.Direction == TdsParameterDirection.InputOutput)
107 result.AppendFormat ("@{0}={0} output", parameterName);
109 result.Append (FormatParameter (p));
112 return result.ToString ();
115 private string BuildPreparedParameters ()
117 StringBuilder parms = new StringBuilder ();
118 foreach (TdsMetaParameter p in Parameters) {
119 if (parms.Length > 0)
121 parms.Append (p.Prepare ());
122 if (p.Direction == TdsParameterDirection.Output)
123 parms.Append (" output");
125 return parms.ToString ();
128 private string BuildPreparedQuery (string id)
130 return BuildProcedureCall (String.Format ("sp_execute {0},", id));
133 private string BuildProcedureCall (string procedure)
135 string exec = String.Empty;
137 StringBuilder declare = new StringBuilder ();
138 StringBuilder select = new StringBuilder ();
139 StringBuilder set = new StringBuilder ();
142 if (Parameters != null) {
143 foreach (TdsMetaParameter p in Parameters) {
144 string parameterName = p.ParameterName;
145 if (parameterName [0] == '@') {
146 parameterName = parameterName.Substring (1);
149 if (p.Direction != TdsParameterDirection.Input) {
151 select.Append ("select ");
153 select.Append (", ");
154 select.Append ("@" + parameterName);
156 declare.Append (String.Format ("declare {0}\n", p.Prepare ()));
158 if (p.Direction != TdsParameterDirection.ReturnValue) {
159 if (p.Direction == TdsParameterDirection.InputOutput)
160 set.Append (String.Format ("set {0}\n", FormatParameter(p)));
162 set.Append (String.Format ("set @{0}=NULL\n", parameterName));
167 if (p.Direction == TdsParameterDirection.ReturnValue)
168 exec = "@" + parameterName + "=";
171 exec = "exec " + exec;
173 return String.Format ("{0}{1}{2}{3} {4}\n{5}",
174 declare.ToString (), set.ToString (), exec,
175 procedure, BuildParameters (), select.ToString ());
178 public override bool Connect (TdsConnectionParameters connectionParameters)
181 throw new InvalidOperationException ("The connection is already open.");
183 connectionParms = connectionParameters;
185 SetLanguage (connectionParameters.Language);
186 SetCharset ("utf-8");
188 byte[] empty = new byte[0];
192 byte[] domainMagic = { 6, 0x7d, 0x0f, 0xfd, 0xff, 0x0, 0x0, 0x0,
193 0x0, 0xe0, 0x83, 0x0, 0x0,
194 0x68, 0x01, 0x00, 0x00, 0x09, 0x04, 0x00, 0x00 };
195 byte[] sqlserverMagic = { 6, 0x0, 0x0, 0x0,
197 0x0, 0xe0, 0x03, 0x0,
198 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
202 if (connectionParameters.DomainLogin)
205 magic = sqlserverMagic;
207 string username = connectionParameters.User;
208 string domain = null;
210 int idx = username.IndexOf ("\\");
212 domain = username.Substring (0, idx);
213 username = username.Substring (idx + 1);
215 connectionParameters.DefaultDomain = domain;
216 connectionParameters.User = username;
218 domain = Environment.UserDomainName;
219 connectionParameters.DefaultDomain = domain;
222 short partialPacketSize = (short) (86 + (
223 connectionParameters.Hostname.Length +
224 connectionParameters.ApplicationName.Length +
226 connectionParameters.LibraryName.Length +
228 connectionParameters.Database.Length +
229 connectionParameters.AttachDBFileName.Length) * 2);
231 if (connectionParameters.DomainLogin) {
232 authLen = ((short) (32 + (connectionParameters.Hostname.Length +
234 partialPacketSize += authLen;
236 partialPacketSize += ((short) ((username.Length + connectionParameters.Password.Length) * 2));
238 int totalPacketSize = partialPacketSize;
240 Comm.StartPacket (TdsPacketType.Logon70);
242 Comm.Append (totalPacketSize);
244 //Comm.Append (empty, 3, pad);
245 //byte[] version = {0x00, 0x0, 0x0, 0x71};
246 Comm.Append (ClientVersion); // TDS Version 7
247 Comm.Append ((int)this.PacketSize); // Set the Block Size
248 Comm.Append (empty, 3, pad);
254 Comm.Append (curPos);
255 Comm.Append ((short) connectionParameters.Hostname.Length);
256 curPos += (short) (connectionParameters.Hostname.Length * 2);
258 if (connectionParameters.DomainLogin) {
259 Comm.Append((short)0);
260 Comm.Append((short)0);
261 Comm.Append((short)0);
262 Comm.Append((short)0);
265 Comm.Append (curPos);
266 Comm.Append ((short) username.Length);
267 curPos += ((short) (username.Length * 2));
270 Comm.Append (curPos);
271 Comm.Append ((short) connectionParameters.Password.Length);
272 curPos += (short) (connectionParameters.Password.Length * 2);
276 Comm.Append (curPos);
277 Comm.Append ((short) connectionParameters.ApplicationName.Length);
278 curPos += (short) (connectionParameters.ApplicationName.Length * 2);
281 Comm.Append (curPos);
282 Comm.Append ((short) DataSource.Length);
283 curPos += (short) (DataSource.Length * 2);
286 Comm.Append ((short) curPos);
287 Comm.Append ((short) 0);
290 Comm.Append (curPos);
291 Comm.Append ((short) connectionParameters.LibraryName.Length);
292 curPos += (short) (connectionParameters.LibraryName.Length * 2);
295 Comm.Append (curPos);
296 Comm.Append ((short) Language.Length);
297 curPos += (short) (Language.Length * 2);
300 Comm.Append (curPos);
301 Comm.Append ((short) connectionParameters.Database.Length);
302 curPos += (short) (connectionParameters.Database.Length * 2);
305 Comm.Append((byte) 0);
306 Comm.Append((byte) 0);
307 Comm.Append((byte) 0);
308 Comm.Append((byte) 0);
309 Comm.Append((byte) 0);
310 Comm.Append((byte) 0);
312 // Authentication Stuff
313 Comm.Append ((short) curPos);
314 if (connectionParameters.DomainLogin) {
315 Comm.Append ((short) authLen);
316 curPos += (short) authLen;
318 Comm.Append ((short) 0);
321 Comm.Append (curPos);
322 Comm.Append ((short)( connectionParameters.AttachDBFileName.Length));
323 curPos += (short)(connectionParameters.AttachDBFileName.Length*2);
325 // Connection Parameters
326 Comm.Append (connectionParameters.Hostname);
327 if (!connectionParameters.DomainLogin) {
328 // SQL Server Authentication
329 Comm.Append (connectionParameters.User);
330 string scrambledPwd = EncryptPassword (connectionParameters.Password);
331 Comm.Append (scrambledPwd);
333 Comm.Append (connectionParameters.ApplicationName);
334 Comm.Append (DataSource);
335 Comm.Append (connectionParameters.LibraryName);
336 Comm.Append (Language);
337 Comm.Append (connectionParameters.Database);
339 if (connectionParameters.DomainLogin) {
340 // the rest of the packet is NTLMSSP authentication
341 Type1Message msg = new Type1Message ();
343 msg.Host = connectionParameters.Hostname;
344 msg.Flags = NtlmFlags.NegotiateUnicode |
345 NtlmFlags.NegotiateNtlm |
346 NtlmFlags.NegotiateDomainSupplied |
347 NtlmFlags.NegotiateWorkstationSupplied |
348 NtlmFlags.NegotiateAlwaysSign; // 0xb201
349 Comm.Append (msg.GetBytes ());
352 Comm.Append (connectionParameters.AttachDBFileName);
360 private static string EncryptPassword (string pass)
362 int xormask = 0x5a5a;
363 int len = pass.Length;
364 char[] chars = new char[len];
366 for (int i = 0; i < len; ++i) {
367 int c = ((int) (pass[i])) ^ xormask;
368 int m1 = (c >> 4) & 0x0f0f;
369 int m2 = (c << 4) & 0xf0f0;
370 chars[i] = (char) (m1 | m2);
373 return new String (chars);
376 public override bool Reset ()
378 // Check validity of the connection - a false removes
379 // the connection from the pool
380 // NOTE: MS implementation will throw a connection-reset error as it will
381 // try to use the same connection
382 if (!Comm.IsConnected ())
385 // Set "reset-connection" bit for the next message packet
386 Comm.ResetConnection = true;
391 public override void ExecPrepared (string commandText, TdsMetaParameterCollection parameters, int timeout, bool wantResults)
393 Parameters = parameters;
394 ExecuteQuery (BuildPreparedQuery (commandText), timeout, wantResults);
397 public override void ExecProc (string commandText, TdsMetaParameterCollection parameters, int timeout, bool wantResults)
399 Parameters = parameters;
400 ExecRPC (commandText, parameters, timeout, wantResults);
403 protected override void ExecRPC (string rpcName, TdsMetaParameterCollection parameters,
404 int timeout, bool wantResults)
408 Comm.StartPacket (TdsPacketType.RPC);
410 Comm.Append ( (short) rpcName.Length);
411 Comm.Append (rpcName);
412 Comm.Append ( (short) 0); //no meta data
413 if (parameters != null) {
414 foreach (TdsMetaParameter param in parameters) {
415 if (param.Direction == TdsParameterDirection.ReturnValue)
417 string pname = param.ParameterName;
418 if (pname != null && pname.Length > 0 && pname [0] == '@') {
419 Comm.Append ( (byte) pname.Length);
422 Comm.Append ( (byte) (pname.Length + 1));
423 Comm.Append ("@" + pname);
425 short status = 0; // unused
426 if (param.Direction != TdsParameterDirection.Input)
427 status |= 0x01; // output
428 Comm.Append ( (byte) status);
429 WriteParameterInfo (param);
433 CheckForData (timeout);
438 private void WriteParameterInfo (TdsMetaParameter param)
441 Ms.net send non-nullable datatypes as nullable and allows setting null values
442 to int/float etc.. So, using Nullable form of type for all data
444 param.IsNullable = true;
445 TdsColumnType colType = param.GetMetaType ();
446 param.IsNullable = false;
448 bool partLenType = false;
449 int size = param.Size;
453 size = param.GetActualSize ();
456 // Change colType according to the following table
458 * Original Type Maxlen New Type
460 * NVarChar 4000 UCS2 NText
461 * BigVarChar 8000 ASCII Text
462 * BigVarBinary 8000 bytes Image
465 TdsColumnType origColType = colType;
466 if (colType == TdsColumnType.BigNVarChar) {
470 colType = TdsColumnType.NText;
472 } else if (colType == TdsColumnType.BigVarChar) {
474 colType = TdsColumnType.Text;
475 } else if (colType == TdsColumnType.BigVarBinary) {
477 colType = TdsColumnType.Image;
479 // Calculation of TypeInfo field
481 * orig size value TypeInfo field
483 * >= 0 <= Maxlen origColType + content len
484 * > Maxlen NewType as per above table + content len
485 * -1 origColType + USHORTMAXLEN (0xFFFF) + content len (TDS 9)
488 // Write updated colType, iff partLenType == false
489 if (TdsVersion > TdsVersion.tds81 && partLenType) {
490 Comm.Append ((byte)origColType);
491 Comm.Append ((short)-1);
493 Comm.Append ((byte)colType);
496 if (IsLargeType (colType))
497 Comm.Append ((short)size); // Parameter size passed in SqlParameter
498 else if (IsBlobType (colType))
499 Comm.Append (size); // Parameter size passed in SqlParameter
501 Comm.Append ((byte)size);
503 // Precision and Scale are non-zero for only decimal/numeric
504 if ( param.TypeName == "decimal" || param.TypeName == "numeric") {
505 Comm.Append ((param.Precision !=0 ) ? param.Precision : (byte) 28);
506 Comm.Append (param.Scale);
510 * VARADHAN: TDS 8 Debugging *
511 if (Collation != null) {
512 Console.WriteLine ("Collation is not null");
513 Console.WriteLine ("Column Type: {0}", colType);
514 Console.WriteLine ("Collation bytes: {0} {1} {2} {3} {4}", Collation[0], Collation[1], Collation[2],
515 Collation[3], Collation[4]);
519 // Tds > 7.0 uses collation
520 if (Collation != null &&
521 (colType == TdsColumnType.BigChar || colType == TdsColumnType.BigNVarChar ||
522 colType == TdsColumnType.BigVarChar || colType == TdsColumnType.NChar ||
523 colType == TdsColumnType.NVarChar || colType == TdsColumnType.Text ||
524 colType == TdsColumnType.NText))
525 Comm.Append (Collation);
527 size = param.GetActualSize ();
528 if (IsLargeType (colType))
529 Comm.Append ((short)size);
530 else if (IsBlobType (colType))
533 Comm.Append ((byte)size);
536 switch (param.TypeName) {
538 Decimal val = (decimal) param.Value;
539 int[] arr = Decimal.GetBits (val);
542 Comm.Append (arr[1]);
543 Comm.Append (arr[0]);
545 Comm.Append (~arr[1]);
546 Comm.Append (~arr[0] + 1);
551 Decimal val = (decimal) param.Value;
552 if (val < SMALLMONEY_MIN || val > SMALLMONEY_MAX)
553 throw new OverflowException (string.Format (
554 CultureInfo.InvariantCulture,
555 "Value '{0}' is not valid for SmallMoney."
556 + " Must be between {1:N4} and {2:N4}.",
560 val.ToString (CultureInfo.CurrentCulture),
562 SMALLMONEY_MIN, SMALLMONEY_MAX));
564 int[] arr = Decimal.GetBits (val);
565 int sign = (val>0 ? 1: -1);
566 Comm.Append (sign * arr[0]);
570 Comm.Append ((DateTime)param.Value, 8);
572 case "smalldatetime":
573 Comm.Append ((DateTime)param.Value, 4);
581 byte [] tmp = param.GetBytes ();
584 case "uniqueidentifier" :
585 Comm.Append (((Guid)param.Value).ToByteArray());
588 Comm.Append (param.Value);
595 public override void Execute (string commandText, TdsMetaParameterCollection parameters, int timeout, bool wantResults)
597 Parameters = parameters;
598 string sql = commandText;
599 if (wantResults || (Parameters != null && Parameters.Count > 0))
600 sql = BuildExec (commandText);
601 ExecuteQuery (sql, timeout, wantResults);
604 private string FormatParameter (TdsMetaParameter parameter)
606 string parameterName = parameter.ParameterName;
607 if (parameterName [0] == '@') {
608 parameterName = parameterName.Substring (1);
610 if (parameter.Direction == TdsParameterDirection.Output)
611 return String.Format ("@{0}=@{0} output", parameterName);
612 if (parameter.Value == null || parameter.Value == DBNull.Value)
613 return String.Format ("@{0}=NULL", parameterName);
616 switch (parameter.TypeName) {
617 case "smalldatetime":
619 DateTime d = Convert.ToDateTime (parameter.Value);
620 value = String.Format (base.Locale,
621 "'{0:MMM dd yyyy hh:mm:ss.fff tt}'", d);
632 object paramValue = parameter.Value;
633 Type paramType = paramValue.GetType ();
634 if (paramType.IsEnum)
635 paramValue = Convert.ChangeType (paramValue,
636 Type.GetTypeCode (paramType));
637 value = paramValue.ToString ();
641 value = String.Format ("N'{0}'", parameter.Value.ToString ().Replace ("'", "''"));
643 case "uniqueidentifier":
644 value = String.Format ("'{0}'", ((Guid) parameter.Value).ToString (string.Empty));
647 if (parameter.Value.GetType () == typeof (bool))
648 value = (((bool) parameter.Value) ? "0x1" : "0x0");
650 value = parameter.Value.ToString ();
655 byte[] byteArray = (byte[]) parameter.Value;
656 // In 1.0 profile, BitConverter.ToString() throws ArgumentOutOfRangeException when passed a 0-length
657 // array, so handle that as a special case.
658 if (byteArray.Length == 0)
661 value = String.Format ("0x{0}", BitConverter.ToString (byteArray).Replace ("-", string.Empty).ToLower ());
664 value = String.Format ("'{0}'", parameter.Value.ToString ().Replace ("'", "''"));
668 return "@" + parameterName + "=" + value;
671 public override string Prepare (string commandText, TdsMetaParameterCollection parameters)
673 Parameters = parameters;
675 TdsMetaParameterCollection parms = new TdsMetaParameterCollection ();
676 TdsMetaParameter parm = new TdsMetaParameter ("@Handle", "int", null);
677 parm.Direction = TdsParameterDirection.Output;
680 parms.Add (new TdsMetaParameter ("@VarDecl", "nvarchar", BuildPreparedParameters ()));
681 parms.Add (new TdsMetaParameter ("@Query", "nvarchar", commandText));
683 ExecProc ("sp_prepare", parms, 0, true);
685 return OutputParameters[0].ToString () ;
686 //if (ColumnValues == null || ColumnValues [0] == null || ColumnValues [0] == DBNull.Value)
687 // throw new TdsInternalException ();
688 //return string.Empty;
689 //return ColumnValues [0].ToString ();
692 protected override TdsDataColumnCollection ProcessColumnInfo ()
694 TdsDataColumnCollection result = new TdsDataColumnCollection ();
695 int numColumns = Comm.GetTdsShort ();
696 for (int i = 0; i < numColumns; i += 1) {
697 byte[] flagData = new byte[4];
698 for (int j = 0; j < 4; j += 1)
699 flagData[j] = Comm.GetByte ();
701 bool nullable = (flagData[2] & 0x01) > 0;
702 //bool caseSensitive = (flagData[2] & 0x02) > 0;
703 bool writable = (flagData[2] & 0x0c) > 0;
704 bool autoIncrement = (flagData[2] & 0x10) > 0;
705 bool isIdentity = (flagData[2] & 0x10) > 0;
707 TdsColumnType columnType = (TdsColumnType) ((Comm.GetByte () & 0xff));
709 byte xColumnType = 0;
710 if (IsLargeType (columnType)) {
711 xColumnType = (byte) columnType;
712 if (columnType != TdsColumnType.NChar)
717 string tableName = null;
719 if (IsBlobType (columnType)) {
720 columnSize = Comm.GetTdsInt ();
721 tableName = Comm.GetString (Comm.GetTdsShort ());
722 } else if (IsFixedSizeColumn (columnType)) {
723 columnSize = LookupBufferSize (columnType);
724 } else if (IsLargeType ((TdsColumnType) xColumnType)) {
725 columnSize = Comm.GetTdsShort ();
727 columnSize = Comm.GetByte () & 0xff;
730 if (IsWideType ((TdsColumnType) columnType))
736 if (columnType == TdsColumnType.Decimal || columnType == TdsColumnType.Numeric) {
737 precision = Comm.GetByte ();
738 scale = Comm.GetByte ();
740 precision = GetPrecision (columnType, columnSize);
741 scale = GetScale (columnType, columnSize);
744 string columnName = Comm.GetString (Comm.GetByte ());
746 TdsDataColumn col = new TdsDataColumn ();
749 col.ColumnType = columnType;
750 col.ColumnName = columnName;
751 col.IsAutoIncrement = autoIncrement;
752 col.IsIdentity = isIdentity;
753 col.ColumnSize = columnSize;
754 col.NumericPrecision = precision;
755 col.NumericScale = scale;
756 col.IsReadOnly = !writable;
757 col.AllowDBNull = nullable;
758 col.BaseTableName = tableName;
760 col ["ColumnType"] = columnType;
761 col ["ColumnName"] = columnName;
762 col ["IsAutoIncrement"] = autoIncrement;
763 col ["IsIdentity"] = isIdentity;
764 col ["ColumnSize"] = columnSize;
765 col ["NumericPrecision"] = precision;
766 col ["NumericScale"] = scale;
767 col ["IsReadOnly"] = !writable;
768 col ["AllowDBNull"] = nullable;
769 col ["BaseTableName"] = tableName;
775 public override void Unprepare (string statementId)
777 TdsMetaParameterCollection parms = new TdsMetaParameterCollection ();
778 parms.Add (new TdsMetaParameter ("@P1", "int", Int32.Parse (statementId)));
779 ExecProc ("sp_unprepare", parms, 0, false);
782 protected override bool IsValidRowCount (byte status, byte op)
784 if ((status & (byte)0x10) == 0 || op == (byte)0xc1)
789 protected override void ProcessReturnStatus ()
791 int result = Comm.GetTdsInt ();
792 if (Parameters != null) {
793 foreach (TdsMetaParameter param in Parameters) {
794 if (param.Direction == TdsParameterDirection.ReturnValue) {
795 param.Value = result;
802 byte GetScale (TdsColumnType type, int columnSize)
805 case TdsColumnType.DateTime:
807 case TdsColumnType.DateTime4:
809 case TdsColumnType.DateTimeN:
810 switch (columnSize) {
821 throw new NotSupportedException (string.Format (
822 CultureInfo.InvariantCulture,
823 "Fixed scale not defined for column " +
824 "type '{0}' with size {1}.", type, columnSize));
827 byte GetPrecision (TdsColumnType type, int columnSize)
830 case TdsColumnType.Binary:
832 case TdsColumnType.Bit:
834 case TdsColumnType.Char:
836 case TdsColumnType.DateTime:
838 case TdsColumnType.DateTime4:
840 case TdsColumnType.DateTimeN:
841 switch (columnSize) {
848 case TdsColumnType.Real:
850 case TdsColumnType.Float8:
852 case TdsColumnType.FloatN:
853 switch (columnSize) {
860 case TdsColumnType.Image:
862 case TdsColumnType.Int1:
864 case TdsColumnType.Int2:
866 case TdsColumnType.Int4:
868 case TdsColumnType.IntN:
869 switch (columnSize) {
878 case TdsColumnType.Void:
880 case TdsColumnType.Text:
882 case TdsColumnType.UniqueIdentifier:
884 case TdsColumnType.VarBinary:
886 case TdsColumnType.VarChar:
888 case TdsColumnType.Money:
890 case TdsColumnType.NText:
892 case TdsColumnType.NVarChar:
894 case TdsColumnType.BitN:
896 case TdsColumnType.MoneyN:
897 switch (columnSize) {
904 case TdsColumnType.Money4:
906 case TdsColumnType.NChar:
908 case TdsColumnType.BigBinary:
910 case TdsColumnType.BigVarBinary:
912 case TdsColumnType.BigVarChar:
914 case TdsColumnType.BigNVarChar:
916 case TdsColumnType.BigChar:
918 case TdsColumnType.SmallMoney:
920 case TdsColumnType.Variant:
922 case TdsColumnType.BigInt:
926 throw new NotSupportedException (string.Format (
927 CultureInfo.InvariantCulture,
928 "Fixed precision not defined for column " +
929 "type '{0}' with size {1}.", type, columnSize));
932 #endregion // Methods
935 #region Asynchronous Methods
937 public override IAsyncResult BeginExecuteNonQuery (string cmdText,
938 TdsMetaParameterCollection parameters,
939 AsyncCallback callback,
942 Parameters = parameters;
943 string sql = cmdText;
944 if (Parameters != null && Parameters.Count > 0)
945 sql = BuildExec (cmdText);
947 IAsyncResult ar = BeginExecuteQueryInternal (sql, false, callback, state);
951 public override void EndExecuteNonQuery (IAsyncResult ar)
953 EndExecuteQueryInternal (ar);
956 public override IAsyncResult BeginExecuteQuery (string cmdText,
957 TdsMetaParameterCollection parameters,
958 AsyncCallback callback,
961 Parameters = parameters;
962 string sql = cmdText;
963 if (Parameters != null && Parameters.Count > 0)
964 sql = BuildExec (cmdText);
966 IAsyncResult ar = BeginExecuteQueryInternal (sql, true, callback, state);
970 public override void EndExecuteQuery (IAsyncResult ar)
972 EndExecuteQueryInternal (ar);
975 public override IAsyncResult BeginExecuteProcedure (string prolog,
979 TdsMetaParameterCollection parameters,
980 AsyncCallback callback,
983 Parameters = parameters;
984 string pcall = BuildProcedureCall (cmdText);
985 string sql = String.Format ("{0};{1};{2};", prolog, pcall, epilog);
987 IAsyncResult ar = BeginExecuteQueryInternal (sql, !IsNonQuery, callback, state);
991 public override void EndExecuteProcedure (IAsyncResult ar)
993 EndExecuteQueryInternal (ar);
996 #endregion // Asynchronous Methods