+2008-12-30 Gert Driesen <drieseng@users.sourceforge.net>
+
+ * DbCommandBuilder.cs: When CatalogSeparator or SchemaSeparator are
+ not set (or explicitly set to null or empty string), then return
+ default separator character. Added value check for CatalogLocation and
+ ConflictOption. Removed regions.
+
2008-12-30 Gert Driesen <drieseng@users.sourceforge.net>
* DbCommandBuilder.cs: Fixed default value for ConflicOption.
using System.ComponentModel;
using System.Data;
+using System.Globalization;
using System.Text;
namespace System.Data.Common {
public abstract class DbCommandBuilder : Component
{
- bool _setAllValues = false;
- bool _disposed = false;
+ bool _setAllValues;
+ bool _disposed;
DataTable _dbSchemaTable;
- DbDataAdapter _dbDataAdapter = null;
+ DbDataAdapter _dbDataAdapter;
private CatalogLocation _catalogLocation = CatalogLocation.Start;
private ConflictOption _conflictOption = ConflictOption.CompareAllSearchableValues;
private string _tableName;
- private string _catalogSeperator = ".";
+ private string _catalogSeparator;
private string _quotePrefix;
private string _quoteSuffix;
- private string _schemaSeperator = ".";
- private DbCommand _dbCommand = null;
-
- // Used to construct WHERE clauses
- static readonly string clause1 = "({0} = 1 AND {1} IS NULL)";
- static readonly string clause2 = "({0} = {1})";
+ private string _schemaSeparator;
+ private DbCommand _dbCommand;
DbCommand _deleteCommand;
DbCommand _insertCommand;
DbCommand _updateCommand;
- #region Constructors
+ static readonly string SEPARATOR_DEFAULT = ".";
+ // Used to construct WHERE clauses
+ static readonly string clause1 = "({0} = 1 AND {1} IS NULL)";
+ static readonly string clause2 = "({0} = {1})";
protected DbCommandBuilder ()
{
}
- #endregion // Constructors
-
- #region Properties
-
private void BuildCache (bool closeConnection)
{
DbCommand sourceCommand = SourceCommand;
[DefaultValue (CatalogLocation.Start)]
public virtual CatalogLocation CatalogLocation {
get { return _catalogLocation; }
- set { _catalogLocation = value; }
+ set {
+ CheckEnumValue (typeof (CatalogLocation),
+ (int) value);
+ _catalogLocation = value;
+ }
}
[DefaultValue (".")]
public virtual string CatalogSeparator {
- get { return _catalogSeperator; }
- set { if (value != null) _catalogSeperator = value; }
+ get {
+ if (_catalogSeparator == null || _catalogSeparator.Length == 0)
+ return SEPARATOR_DEFAULT;
+ return _catalogSeparator;
+ }
+ set { _catalogSeparator = value; }
}
[DefaultValue (ConflictOption.CompareAllSearchableValues)]
public virtual ConflictOption ConflictOption {
get { return _conflictOption; }
- set { _conflictOption = value; }
+ set {
+ CheckEnumValue (typeof (ConflictOption),
+ (int) value);
+ _conflictOption = value;
+ }
}
[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
[DefaultValue (".")]
public virtual string SchemaSeparator {
- get { return _schemaSeperator; }
- set { if (value != null) _schemaSeperator = value; }
+ get {
+ if (_schemaSeparator == null || _schemaSeparator.Length == 0)
+ return SEPARATOR_DEFAULT;
+ return _schemaSeparator;
+ }
+ set { _schemaSeparator = value; }
}
[DefaultValue (false)]
public bool SetAllValues {
get { return _setAllValues; }
set { _setAllValues = value; }
- }
+ }
private DbCommand SourceCommand {
get {
return null;
}
}
- #endregion // Properties
-
- #region Methods
protected abstract void ApplyParameterInfo (DbParameter parameter,
DataRow row,
return rdr.GetSchemaTable ();
}
- #endregion // Methods
+ static void CheckEnumValue (Type type, int value)
+ {
+ if (Enum.IsDefined (type, value))
+ return;
+
+ string typename = type.Name;
+ string msg = string.Format (CultureInfo.CurrentCulture,
+ "Value {0} is not valid for {1}.", value,
+ typename);
+ throw new ArgumentOutOfRangeException (typename, msg);
+ }
}
}
+2008-12-30 Gert Driesen <drieseng@users.sourceforge.net>
+
+ * DbCommandBuilderTest.cs: Added tests for properties.
+
2008-12-30 Gert Driesen <drieseng@users.sourceforge.net>
* DbCommandBuilderTest.cs: Added tests for QuotePrefix and
[TestFixture]
public class DbCommandBuilderTest
{
+ [Test]
+ public void CatalogLocationTest ()
+ {
+ MyCommandBuilder cb = new MyCommandBuilder ();
+ Assert.AreEqual (CatalogLocation.Start, cb.CatalogLocation, "#1");
+ cb.CatalogLocation = CatalogLocation.End;
+ Assert.AreEqual (CatalogLocation.End, cb.CatalogLocation, "#2");
+ }
+
+ [Test]
+ public void CatalogLocation_Value_Invalid ()
+ {
+ MyCommandBuilder cb = new MyCommandBuilder ();
+ cb.CatalogLocation = CatalogLocation.End;
+ try {
+ cb.CatalogLocation = (CatalogLocation) 666;
+ Assert.Fail ("#1");
+ } catch (ArgumentOutOfRangeException ex) {
+ // The CatalogLocation enumeration value, 666, is invalid
+ Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
+ Assert.IsNull (ex.InnerException, "#3");
+ Assert.IsNotNull (ex.Message, "#4");
+ Assert.IsTrue (ex.Message.IndexOf ("CatalogLocation") != -1, "#5:" + ex.Message);
+ Assert.IsTrue (ex.Message.IndexOf ("666") != -1, "#6:" + ex.Message);
+ Assert.AreEqual ("CatalogLocation", ex.ParamName, "#7");
+ }
+ Assert.AreEqual (CatalogLocation.End, cb.CatalogLocation, "#8");
+ }
+
+ [Test]
+ public void CatalogSeparator ()
+ {
+ MyCommandBuilder cb = new MyCommandBuilder ();
+ Assert.AreEqual (".", cb.CatalogSeparator, "#1");
+ cb.CatalogSeparator = "a";
+ Assert.AreEqual ("a", cb.CatalogSeparator, "#2");
+ cb.CatalogSeparator = null;
+ Assert.AreEqual (".", cb.CatalogSeparator, "#3");
+ cb.CatalogSeparator = "b";
+ Assert.AreEqual ("b", cb.CatalogSeparator, "#4");
+ cb.CatalogSeparator = string.Empty;
+ Assert.AreEqual (".", cb.CatalogSeparator, "#5");
+ cb.CatalogSeparator = " ";
+ Assert.AreEqual (" ", cb.CatalogSeparator, "#6");
+ }
+
+ [Test]
+ public void ConflictOptionTest ()
+ {
+ MyCommandBuilder cb = new MyCommandBuilder ();
+ Assert.AreEqual (ConflictOption.CompareAllSearchableValues, cb.ConflictOption, "#1");
+ cb.ConflictOption = ConflictOption.CompareRowVersion;
+ Assert.AreEqual (ConflictOption.CompareRowVersion, cb.ConflictOption, "#2");
+ }
+
+ [Test]
+ public void ConflictOption_Value_Invalid ()
+ {
+ MyCommandBuilder cb = new MyCommandBuilder ();
+ cb.ConflictOption = ConflictOption.CompareRowVersion;
+ try {
+ cb.ConflictOption = (ConflictOption) 666;
+ Assert.Fail ("#1");
+ } catch (ArgumentOutOfRangeException ex) {
+ // The ConflictOption enumeration value, 666, is invalid
+ Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
+ Assert.IsNull (ex.InnerException, "#3");
+ Assert.IsNotNull (ex.Message, "#4");
+ Assert.IsTrue (ex.Message.IndexOf ("ConflictOption") != -1, "#5:" + ex.Message);
+ Assert.IsTrue (ex.Message.IndexOf ("666") != -1, "#6:" + ex.Message);
+ Assert.AreEqual ("ConflictOption", ex.ParamName, "#7");
+ }
+ Assert.AreEqual (ConflictOption.CompareRowVersion, cb.ConflictOption, "#8");
+ }
+
[Test]
public void QuotePrefix ()
{
Assert.AreEqual ("'\"", cb.QuoteSuffix, "#4");
cb.QuoteSuffix = string.Empty;
Assert.AreEqual (string.Empty, cb.QuoteSuffix, "#5");
+ cb.QuoteSuffix = " ";
+ Assert.AreEqual (" ", cb.QuoteSuffix, "#6");
+ }
+
+ [Test]
+ public void SchemaSeparator ()
+ {
+ MyCommandBuilder cb = new MyCommandBuilder ();
+ Assert.AreEqual (".", cb.SchemaSeparator, "#1");
+ cb.SchemaSeparator = "a";
+ Assert.AreEqual ("a", cb.SchemaSeparator, "#2");
+ cb.SchemaSeparator = null;
+ Assert.AreEqual (".", cb.SchemaSeparator, "#3");
+ cb.SchemaSeparator = "b";
+ Assert.AreEqual ("b", cb.SchemaSeparator, "#4");
+ cb.SchemaSeparator = string.Empty;
+ Assert.AreEqual (".", cb.SchemaSeparator, "#5");
+ cb.SchemaSeparator = " ";
+ Assert.AreEqual (" ", cb.SchemaSeparator, "#6");
}
private class MyCommandBuilder : DbCommandBuilder
+2008-12-30 Gert Driesen <drieseng@users.sourceforge.net>
+
+ * OdbcCommandBuilderTest.cs: Added tests for properties.
+
2008-12-30 Gert Driesen <drieseng@users.sourceforge.net>
* OdbcCommandBuilder.cs: Added test for ConflictOption default value.
[TestFixture]
public class OdbcCommandBuilderTest
{
+#if NET_2_0
+ [Test]
+ public void CatalogLocationTest ()
+ {
+ OdbcCommandBuilder cb = new OdbcCommandBuilder ();
+ Assert.AreEqual (CatalogLocation.Start, cb.CatalogLocation, "#1");
+ cb.CatalogLocation = CatalogLocation.End;
+ Assert.AreEqual (CatalogLocation.End, cb.CatalogLocation, "#2");
+ }
+
+ [Test]
+ public void CatalogLocation_Value_Invalid ()
+ {
+ OdbcCommandBuilder cb = new OdbcCommandBuilder ();
+ cb.CatalogLocation = CatalogLocation.End;
+ try {
+ cb.CatalogLocation = (CatalogLocation) 666;
+ Assert.Fail ("#1");
+ } catch (ArgumentOutOfRangeException ex) {
+ // The CatalogLocation enumeration value, 666, is invalid
+ Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
+ Assert.IsNull (ex.InnerException, "#3");
+ Assert.IsNotNull (ex.Message, "#4");
+ Assert.IsTrue (ex.Message.IndexOf ("CatalogLocation") != -1, "#5:" + ex.Message);
+ Assert.IsTrue (ex.Message.IndexOf ("666") != -1, "#6:" + ex.Message);
+ }
+ Assert.AreEqual (CatalogLocation.End, cb.CatalogLocation, "#6");
+ }
+
+ [Test]
+ public void CatalogSeparator ()
+ {
+ OdbcCommandBuilder cb = new OdbcCommandBuilder ();
+ Assert.AreEqual (".", cb.CatalogSeparator, "#1");
+ cb.CatalogSeparator = "a";
+ Assert.AreEqual ("a", cb.CatalogSeparator, "#2");
+ cb.CatalogSeparator = null;
+ Assert.AreEqual (".", cb.CatalogSeparator, "#3");
+ cb.CatalogSeparator = "b";
+ Assert.AreEqual ("b", cb.CatalogSeparator, "#4");
+ cb.CatalogSeparator = string.Empty;
+ Assert.AreEqual (".", cb.CatalogSeparator, "#5");
+ cb.CatalogSeparator = " ";
+ Assert.AreEqual (" ", cb.CatalogSeparator, "#6");
+ }
+
+ [Test]
+ public void ConflictOptionTest ()
+ {
+ OdbcCommandBuilder cb = new OdbcCommandBuilder ();
+ Assert.AreEqual (ConflictOption.CompareAllSearchableValues, cb.ConflictOption, "#1");
+ cb.ConflictOption = ConflictOption.CompareRowVersion;
+ Assert.AreEqual (ConflictOption.CompareRowVersion, cb.ConflictOption, "#2");
+ }
+
+ [Test]
+ public void ConflictOption_Value_Invalid ()
+ {
+ OdbcCommandBuilder cb = new OdbcCommandBuilder ();
+ cb.ConflictOption = ConflictOption.CompareRowVersion;
+ try {
+ cb.ConflictOption = (ConflictOption) 666;
+ Assert.Fail ("#1");
+ } catch (ArgumentOutOfRangeException ex) {
+ // The ConflictOption enumeration value, 666, is invalid
+ Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
+ Assert.IsNull (ex.InnerException, "#3");
+ Assert.IsNotNull (ex.Message, "#4");
+ Assert.IsTrue (ex.Message.IndexOf ("ConflictOption") != -1, "#5:" + ex.Message);
+ Assert.IsTrue (ex.Message.IndexOf ("666") != -1, "#6:" + ex.Message);
+ Assert.AreEqual ("ConflictOption", ex.ParamName, "#7");
+ }
+ Assert.AreEqual (ConflictOption.CompareRowVersion, cb.ConflictOption, "#8");
+ }
+#endif
+
[Test]
public void QuotePrefix ()
{
Assert.AreEqual ("'\"", cb.QuoteSuffix, "#4");
cb.QuoteSuffix = string.Empty;
Assert.AreEqual (string.Empty, cb.QuoteSuffix, "#5");
+ cb.QuoteSuffix = " ";
+ Assert.AreEqual (" ", cb.QuoteSuffix, "#6");
}
#if NET_2_0
}
[Test]
- public void DefaultPropertiesTest ()
+ public void SchemaSeparator ()
{
OdbcCommandBuilder cb = new OdbcCommandBuilder ();
- Assert.AreEqual (".", cb.CatalogSeparator, "#2");
- Assert.AreEqual (ConflictOption.CompareAllSearchableValues, cb.ConflictOption, "#3");
- Assert.AreEqual (".", cb.SchemaSeparator, "#4");
- Assert.AreEqual (CatalogLocation.Start, cb.CatalogLocation, "#1");
+ Assert.AreEqual (".", cb.SchemaSeparator, "#1");
+ cb.SchemaSeparator = "a";
+ Assert.AreEqual ("a", cb.SchemaSeparator, "#2");
+ cb.SchemaSeparator = null;
+ Assert.AreEqual (".", cb.SchemaSeparator, "#3");
+ cb.SchemaSeparator = "b";
+ Assert.AreEqual ("b", cb.SchemaSeparator, "#4");
+ cb.SchemaSeparator = string.Empty;
+ Assert.AreEqual (".", cb.SchemaSeparator, "#5");
+ cb.SchemaSeparator = " ";
+ Assert.AreEqual (" ", cb.SchemaSeparator, "#6");
}
#endif
}