From 595f3b7a5cecb4ca027d8d62a0cbe2aa7035054e Mon Sep 17 00:00:00 2001 From: Rodrigo Moya Date: Sun, 2 Jun 2002 14:46:11 +0000 Subject: [PATCH] 2002-06-02 Francisco Jr. * System.Data.SqlClient/SqlParameterCollection.cs: implemented missing methods. svn path=/trunk/mcs/; revision=5092 --- .../PgSqlParameterCollection.cs | 71 ++++++++++++++----- .../PgSqlParameterCollection.cs | 71 ++++++++++++++----- mcs/class/System.Data/ChangeLog | 5 ++ .../SqlParameterCollection.cs | 71 ++++++++++++++----- .../System.Data/System.Data/IDbConnection.cs | 2 +- 5 files changed, 168 insertions(+), 52 deletions(-) diff --git a/mcs/class/Mono.Data.PostgreSqlClient/Mono.Data.PostgreSqlClient/PgSqlParameterCollection.cs b/mcs/class/Mono.Data.PostgreSqlClient/Mono.Data.PostgreSqlClient/PgSqlParameterCollection.cs index f7fddd9806f..1ccfae90c9a 100644 --- a/mcs/class/Mono.Data.PostgreSqlClient/Mono.Data.PostgreSqlClient/PgSqlParameterCollection.cs +++ b/mcs/class/Mono.Data.PostgreSqlClient/Mono.Data.PostgreSqlClient/PgSqlParameterCollection.cs @@ -54,13 +54,19 @@ namespace System.Data.SqlClient throw new NotImplementedException (); } - [MonoTODO] + public int Add( object value) { - throw new NotImplementedException (); + // Call the add version that receives a SqlParameter + + // Check if value is a SqlParameter. + CheckType(value); + Add((SqlParameter) value); + + return IndexOf (value); } - [MonoTODO] + public SqlParameter Add(SqlParameter value) { parameterList.Add(value); @@ -68,30 +74,46 @@ namespace System.Data.SqlClient return value; } - [MonoTODO] + public SqlParameter Add(string parameterName, object value) { - throw new NotImplementedException (); + SqlParameter sqlparam = new SqlParameter(); + sqlparam.Value = value; + // TODO: Get the dbtype and Sqldbtype from system type of value. + + return Add(sqlparam); } - [MonoTODO] + public SqlParameter Add(string parameterName, SqlDbType sqlDbType) { - throw new NotImplementedException (); + SqlParameter sqlparam = new SqlParameter(); + sqlparam.ParameterName = parameterName; + sqlparam.SqlDbType = sqlDbType; + return Add(sqlparam); } - [MonoTODO] + public SqlParameter Add(string parameterName, SqlDbType sqlDbType, int size) { - throw new NotImplementedException (); + SqlParameter sqlparam = new SqlParameter(); + sqlparam.ParameterName = parameterName; + sqlparam.SqlDbType = sqlDbType; + sqlparam.Size = size; + return Add(sqlparam); } - [MonoTODO] + public SqlParameter Add(string parameterName, SqlDbType sqlDbType, int size, string sourceColumn) { - throw new NotImplementedException (); + SqlParameter sqlparam = new SqlParameter(); + sqlparam.ParameterName = parameterName; + sqlparam.SqlDbType = sqlDbType; + sqlparam.Size = size; + sqlparam.SourceColumn = sourceColumn; + return Add(sqlparam); } [MonoTODO] @@ -100,10 +122,12 @@ namespace System.Data.SqlClient throw new NotImplementedException (); } - [MonoTODO] + public bool Contains(object value) { - throw new NotImplementedException (); + // Check if value is a SqlParameter + CheckType(value); + return Contains(((SqlParameter)value).ParameterName); } @@ -119,16 +143,18 @@ namespace System.Data.SqlClient throw new NotImplementedException (); } - [MonoTODO] + public int IndexOf(object value) { - throw new NotImplementedException (); + // Check if value is a SqlParameter + CheckType(value); + return IndexOf(((SqlParameter)value).ParameterName); } - [MonoTODO] + public int IndexOf(string parameterName) { - throw new NotImplementedException (); + return parameterList.IndexOf(parameterName); } [MonoTODO] @@ -235,5 +261,16 @@ namespace System.Data.SqlClient throw new NotImplementedException (); } } + + /// + /// This method checks if the parameter value is of + /// SqlParameter type. If it doesn't, throws an InvalidCastException. + /// + private void CheckType(object value) + { + if(!(value is SqlParameter)) + throw new InvalidCastException("Only SQLParameter objects can be used."); + } + } } diff --git a/mcs/class/Mono.Data.PostgreSqlClient/PgSqlParameterCollection.cs b/mcs/class/Mono.Data.PostgreSqlClient/PgSqlParameterCollection.cs index f7fddd9806f..1ccfae90c9a 100644 --- a/mcs/class/Mono.Data.PostgreSqlClient/PgSqlParameterCollection.cs +++ b/mcs/class/Mono.Data.PostgreSqlClient/PgSqlParameterCollection.cs @@ -54,13 +54,19 @@ namespace System.Data.SqlClient throw new NotImplementedException (); } - [MonoTODO] + public int Add( object value) { - throw new NotImplementedException (); + // Call the add version that receives a SqlParameter + + // Check if value is a SqlParameter. + CheckType(value); + Add((SqlParameter) value); + + return IndexOf (value); } - [MonoTODO] + public SqlParameter Add(SqlParameter value) { parameterList.Add(value); @@ -68,30 +74,46 @@ namespace System.Data.SqlClient return value; } - [MonoTODO] + public SqlParameter Add(string parameterName, object value) { - throw new NotImplementedException (); + SqlParameter sqlparam = new SqlParameter(); + sqlparam.Value = value; + // TODO: Get the dbtype and Sqldbtype from system type of value. + + return Add(sqlparam); } - [MonoTODO] + public SqlParameter Add(string parameterName, SqlDbType sqlDbType) { - throw new NotImplementedException (); + SqlParameter sqlparam = new SqlParameter(); + sqlparam.ParameterName = parameterName; + sqlparam.SqlDbType = sqlDbType; + return Add(sqlparam); } - [MonoTODO] + public SqlParameter Add(string parameterName, SqlDbType sqlDbType, int size) { - throw new NotImplementedException (); + SqlParameter sqlparam = new SqlParameter(); + sqlparam.ParameterName = parameterName; + sqlparam.SqlDbType = sqlDbType; + sqlparam.Size = size; + return Add(sqlparam); } - [MonoTODO] + public SqlParameter Add(string parameterName, SqlDbType sqlDbType, int size, string sourceColumn) { - throw new NotImplementedException (); + SqlParameter sqlparam = new SqlParameter(); + sqlparam.ParameterName = parameterName; + sqlparam.SqlDbType = sqlDbType; + sqlparam.Size = size; + sqlparam.SourceColumn = sourceColumn; + return Add(sqlparam); } [MonoTODO] @@ -100,10 +122,12 @@ namespace System.Data.SqlClient throw new NotImplementedException (); } - [MonoTODO] + public bool Contains(object value) { - throw new NotImplementedException (); + // Check if value is a SqlParameter + CheckType(value); + return Contains(((SqlParameter)value).ParameterName); } @@ -119,16 +143,18 @@ namespace System.Data.SqlClient throw new NotImplementedException (); } - [MonoTODO] + public int IndexOf(object value) { - throw new NotImplementedException (); + // Check if value is a SqlParameter + CheckType(value); + return IndexOf(((SqlParameter)value).ParameterName); } - [MonoTODO] + public int IndexOf(string parameterName) { - throw new NotImplementedException (); + return parameterList.IndexOf(parameterName); } [MonoTODO] @@ -235,5 +261,16 @@ namespace System.Data.SqlClient throw new NotImplementedException (); } } + + /// + /// This method checks if the parameter value is of + /// SqlParameter type. If it doesn't, throws an InvalidCastException. + /// + private void CheckType(object value) + { + if(!(value is SqlParameter)) + throw new InvalidCastException("Only SQLParameter objects can be used."); + } + } } diff --git a/mcs/class/System.Data/ChangeLog b/mcs/class/System.Data/ChangeLog index 25b3b353d87..2905095234b 100644 --- a/mcs/class/System.Data/ChangeLog +++ b/mcs/class/System.Data/ChangeLog @@ -1,3 +1,8 @@ +2002-06-02 Francisco Jr. + + * System.Data.SqlClient/SqlParameterCollection.cs: implemented missing + methods. + 2002-05-30 Daniel Morgan * System.Data.SqlClient/SqlConnection.cs: modifed - diff --git a/mcs/class/System.Data/System.Data.SqlClient/SqlParameterCollection.cs b/mcs/class/System.Data/System.Data.SqlClient/SqlParameterCollection.cs index f7fddd9806f..1ccfae90c9a 100644 --- a/mcs/class/System.Data/System.Data.SqlClient/SqlParameterCollection.cs +++ b/mcs/class/System.Data/System.Data.SqlClient/SqlParameterCollection.cs @@ -54,13 +54,19 @@ namespace System.Data.SqlClient throw new NotImplementedException (); } - [MonoTODO] + public int Add( object value) { - throw new NotImplementedException (); + // Call the add version that receives a SqlParameter + + // Check if value is a SqlParameter. + CheckType(value); + Add((SqlParameter) value); + + return IndexOf (value); } - [MonoTODO] + public SqlParameter Add(SqlParameter value) { parameterList.Add(value); @@ -68,30 +74,46 @@ namespace System.Data.SqlClient return value; } - [MonoTODO] + public SqlParameter Add(string parameterName, object value) { - throw new NotImplementedException (); + SqlParameter sqlparam = new SqlParameter(); + sqlparam.Value = value; + // TODO: Get the dbtype and Sqldbtype from system type of value. + + return Add(sqlparam); } - [MonoTODO] + public SqlParameter Add(string parameterName, SqlDbType sqlDbType) { - throw new NotImplementedException (); + SqlParameter sqlparam = new SqlParameter(); + sqlparam.ParameterName = parameterName; + sqlparam.SqlDbType = sqlDbType; + return Add(sqlparam); } - [MonoTODO] + public SqlParameter Add(string parameterName, SqlDbType sqlDbType, int size) { - throw new NotImplementedException (); + SqlParameter sqlparam = new SqlParameter(); + sqlparam.ParameterName = parameterName; + sqlparam.SqlDbType = sqlDbType; + sqlparam.Size = size; + return Add(sqlparam); } - [MonoTODO] + public SqlParameter Add(string parameterName, SqlDbType sqlDbType, int size, string sourceColumn) { - throw new NotImplementedException (); + SqlParameter sqlparam = new SqlParameter(); + sqlparam.ParameterName = parameterName; + sqlparam.SqlDbType = sqlDbType; + sqlparam.Size = size; + sqlparam.SourceColumn = sourceColumn; + return Add(sqlparam); } [MonoTODO] @@ -100,10 +122,12 @@ namespace System.Data.SqlClient throw new NotImplementedException (); } - [MonoTODO] + public bool Contains(object value) { - throw new NotImplementedException (); + // Check if value is a SqlParameter + CheckType(value); + return Contains(((SqlParameter)value).ParameterName); } @@ -119,16 +143,18 @@ namespace System.Data.SqlClient throw new NotImplementedException (); } - [MonoTODO] + public int IndexOf(object value) { - throw new NotImplementedException (); + // Check if value is a SqlParameter + CheckType(value); + return IndexOf(((SqlParameter)value).ParameterName); } - [MonoTODO] + public int IndexOf(string parameterName) { - throw new NotImplementedException (); + return parameterList.IndexOf(parameterName); } [MonoTODO] @@ -235,5 +261,16 @@ namespace System.Data.SqlClient throw new NotImplementedException (); } } + + /// + /// This method checks if the parameter value is of + /// SqlParameter type. If it doesn't, throws an InvalidCastException. + /// + private void CheckType(object value) + { + if(!(value is SqlParameter)) + throw new InvalidCastException("Only SQLParameter objects can be used."); + } + } } diff --git a/mcs/class/System.Data/System.Data/IDbConnection.cs b/mcs/class/System.Data/System.Data/IDbConnection.cs index 1b84bed5ba2..5a67874102b 100644 --- a/mcs/class/System.Data/System.Data/IDbConnection.cs +++ b/mcs/class/System.Data/System.Data/IDbConnection.cs @@ -38,4 +38,4 @@ namespace System.Data ConnectionState State{get;} } -} \ No newline at end of file +} -- 2.25.1