diff options
6 files changed, 380 insertions, 326 deletions
diff --git a/mcs/class/System.Data/System.Data.Common/DbDataPermission.cs b/mcs/class/System.Data/System.Data.Common/DbDataPermission.cs index faf4ee88c61..0d157b60e6c 100644 --- a/mcs/class/System.Data/System.Data.Common/DbDataPermission.cs +++ b/mcs/class/System.Data/System.Data.Common/DbDataPermission.cs @@ -16,41 +16,60 @@ namespace System.Data.Common { [Serializable] public abstract class DBDataPermission : CodeAccessPermission, IUnrestrictedPermission { - private bool allowBlankPassword; - private PermissionState permissionState; + #region Fields + + bool allowBlankPassword; + PermissionState state; + + #endregion // Fields + + #region Constructors protected DBDataPermission () + : this (PermissionState.None, false) { - allowBlankPassword = false; - permissionState = PermissionState.None; } protected DBDataPermission (PermissionState state) + : this (state, false) { - allowBlankPassword = false; - permissionState = state; } - public DBDataPermission (PermissionState state, bool abp) + public DBDataPermission (PermissionState state, bool allowBlankPassword) { - allowBlankPassword = abp; - permissionState = state; + this.state = state; + this.allowBlankPassword = allowBlankPassword; } + #endregion // Constructors + + #region Properties + public bool AllowBlankPassword { get { return allowBlankPassword; } set { allowBlankPassword = value; } } + + internal PermissionState State { + get { return state; } + set { state = value; } + } + + #endregion // Properties + + #region Methods public override IPermission Copy () { - throw new NotImplementedException (); + DBDataPermission copy = CreateInstance (); + copy.AllowBlankPassword = this.allowBlankPassword; + copy.State = this.state; + return copy; } - [MonoTODO] protected virtual DBDataPermission CreateInstance () { - throw new NotImplementedException (); + return (DBDataPermission) Activator.CreateInstance (this.GetType ()); } [MonoTODO] @@ -73,9 +92,7 @@ namespace System.Data.Common { public bool IsUnrestricted () { - if (permissionState == PermissionState.Unrestricted) - return true; - return false; + return (state == PermissionState.Unrestricted); } [MonoTODO] @@ -89,5 +106,7 @@ namespace System.Data.Common { { throw new NotImplementedException (); } + + #endregion // Methods } } diff --git a/mcs/class/System.Data/System.Data.SqlClient/SqlClientPermission.cs b/mcs/class/System.Data/System.Data.SqlClient/SqlClientPermission.cs index 084a1098a6b..ad826984b71 100644 --- a/mcs/class/System.Data/System.Data.SqlClient/SqlClientPermission.cs +++ b/mcs/class/System.Data/System.Data.SqlClient/SqlClientPermission.cs @@ -20,70 +20,36 @@ namespace System.Data.SqlClient { [Serializable] public sealed class SqlClientPermission : DBDataPermission { + #region Fields + + PermissionState state; + + #endregion // Fields + #region Constructors - [MonoTODO] - public SqlClientPermission () + public SqlClientPermission () + : this (PermissionState.None, false) { - // FIXME: do constructor } - [MonoTODO] public SqlClientPermission (PermissionState state) + : this (state, false) { - // FIXME: do constructor } - [MonoTODO] public SqlClientPermission (PermissionState state, bool allowBlankPassword) - { - throw new NotImplementedException (); + { + AllowBlankPassword = allowBlankPassword; } #endregion // Constructors #region Methods - [MonoTODO] - public override IPermission Copy () - { - throw new NotImplementedException (); - } - - [MonoTODO] - public override void FromXml (SecurityElement securityElement) - { - throw new NotImplementedException (); - } - - [MonoTODO] - public override IPermission Intersect (IPermission target) - { - throw new NotImplementedException (); - } - - [MonoTODO] - public override bool IsSubsetOf (IPermission target) - { - throw new NotImplementedException (); - } - - [MonoTODO] - public override string ToString () - { - throw new NotImplementedException (); - } - - [MonoTODO] - public override SecurityElement ToXml () - { - throw new NotImplementedException (); - } - - [MonoTODO] - public override IPermission Union (IPermission target) + protected override DBDataPermission CreateInstance () { - throw new NotImplementedException (); + return (DBDataPermission) new SqlClientPermission (); } #endregion // Methods diff --git a/mcs/class/System.Data/System.Data.SqlClient/SqlCommand.cs b/mcs/class/System.Data/System.Data.SqlClient/SqlCommand.cs index 424ec74e91a..90ca617a318 100644 --- a/mcs/class/System.Data/System.Data.SqlClient/SqlCommand.cs +++ b/mcs/class/System.Data/System.Data.SqlClient/SqlCommand.cs @@ -475,12 +475,10 @@ namespace System.Data.SqlClient { if (parameter.Value.GetType () == typeof (bool)) return (((bool) parameter.Value) ? "0x1" : "0x0"); return parameter.Value.ToString (); + case SqlDbType.Image: case SqlDbType.Binary: case SqlDbType.VarBinary: - StringBuilder result = new StringBuilder ("0x"); - foreach (byte b in (byte[]) parameter.Value) - result.Append (Convert.ToString (b, 16)); - return result.ToString (); + return String.Format ("0x{0}", BitConverter.ToString ((byte[]) parameter.Value).Replace ("-", "").ToLower ()); default: return String.Format ("'{0}'", parameter.Value.ToString ().Replace ("'", "''")); } diff --git a/mcs/class/System.Data/System.Data.SqlClient/SqlParameter.cs b/mcs/class/System.Data/System.Data.SqlClient/SqlParameter.cs index 283d7faecad..4a0964c1cd7 100644 --- a/mcs/class/System.Data/System.Data.SqlClient/SqlParameter.cs +++ b/mcs/class/System.Data/System.Data.SqlClient/SqlParameter.cs @@ -32,6 +32,9 @@ namespace System.Data.SqlClient { DbType dbType; string typeName; + bool isSizeSet = false; + bool isTypeSet = false; + string parmName; object objValue; int size; @@ -42,7 +45,8 @@ namespace System.Data.SqlClient { byte scale; DataRowVersion sourceVersion; int offset; - bool sizeSet = false; + + SqlParameterCollection container = null; #endregion // Fields @@ -58,7 +62,7 @@ namespace System.Data.SqlClient { this.parmName = parameterName; this.objValue = value; this.sourceVersion = DataRowVersion.Current; - SetType (value.GetType ()); + InferSqlType (value); } public SqlParameter (string parameterName, SqlDbType dbType) @@ -128,6 +132,13 @@ namespace System.Data.SqlClient { #region Properties + // Used to ensure that only one collection can contain this + // parameter + internal SqlParameterCollection Container { + get { return container; } + set { container = value; } + } + [Browsable (false)] [DataCategory ("Data")] [DataSysDescription ("The parameter generic type.")] @@ -135,7 +146,10 @@ namespace System.Data.SqlClient { [RefreshProperties (RefreshProperties.All)] public DbType DbType { get { return dbType; } - set { SetDbType (value); } + set { + SetDbType (value); + isTypeSet = true; + } } [DataCategory ("Data")] @@ -199,8 +213,8 @@ namespace System.Data.SqlClient { public int Size { get { return size; } set { - sizeSet = true; size = value; + isSizeSet = true; } } @@ -226,7 +240,10 @@ namespace System.Data.SqlClient { [RefreshProperties (RefreshProperties.All)] public SqlDbType SqlDbType { get { return sqlDbType; } - set { SetSqlDbType (value); } + set { + SetSqlDbType (value); + isTypeSet = true; + } } [DataCategory ("Data")] @@ -234,7 +251,11 @@ namespace System.Data.SqlClient { [DefaultValue (null)] public object Value { get { return objValue; } - set { objValue = value; } + set { + if (!isTypeSet) + InferSqlType (value); + objValue = value; + } } #endregion // Properties @@ -246,6 +267,57 @@ namespace System.Data.SqlClient { return new SqlParameter (ParameterName, SqlDbType, Size, Direction, IsNullable, Precision, Scale, SourceColumn, SourceVersion, Value); } + private void InferSqlType (object value) + { + Type type = value.GetType (); + + string exception = String.Format ("The parameter data type of {0} is invalid.", type.Name); + + switch (type.FullName) { + case "System.Int64": + SetSqlDbType (SqlDbType.BigInt); + break; + case "System.Boolean": + SetSqlDbType (SqlDbType.Bit); + break; + case "System.String": + SetSqlDbType (SqlDbType.NVarChar); + break; + case "System.DateTime": + SetSqlDbType (SqlDbType.DateTime); + break; + case "System.Decimal": + SetSqlDbType (SqlDbType.Decimal); + break; + case "System.Double": + SetSqlDbType (SqlDbType.Float); + break; + case "System.Byte[]": + SetSqlDbType (SqlDbType.VarBinary); + break; + case "System.Byte": + SetSqlDbType (SqlDbType.TinyInt); + break; + case "System.Int32": + SetSqlDbType (SqlDbType.Int); + break; + case "System.Single": + SetSqlDbType (SqlDbType.Real); + break; + case "System.Int16": + SetSqlDbType (SqlDbType.SmallInt); + break; + case "System.Guid": + SetSqlDbType (SqlDbType.UniqueIdentifier); + break; + case "System.Object": + SetSqlDbType (SqlDbType.Variant); + break; + default: + throw new ArgumentException (exception); + } + } + internal string Prepare (string name) { StringBuilder result = new StringBuilder (); @@ -254,11 +326,10 @@ namespace System.Data.SqlClient { result.Append (typeName); switch (sqlDbType) { - case SqlDbType.Image : case SqlDbType.VarBinary : case SqlDbType.NVarChar : case SqlDbType.VarChar : - if (!sizeSet || size == 0) + if (!isSizeSet || size == 0) throw new InvalidOperationException ("All variable length parameters must have an explicitly set non-zero size."); result.Append ("("); result.Append (size.ToString ()); @@ -274,8 +345,6 @@ namespace System.Data.SqlClient { } break; case SqlDbType.Decimal : - case SqlDbType.Money : - case SqlDbType.SmallMoney : result.Append ("("); result.Append (precision.ToString ()); result.Append (","); @@ -295,58 +364,76 @@ namespace System.Data.SqlClient { switch (type) { case DbType.AnsiString: + typeName = "varchar"; sqlDbType = SqlDbType.VarChar; break; case DbType.AnsiStringFixedLength: + typeName = "char"; sqlDbType = SqlDbType.Char; break; case DbType.Binary: + typeName = "varbinary"; sqlDbType = SqlDbType.VarBinary; break; case DbType.Boolean: + typeName = "bit"; sqlDbType = SqlDbType.Bit; break; case DbType.Byte: + typeName = "tinyint"; sqlDbType = SqlDbType.TinyInt; break; case DbType.Currency: sqlDbType = SqlDbType.Money; + typeName = "money"; break; case DbType.Date: case DbType.DateTime: + typeName = "datetime"; sqlDbType = SqlDbType.DateTime; break; case DbType.Decimal: + typeName = "decimal"; sqlDbType = SqlDbType.Decimal; break; case DbType.Double: + typeName = "float"; sqlDbType = SqlDbType.Float; break; case DbType.Guid: + typeName = "uniqueidentifier"; sqlDbType = SqlDbType.UniqueIdentifier; break; case DbType.Int16: + typeName = "smallint"; sqlDbType = SqlDbType.SmallInt; break; case DbType.Int32: + typeName = "int"; sqlDbType = SqlDbType.Int; break; case DbType.Int64: + typeName = "bigint"; sqlDbType = SqlDbType.BigInt; break; case DbType.Object: + typeName = "sql_variant"; sqlDbType = SqlDbType.Variant; break; case DbType.Single: + typeName = "real"; sqlDbType = SqlDbType.Real; break; case DbType.String: + typeName = "nvarchar"; sqlDbType = SqlDbType.NVarChar; break; case DbType.StringFixedLength: + typeName = "nchar"; sqlDbType = SqlDbType.NChar; break; case DbType.Time: + typeName = "datetime"; sqlDbType = SqlDbType.DateTime; break; default: @@ -532,7 +619,7 @@ namespace System.Data.SqlClient { dbType = DbType.Guid; break; case SqlDbType.Variant: - typeName = "variant"; + typeName = "sql_variant"; dbType = DbType.Object; break; default: @@ -541,55 +628,6 @@ namespace System.Data.SqlClient { sqlDbType = type; } - private void SetType (Type type) - { - string exception = String.Format ("The parameter data type of {0} is invalid.", type.Name); - - switch (type.FullName) { - case "System.Int64": - SetSqlDbType (SqlDbType.BigInt); - break; - case "System.Boolean": - SetSqlDbType (SqlDbType.Bit); - break; - case "System.String": - SetSqlDbType (SqlDbType.NVarChar); - break; - case "System.DateTime": - SetSqlDbType (SqlDbType.DateTime); - break; - case "System.Decimal": - SetSqlDbType (SqlDbType.Decimal); - break; - case "System.Double": - SetSqlDbType (SqlDbType.Float); - break; - case "System.Byte[]": - SetSqlDbType (SqlDbType.VarBinary); - break; - case "System.Byte": - SetSqlDbType (SqlDbType.TinyInt); - break; - case "System.Int32": - SetSqlDbType (SqlDbType.Int); - break; - case "System.Single": - SetSqlDbType (SqlDbType.Real); - break; - case "System.Int16": - SetSqlDbType (SqlDbType.SmallInt); - break; - case "System.Guid": - SetSqlDbType (SqlDbType.UniqueIdentifier); - break; - case "System.Object": - SetSqlDbType (SqlDbType.Variant); - break; - default: - throw new ArgumentException (exception); - } - } - public override string ToString() { return parmName; diff --git a/mcs/class/System.Data/System.Data.SqlClient/SqlParameterCollection.cs b/mcs/class/System.Data/System.Data.SqlClient/SqlParameterCollection.cs index a257a14991a..fbadf2a5dfb 100644 --- a/mcs/class/System.Data/System.Data.SqlClient/SqlParameterCollection.cs +++ b/mcs/class/System.Data/System.Data.SqlClient/SqlParameterCollection.cs @@ -54,7 +54,8 @@ namespace System.Data.SqlClient { object IDataParameterCollection.this [string parameterName] { get { return this[parameterName]; } set { - CheckType (value); + if (!(value is SqlParameter)) + throw new InvalidCastException ("Only SQLParameter objects can be used."); this [parameterName] = (SqlParameter) value; } } @@ -102,52 +103,40 @@ namespace System.Data.SqlClient { public int Add (object value) { - // Check if value is a SqlParameter. - CheckType (value); + if (!(value is SqlParameter)) + throw new InvalidCastException ("Only SQLParameter objects can be used."); Add ((SqlParameter) value); return IndexOf (value); } public SqlParameter Add (SqlParameter value) { + if (value.Container != null) + throw new ArgumentException ("The SqlParameter specified in the value parameter is already added to this or another SqlParameterCollection."); + + value.Container = this; list.Add (value); return value; } public SqlParameter Add (string parameterName, object value) { - SqlParameter sqlparam = new SqlParameter(); - sqlparam.Value = value; - // TODO: Get the dbtype and Sqldbtype from system type of value. - - return Add(sqlparam); + return Add (new SqlParameter (parameterName, value)); } public SqlParameter Add (string parameterName, SqlDbType sqlDbType) { - SqlParameter sqlparam = new SqlParameter(); - sqlparam.ParameterName = parameterName; - sqlparam.SqlDbType = sqlDbType; - return Add(sqlparam); + return Add (new SqlParameter (parameterName, sqlDbType)); } public SqlParameter Add (string parameterName, SqlDbType sqlDbType, int size) { - SqlParameter sqlparam = new SqlParameter(); - sqlparam.ParameterName = parameterName; - sqlparam.SqlDbType = sqlDbType; - sqlparam.Size = size; - return Add(sqlparam); + return Add (new SqlParameter (parameterName, sqlDbType, size)); } public SqlParameter Add (string parameterName, SqlDbType sqlDbType, int size, string sourceColumn) { - SqlParameter sqlparam = new SqlParameter (); - sqlparam.ParameterName = parameterName; - sqlparam.SqlDbType = sqlDbType; - sqlparam.Size = size; - sqlparam.SourceColumn = sourceColumn; - return Add (sqlparam); + return Add (new SqlParameter (parameterName, sqlDbType, size, sourceColumn)); } public void Clear() @@ -157,7 +146,8 @@ namespace System.Data.SqlClient { public bool Contains (object value) { - CheckType (value); + if (!(value is SqlParameter)) + throw new InvalidCastException ("Only SQLParameter objects can be used."); return Contains (((SqlParameter) value).ParameterName); } @@ -181,7 +171,8 @@ namespace System.Data.SqlClient { public int IndexOf (object value) { - CheckType (value); + if (!(value is SqlParameter)) + throw new InvalidCastException ("Only SQLParameter objects can be used."); return IndexOf (((SqlParameter) value).ParameterName); } @@ -210,16 +201,6 @@ namespace System.Data.SqlClient { RemoveAt (IndexOf (parameterName)); } - /// <summary> - /// This method checks if the parameter value is of - /// SqlParameter type. If it doesn't, throws an InvalidCastException. - /// </summary> - private void CheckType(object value) - { - if (!(value is SqlParameter)) - throw new InvalidCastException ("Only SQLParameter objects can be used."); - } - #endregion // Methods } } diff --git a/mcs/class/System.Data/Test/SqlTest.cs b/mcs/class/System.Data/Test/SqlTest.cs index a6937032b86..993e090730e 100644 --- a/mcs/class/System.Data/Test/SqlTest.cs +++ b/mcs/class/System.Data/Test/SqlTest.cs @@ -49,40 +49,49 @@ namespace Test.Mono.Data.SqlClient { createCommand.CommandText = "create table mono_sql_test (" + - "boolean_value bit, " + - "byte_value tinyint, " + - "int2_value smallint, " + - "int4_value integer, " + - "float_value real, " + - "double_value float, " + - "numeric_value decimal(15, 3), " + + "bit_value bit, " + + "binary_value binary (8), " + "char_value char(50), " + + "datetime_value datetime, " + + "decimal_value decimal(15, 3), " + + "float_value float, " + + "image_value image, " + + "int_value int, " + + "money_value money, " + "nchar_value nchar(50), " + - "varchar_value varchar(20), " + + "ntext_value ntext, " + "nvarchar_value nvarchar(20), " + + "real_value real, " + + "smalldatetime_value smalldatetime, " + + "smallint_value smallint, " + + "smallmoney_value smallmoney, " + "text_value text, " + - "ntext_value ntext, " + - "datetime_value datetime, " + - "guid_value uniqueidentifier, " + - "binary_value binary (8), " + + "timestamp_value timestamp, " + + "tinyint_value tinyint, " + + "uniqueidentifier_value uniqueidentifier, " + "varbinary_value varbinary (8), " + - "null_boolean_value bit, " + - "null_byte_value tinyint, " + - "null_int2_value smallint, " + - "null_int4_value integer, " + - "null_float_value real, " + - "null_double_value float, " + - "null_numeric_value decimal(15, 3), " + + "varchar_value varchar(20), " + + "null_bit_value bit, " + + "null_binary_value binary (8), " + "null_char_value char(50), " + + "null_datetime_value datetime, " + + "null_decimal_value decimal(15, 3), " + + "null_float_value float, " + + "null_image_value image, " + + "null_int_value int, " + + "null_money_value int, " + "null_nchar_value nchar(50), " + - "null_varchar_value varchar(20), " + + "null_ntext_value ntext, " + "null_nvarchar_value nvarchar(20), " + + "null_real_value real, " + + "null_smalldatetime_value smalldatetime, " + + "null_smallint_value smallint, " + + "null_smallmoney_value int, " + "null_text_value text, " + - "null_ntext_value ntext, " + - "null_datetime_value datetime, " + - "null_guid_value uniqueidentifier, " + - "null_binary_value binary (8), " + - "null_varbinary_value varbinary (8) " + + "null_tinyint_value tinyint, " + + "null_uniqueidentifier_value uniqueidentifier, " + + "null_varbinary_value varbinary (8), " + + "null_varchar_value varchar(20) " + ")"; createCommand.ExecuteNonQuery (); @@ -122,23 +131,27 @@ namespace Test.Mono.Data.SqlClient { insertCommand.CommandText = "insert into mono_sql_test (" + - "boolean_value, " + - "byte_value, " + - "int2_value, " + - "int4_value, " + - "float_value, " + - "double_value, " + - "numeric_value, " + + "bit_value, " + + "binary_value, " + "char_value, " + + "datetime_value, " + + "decimal_value, " + + "float_value, " + + "image_value, " + + "int_value, " + + "money_value, " + "nchar_value, " + - "varchar_value, " + + "ntext_value, " + "nvarchar_value, " + + "real_value, " + + "smalldatetime_value, " + + "smallint_value, " + + "smallmoney_value, " + "text_value, " + - "ntext_value, " + - "datetime_value, " + - "guid_value, " + - "binary_value, " + - "varbinary_value " + + "tinyint_value, " + + "uniqueidentifier_value, " + + "varbinary_value, " + + "varchar_value " + ") values (" + "@p1, " + "@p2, " + @@ -156,48 +169,62 @@ namespace Test.Mono.Data.SqlClient { "@p14, " + "@p15, " + "@p16, " + - "@p17 " + + "@p17, " + + "@p18, " + + "@p19, " + + "@p20, " + + "@p21 " + ")"; SqlParameterCollection parameters = ((SqlCommand) insertCommand).Parameters; parameters.Add ("@p1", SqlDbType.Bit); - parameters.Add ("@p2", SqlDbType.TinyInt); - parameters.Add ("@p3", SqlDbType.SmallInt); - parameters.Add ("@p4", SqlDbType.Int); - parameters.Add ("@p5", SqlDbType.Real); + parameters.Add ("@p2", SqlDbType.Binary, 8); + parameters.Add ("@p3", SqlDbType.Char, 14); + parameters.Add ("@p4", SqlDbType.DateTime); + parameters.Add ("@p5", SqlDbType.Decimal); parameters.Add ("@p6", SqlDbType.Float); - parameters.Add ("@p7", SqlDbType.Decimal); - parameters.Add ("@p8", SqlDbType.Char, 14); - parameters.Add ("@p9", SqlDbType.NChar, 16); - parameters.Add ("@p10", SqlDbType.VarChar, 17); - parameters.Add ("@p11", SqlDbType.NVarChar, 19); - parameters.Add ("@p12", SqlDbType.Text); - parameters.Add ("@p13", SqlDbType.NText); - parameters.Add ("@p14", SqlDbType.DateTime); - parameters.Add ("@p15", SqlDbType.UniqueIdentifier); - parameters.Add ("@p16", SqlDbType.Binary, 8); - parameters.Add ("@p17", SqlDbType.VarBinary, 8); + parameters.Add ("@p7", SqlDbType.Image); + parameters.Add ("@p8", SqlDbType.Int); + parameters.Add ("@p9", SqlDbType.Money); + parameters.Add ("@p10", SqlDbType.NChar, 16); + parameters.Add ("@p11", SqlDbType.NText); + parameters.Add ("@p12", SqlDbType.NVarChar, 19); + parameters.Add ("@p13", SqlDbType.Real); + parameters.Add ("@p14", SqlDbType.SmallDateTime); + parameters.Add ("@p15", SqlDbType.SmallInt); + parameters.Add ("@p16", SqlDbType.SmallMoney); + parameters.Add ("@p17", SqlDbType.Text); + parameters.Add ("@p18", SqlDbType.TinyInt); + parameters.Add ("@p19", SqlDbType.UniqueIdentifier); + parameters.Add ("@p20", SqlDbType.VarBinary, 8); + parameters.Add ("@p21", SqlDbType.VarChar, 17); parameters ["@p1"].Value = true; - parameters ["@p2"].Value = 15; - parameters ["@p3"].Value = -22; - parameters ["@p4"].Value = 1048000; - parameters ["@p5"].Value = 3.141592; + parameters ["@p2"].Value = new byte[2] {0x12,0x34}; + parameters ["@p3"].Value = "This is a char"; + parameters ["@p4"].Value = new DateTime (1959, 7, 17); // My mom's birthday! + + parameters ["@p5"].Value = 123456789012.345; + parameters ["@p5"].Precision = 15; + parameters ["@p5"].Scale = 3; + parameters ["@p6"].Value = 3.1415926969696; - parameters ["@p7"].Value = 123456789012.345; - parameters ["@p7"].Precision = 15; - parameters ["@p7"].Scale = 3; - parameters ["@p8"].Value = "This is a char"; - parameters ["@p9"].Value = "This is an nchar"; - parameters ["@p10"].Value = "This is a varchar"; - parameters ["@p11"].Value = "This is an nvarchar"; - parameters ["@p12"].Value = "This is a text"; - parameters ["@p13"].Value = "This is an ntext"; - parameters ["@p14"].Value = DateTime.Now; - parameters ["@p15"].Value = Guid.NewGuid (); - parameters ["@p16"].Value = new byte[2] {0x12,0x34}; - parameters ["@p17"].Value = new byte[2] {0x56,0x78}; + parameters ["@p7"].Value = new byte[4] {0xde, 0xad, 0xbe, 0xef}; + parameters ["@p8"].Value = 1048000; + parameters ["@p9"].Value = 31337.456; + parameters ["@p10"].Value = "This is an nchar"; + parameters ["@p11"].Value = "This is an ntext"; + parameters ["@p12"].Value = "This is an nvarchar"; + parameters ["@p13"].Value = 3.141592; + parameters ["@p14"].Value = new DateTime (1976, 10, 31); // My birthday! + parameters ["@p15"].Value = -22; + parameters ["@p16"].Value = 31337.456; + parameters ["@p17"].Value = "This is a text"; + parameters ["@p18"].Value = 15; + parameters ["@p19"].Value = Guid.NewGuid (); + parameters ["@p20"].Value = new byte[2] {0x56,0x78}; + parameters ["@p21"].Value = "This is a varchar"; insertCommand.ExecuteNonQuery (); } @@ -220,40 +247,49 @@ namespace Test.Mono.Data.SqlClient { selectCommand.CommandText = "select " + - "boolean_value, " + - "byte_value, " + - "int2_value, " + - "int4_value, " + - "float_value, " + - "double_value, " + - "numeric_value, " + + "bit_value, " + + "binary_value, " + "char_value, " + + "datetime_value, " + + "decimal_value, " + + "float_value, " + + "image_value, " + + "int_value, " + + "money_value, " + "nchar_value, " + - "varchar_value, " + + "ntext_value, " + "nvarchar_value, " + + "real_value, " + + "smalldatetime_value, " + + "smallint_value, " + + "smallmoney_value, " + "text_value, " + - "ntext_value, " + - "datetime_value, " + - "guid_value, " + - "binary_value, " + + "timestamp_value, " + + "tinyint_value, " + + "uniqueidentifier_value, " + "varbinary_value, " + - "null_boolean_value, " + - "null_byte_value, " + - "null_int2_value, " + - "null_int4_value, " + - "null_float_value, " + - "null_double_value, " + - "null_numeric_value, " + + "varchar_value, " + + "null_bit_value, " + + "null_binary_value, " + "null_char_value, " + + "null_datetime_value, " + + "null_decimal_value, " + + "null_float_value, " + + "null_image_value, " + + "null_int_value, " + + "null_money_value, " + "null_nchar_value, " + - "null_varchar_value, " + + "null_ntext_value, " + "null_nvarchar_value, " + + "null_real_value, " + + "null_smalldatetime_value, " + + "null_smallint_value, " + + "null_smallmoney_value, " + "null_text_value, " + - "null_ntext_value, " + - "null_datetime_value, " + - "null_guid_value, " + - "null_binary_value, " + - "null_varbinary_value " + + "null_tinyint_value, " + + "null_uniqueidentifier_value, " + + "null_varbinary_value, " + + "null_varchar_value " + "from mono_sql_test"; @@ -272,23 +308,27 @@ namespace Test.Mono.Data.SqlClient { // This is a SQL INSERT Command, not a Query selectCommand.CommandText = "insert into mono_sql_test (" + - "boolean_value, " + - "byte_value, " + - "int2_value, " + - "int4_value, " + - "float_value, " + - "double_value, " + - "numeric_value, " + + "bit_value, " + + "binary_value, " + "char_value, " + + "datetime_value, " + + "decimal_value, " + + "float_value, " + + "image_value, " + + "int_value, " + + "money_value, " + "nchar_value, " + - "varchar_value, " + + "ntext_value, " + "nvarchar_value, " + + "real_value, " + + "smalldatetime_value, " + + "smallint_value, " + + "smallmoney_value, " + "text_value, " + - "ntext_value, " + - "datetime_value, " + - "guid_value, " + - "binary_value, " + - "varbinary_value " + + "tinyint_value, " + + "uniqueidentifier_value, " + + "varbinary_value, " + + "varchar_value " + ") values (" + "@p1, " + "@p2, " + @@ -306,48 +346,62 @@ namespace Test.Mono.Data.SqlClient { "@p14, " + "@p15, " + "@p16, " + - "@p17 " + + "@p17, " + + "@p18, " + + "@p19, " + + "@p20, " + + "@p21 " + ")"; SqlParameterCollection parameters = ((SqlCommand) selectCommand).Parameters; parameters.Add ("@p1", SqlDbType.Bit); - parameters.Add ("@p2", SqlDbType.TinyInt); - parameters.Add ("@p3", SqlDbType.SmallInt); - parameters.Add ("@p4", SqlDbType.Int); - parameters.Add ("@p5", SqlDbType.Real); + parameters.Add ("@p2", SqlDbType.Binary, 8); + parameters.Add ("@p3", SqlDbType.Char, 14); + parameters.Add ("@p4", SqlDbType.DateTime); + parameters.Add ("@p5", SqlDbType.Decimal); parameters.Add ("@p6", SqlDbType.Float); - parameters.Add ("@p7", SqlDbType.Decimal); - parameters.Add ("@p8", SqlDbType.Char, 14); - parameters.Add ("@p9", SqlDbType.NChar, 16); - parameters.Add ("@p10", SqlDbType.VarChar, 17); - parameters.Add ("@p11", SqlDbType.NVarChar, 19); - parameters.Add ("@p12", SqlDbType.Text); - parameters.Add ("@p13", SqlDbType.NText); - parameters.Add ("@p14", SqlDbType.DateTime); - parameters.Add ("@p15", SqlDbType.UniqueIdentifier); - parameters.Add ("@p16", SqlDbType.Binary, 8); - parameters.Add ("@p17", SqlDbType.VarBinary, 8); + parameters.Add ("@p7", SqlDbType.Image); + parameters.Add ("@p8", SqlDbType.Int); + parameters.Add ("@p9", SqlDbType.Money); + parameters.Add ("@p10", SqlDbType.NChar, 16); + parameters.Add ("@p11", SqlDbType.NText); + parameters.Add ("@p12", SqlDbType.NVarChar, 19); + parameters.Add ("@p13", SqlDbType.Real); + parameters.Add ("@p14", SqlDbType.SmallDateTime); + parameters.Add ("@p15", SqlDbType.SmallInt); + parameters.Add ("@p16", SqlDbType.SmallMoney); + parameters.Add ("@p17", SqlDbType.Text); + parameters.Add ("@p18", SqlDbType.TinyInt); + parameters.Add ("@p19", SqlDbType.UniqueIdentifier); + parameters.Add ("@p20", SqlDbType.VarBinary, 8); + parameters.Add ("@p21", SqlDbType.VarChar, 17); parameters ["@p1"].Value = true; - parameters ["@p2"].Value = 15; - parameters ["@p3"].Value = -22; - parameters ["@p4"].Value = 1048000; - parameters ["@p5"].Value = 3.141592; + parameters ["@p2"].Value = new byte[2] {0x9a,0xbc}; + parameters ["@p3"].Value = "This is a char"; + parameters ["@p4"].Value = DateTime.Now; + + parameters ["@p5"].Value = 123456789012.345; + parameters ["@p5"].Precision = 15; + parameters ["@p5"].Scale = 3; + parameters ["@p6"].Value = 3.1415926969696; - parameters ["@p7"].Value = 123456789012.345; - parameters ["@p7"].Precision = 15; - parameters ["@p7"].Scale = 3; - parameters ["@p8"].Value = "This is a char"; - parameters ["@p9"].Value = "This is an nchar"; - parameters ["@p10"].Value = "This is a varchar"; - parameters ["@p11"].Value = "This is an nvarchar"; - parameters ["@p12"].Value = "This is a text"; - parameters ["@p13"].Value = "This is an ntext"; - parameters ["@p14"].Value = DateTime.Now; - parameters ["@p15"].Value = Guid.NewGuid (); - parameters ["@p16"].Value = new byte[2] {0x9a,0xbc}; - parameters ["@p17"].Value = new byte[2] {0xde, 0xef}; + parameters ["@p7"].Value = new byte[4] {0xfe, 0xeb, 0xda, 0xed}; + parameters ["@p8"].Value = 1048000; + parameters ["@p9"].Value = 31337.456; + parameters ["@p10"].Value = "This is an nchar"; + parameters ["@p11"].Value = "This is an ntext"; + parameters ["@p12"].Value = "This is an nvarchar"; + parameters ["@p13"].Value = 3.141592; + parameters ["@p14"].Value = new DateTime (1978, 6, 30); // My brother's birthday! + parameters ["@p15"].Value = -22; + parameters ["@p16"].Value = 31337.456; + parameters ["@p17"].Value = "This is a text"; + parameters ["@p18"].Value = 15; + parameters ["@p19"].Value = Guid.NewGuid (); + parameters ["@p20"].Value = new byte[2] {0xde, 0xef}; + parameters ["@p21"].Value = "This is a varchar"; reader = selectCommand.ExecuteReader (); @@ -379,20 +433,20 @@ namespace Test.Mono.Data.SqlClient { updateCommand.CommandText = "update mono_sql_test " + "set " + - "boolean_value = @p1, " + - "byte_value = @p2, " + - "int2_value = @p3, " + - "int4_value = @p4, " + - "char_value = @p5, " + - "nchar_value = @p6, " + - "varchar_value = @p7, " + - "nvarchar_value = @p8, " + - "text_value = @p9, " + - "ntext_value = @p10, " + - "guid_value = @p11, " + - "binary_value = @p12, " + - "varbinary_value = @p13 " + - "where int2_value = @p14"; + "bit_value = @p1, " + + "tinyint_value = @p2, " + + "smallint_value = @p3, " + + "int_value = @p4, " + + "char_value = @p5, " + + "nchar_value = @p6, " + + "varchar_value = @p7, " + + "nvarchar_value = @p8, " + + "text_value = @p9, " + + "ntext_value = @p10, " + + "uniqueidentifier_value = @p11, " + + "binary_value = @p12, " + + "varbinary_value = @p13 " + + "where smallint_value = @p14"; SqlParameterCollection parameters = ((SqlCommand) updateCommand).Parameters; @@ -485,12 +539,10 @@ namespace Test.Mono.Data.SqlClient { // column data
if (rdr.IsDBNull(c) == true)
dataValue = " is NULL";
- else if ((Type) dr["DataType"] == typeof (byte[])) { - StringBuilder builder = new StringBuilder ("0x"); - foreach (byte b in (byte[]) rdr.GetValue (c)) - builder.Append (Convert.ToString (b, 16)); - dataValue = ": " + builder.ToString (); - } + else if ((Type) dr["DataType"] == typeof (byte[])) + dataValue = + ": 0x" + + BitConverter.ToString ((byte[]) rdr.GetValue (c)).Replace ("-", "").ToLower (); else
dataValue =
": " +
@@ -595,10 +647,10 @@ namespace Test.Mono.Data.SqlClient { // It may have something to do // with culture not being set // properly. - //SelectAggregate (cnc, "avg(int4_value)"); + //SelectAggregate (cnc, "avg(int_value)"); SelectAggregate (cnc, "min(varchar_value)"); - SelectAggregate (cnc, "max(int4_value)"); - SelectAggregate (cnc, "sum(int4_value)"); + SelectAggregate (cnc, "max(int_value)"); + SelectAggregate (cnc, "sum(int_value)"); /* Select values */ Console.WriteLine ("\t\tSelect values from the database: "); |