diff options
Diffstat (limited to 'mcs/class/System.Data')
21 files changed, 561 insertions, 64 deletions
diff --git a/mcs/class/System.Data/System.Data.Odbc/ChangeLog b/mcs/class/System.Data/System.Data.Odbc/ChangeLog index 8994109ad2c..e633dabdd9d 100644 --- a/mcs/class/System.Data/System.Data.Odbc/ChangeLog +++ b/mcs/class/System.Data/System.Data.Odbc/ChangeLog @@ -1,3 +1,17 @@ +2004-08-31 Umadevi S (sumadevi@novell.com) + * OdbcDataReader.cs - Fixed Decimal parsing + + +2004-08-30 Umadevi S (sumadevi@novell.com) + * OdbcType.cs - removed inheritance from short. + +2004-08-27 Sureshkumar T (tsureshkumar@novell.com) + * OdbcDataReader.cs - fixed bug #63539 - TINYINT ODBC datatype is converted into System.Byte + +2004-08-26 Sureshkumar T (tsureshkumar@novell.com) + * OdbcDataReader.cs - Date & DateTime GetValue fixed. + GetBytes ordinal parameter passing fixed for BINARY in GetValue. + 2004-08-20 Sureshkumar T (tsureshkumar@novell.com) * OdbcConnection.cs - correct handles are passed to OdbcError exception to trap the correct error diff --git a/mcs/class/System.Data/System.Data.Odbc/OdbcDataReader.cs b/mcs/class/System.Data/System.Data.Odbc/OdbcDataReader.cs index c65d2bbf0fb..61b49d55481 100644 --- a/mcs/class/System.Data/System.Data.Odbc/OdbcDataReader.cs +++ b/mcs/class/System.Data/System.Data.Odbc/OdbcDataReader.cs @@ -473,13 +473,17 @@ namespace System.Data.Odbc bufsize=50; buffer=new byte[bufsize]; // According to sqlext.h, use SQL_CHAR for decimal ret=libodbc.SQLGetData(hstmt, ColIndex, OdbcType.Char, buffer, bufsize, ref outsize); + byte[] temp = new byte[outsize]; + for (int i=0;i<outsize;i++) + temp[i]=buffer[i]; + if (outsize!=-1) - DataValue=Decimal.Parse(System.Text.Encoding.Default.GetString(buffer)); + DataValue=Decimal.Parse(System.Text.Encoding.Default.GetString(temp)); break; case OdbcType.TinyInt: short short_data=0; ret=libodbc.SQLGetData(hstmt, ColIndex, OdbcType.TinyInt, ref short_data, 0, ref outsize); - DataValue=short_data; + DataValue = System.Convert.ToByte (short_data); break; case OdbcType.SmallInt: short sint_data=0; @@ -517,8 +521,17 @@ namespace System.Data.Odbc break; case OdbcType.Timestamp: case OdbcType.DateTime: + case OdbcType.Date: + case OdbcType.Time: OdbcTimestamp ts_data=new OdbcTimestamp(); - ret=libodbc.SQLGetData(hstmt, ColIndex, OdbcType.DateTime, ref ts_data, 0, ref outsize); + if (col.OdbcType == OdbcType.Timestamp) + ret=libodbc.SQLGetData(hstmt, ColIndex, OdbcType.Timestamp, ref ts_data, 0, ref outsize); + else if (col.OdbcType == OdbcType.DateTime) + ret=libodbc.SQLGetData(hstmt, ColIndex, OdbcType.DateTime, ref ts_data, 0, ref outsize); + else if (col.OdbcType == OdbcType.Date) + ret=libodbc.SQLGetData(hstmt, ColIndex, OdbcType.Date, ref ts_data, 0, ref outsize); + else // FIXME: how to get TIME datatype ?? + ret=libodbc.SQLGetData(hstmt, ColIndex, OdbcType.DateTime, ref ts_data, 0, ref outsize); if (outsize!=-1) // This means SQL_NULL_DATA DataValue=new DateTime(ts_data.year,ts_data.month,ts_data.day,ts_data.hour, ts_data.minute,ts_data.second,Convert.ToInt32(ts_data.fraction)); @@ -527,7 +540,7 @@ namespace System.Data.Odbc case OdbcType.Image : bufsize = col.MaxLength + 1; buffer = new byte [bufsize]; - long read = GetBytes (ColIndex, 0, buffer, 0, bufsize); + long read = GetBytes (ordinal, 0, buffer, 0, bufsize); ret = OdbcReturn.Success; DataValue = buffer; break; diff --git a/mcs/class/System.Data/System.Data.Odbc/OdbcType.cs b/mcs/class/System.Data/System.Data.Odbc/OdbcType.cs index fed8035a7e6..6e7c3169bee 100644 --- a/mcs/class/System.Data/System.Data.Odbc/OdbcType.cs +++ b/mcs/class/System.Data/System.Data.Odbc/OdbcType.cs @@ -51,7 +51,7 @@ namespace System.Data.Odbc //#define SQL_INTERVAL 10
// could map to SmallDateTime?
- public enum OdbcType : short
+ public enum OdbcType {
BigInt=-5, // SQL_BIGINT
Binary=-2, // SQL_BINARY
diff --git a/mcs/class/System.Data/System.Data.SqlClient/ChangeLog b/mcs/class/System.Data/System.Data.SqlClient/ChangeLog index 55a0ce00782..8b39fed6e74 100755 --- a/mcs/class/System.Data/System.Data.SqlClient/ChangeLog +++ b/mcs/class/System.Data/System.Data.SqlClient/ChangeLog @@ -1,3 +1,11 @@ +2004-09-24 Umadevi S <sumadevi@novell.com> + * SqlTransaction.cs - Dispose will not call rollback incase the transaction is not open. + + +2004-09-02 Umadevi S <sumadevi@novell.com> + * SqlCommand.cs - ExecuteNonQuery to return -1 incase of executing a storedprocedure + + 2004-08-12 Sureshkumar T <tsureshkumar@novell.com> * SqlDataReader.cs - In Close method, the remaining resultsets are drained out, to read output parameters & to avoid stream overlap diff --git a/mcs/class/System.Data/System.Data.SqlClient/SqlCommand.cs b/mcs/class/System.Data/System.Data.SqlClient/SqlCommand.cs index 366b381b54d..a5ada9fd053 100644 --- a/mcs/class/System.Data/System.Data.SqlClient/SqlCommand.cs +++ b/mcs/class/System.Data/System.Data.SqlClient/SqlCommand.cs @@ -310,16 +310,19 @@ namespace System.Data.SqlClient { try { Execute (CommandBehavior.Default, false); - // .NET documentation says that except for INSERT, UPDATE and - // DELETE where the return value is the number of rows affected - // for the rest of the commands the return value is -1. - if ((CommandText.ToUpper().IndexOf("UPDATE")!=-1) || - (CommandText.ToUpper().IndexOf("INSERT")!=-1) || - (CommandText.ToUpper().IndexOf("DELETE")!=-1)) - result = Connection.Tds.RecordsAffected; - else + if (commandType == CommandType.StoredProcedure) result = -1; - + else { + // .NET documentation says that except for INSERT, UPDATE and + // DELETE where the return value is the number of rows affected + // for the rest of the commands the return value is -1. + if ((CommandText.ToUpper().IndexOf("UPDATE")!=-1) || + (CommandText.ToUpper().IndexOf("INSERT")!=-1) || + (CommandText.ToUpper().IndexOf("DELETE")!=-1)) + result = Connection.Tds.RecordsAffected; + else + result = -1; + } } catch (TdsTimeoutException e) { throw SqlException.FromTdsInternalException ((TdsInternalException) e); diff --git a/mcs/class/System.Data/System.Data.SqlClient/SqlTransaction.cs b/mcs/class/System.Data/System.Data.SqlClient/SqlTransaction.cs index f6c1ad13f5c..aa145d2c426 100644 --- a/mcs/class/System.Data/System.Data.SqlClient/SqlTransaction.cs +++ b/mcs/class/System.Data/System.Data.SqlClient/SqlTransaction.cs @@ -94,7 +94,8 @@ namespace System.Data.SqlClient { { if (!disposed) { if (disposing) { - Rollback (); + if (isOpen) + Rollback (); } disposed = true; } diff --git a/mcs/class/System.Data/System.Data/ChangeLog b/mcs/class/System.Data/System.Data/ChangeLog index 78cc45ac101..c1212daff3f 100644 --- a/mcs/class/System.Data/System.Data/ChangeLog +++ b/mcs/class/System.Data/System.Data/ChangeLog @@ -1,3 +1,42 @@ +2004-10-08 Atsushi Enomoto <atsushi@ximian.com> + + * DataSet.cs : Yesterday's fix was different and broke the build :( + +2004-10-07 Atsushi Enomoto <atsushi@ximian.com> + + * DataSet.cs : + - When AllowDBNull is false on attribute DataColumn, its schema + should contain use="required". This fixes bug #66792. + - If MaxLength is set on attribute DataColumn, the mapped schema + type should contain maxLength facet. This fixes bug #66793. + +2004-10-04 Atsushi Enomoto <atsushi@ximian.com> + + * DataSet.cs : For a row, when a relation is not nested, then it is + still output target since it won't be written as a child of its + parent. It fixes bug #66379. + +2004-10-03 Atsushi Enomoto <atsushi@ximian.com> + + * DataSet.cs : Attribute constraint field XPath must be written as + @blah. This fixes bug #66366. + +2004-09-28 Umadevi S <sumadevi@novell.com> + * DataRow.cs - checked for Enforceconstraints, while using indices to search for related rows + +2004-09-24 Sureshkumar T <tsureshkumar@novell.com> + + * DataSet.cs : Don't check constraints for dataset clear + * DataRowCollection.cs : check for EnforceConstraints flag + before checking foriegn key constraints in Clear method + * DataTable.cs : Redundant checking removed in Clear method as it is + checked in DataRowCollection.Clear method. + +2004-09-21 Sureshkumar T <tsureshkumar@novell.com> + + * DataRow.cs: Added a new original row cache, if the current row happens + to be the original row. fixed bug #63097 + 2004-08-06 Atsushi Enomoto <atsushi@ximian.com> * DataSet.cs : DataSet's ExtendedProperties were not XmlConverted. diff --git a/mcs/class/System.Data/System.Data/DataRow.cs b/mcs/class/System.Data/System.Data/DataRow.cs index 382659bbcfc..49c59a922db 100644 --- a/mcs/class/System.Data/System.Data/DataRow.cs +++ b/mcs/class/System.Data/System.Data/DataRow.cs @@ -489,7 +489,9 @@ namespace System.Data { DataColumn column = _table.Columns[columnName]; _table.ChangingDataColumn (this, column, val); - if (_original < 0) { + if (_original < 0 || _original == _current) { + // really add a row cache, if _original is not there & + // make row modified _original = Table.RecordCache.NewRecord(); } CheckValue (val, column); @@ -1036,7 +1038,9 @@ namespace System.Data { int numColumn = parentColumns.Length; if (HasVersion(version)) { Index indx = relation.ParentTable.GetIndexByColumns (parentColumns); - if (indx != null) { // get the child rows from the index + if (indx != null && + (Table == null || Table.DataSet == null || + Table.DataSet.EnforceConstraints)) { // get the child rows from the index Node[] childNodes = indx.FindAllSimple(childColumns, IndexFromVersion(version)); for (int i = 0; i < childNodes.Length; i++) { rows.Add (childNodes[i].Row); diff --git a/mcs/class/System.Data/System.Data/DataRowCollection.cs b/mcs/class/System.Data/System.Data/DataRowCollection.cs index 06e94a354b3..8b1d2e20190 100644 --- a/mcs/class/System.Data/System.Data/DataRowCollection.cs +++ b/mcs/class/System.Data/System.Data/DataRowCollection.cs @@ -123,7 +123,7 @@ namespace System.Data /// </summary> public void Clear () { - if (this.table.DataSet != null) + if (this.table.DataSet != null && this.table.DataSet.EnforceConstraints) { foreach (DataTable table in this.table.DataSet.Tables) { diff --git a/mcs/class/System.Data/System.Data/DataSet.cs b/mcs/class/System.Data/System.Data/DataSet.cs index 8ac4d34836b..60b1680e73b 100644 --- a/mcs/class/System.Data/System.Data/DataSet.cs +++ b/mcs/class/System.Data/System.Data/DataSet.cs @@ -330,13 +330,19 @@ namespace System.Data { tempTable.AcceptChanges (); } + /// <summary> + /// Clears all the tables + /// </summary> public void Clear () { if (_xmlDataDocument != null) throw new NotSupportedException ("Clear function on dataset and datatable is not supported when XmlDataDocument is bound to the DataSet."); - for (int t = 0; t < tableCollection.Count; t++) { - tableCollection[t].Clear (); + bool enforceConstraints = this.EnforceConstraints; + this.EnforceConstraints = false; + for (int t = 0; t < tableCollection.Count; t++) { + tableCollection [t].Clear (); } + this.EnforceConstraints = enforceConstraints; } public virtual DataSet Clone () @@ -1188,16 +1194,22 @@ namespace System.Data { case 0: break; case 1: + if (!oneRel.Nested) + break; if (row.GetParentRow (oneRel) != null) continue; break; case 2: bool skip = false; - for (int i = 0; i < table.ParentRelations.Count; i++) - if (row.GetParentRow (table.ParentRelations [i]) != null) { + for (int i = 0; i < table.ParentRelations.Count; i++) { + DataRelation prel = table.ParentRelations [i]; + if (!prel.Nested) + continue; + if (row.GetParentRow (prel) != null) { skip = true; continue; } + } if (skip) continue; break; @@ -1539,7 +1551,8 @@ namespace System.Data { XmlSchemaXPath field; foreach (DataColumn column in uqConst.Columns) { field = new XmlSchemaXPath(); - field.XPath = constraintPrefix+column.ColumnName; + string typePrefix = column.ColumnMapping == MappingType.Attribute ? "@" : ""; + field.XPath = typePrefix + constraintPrefix + column.ColumnName; uniq.Fields.Add(field); } @@ -1606,7 +1619,8 @@ namespace System.Data { XmlSchemaXPath field; foreach (DataColumn column in rel.ChildColumns) { field = new XmlSchemaXPath(); - field.XPath = constraintPrefix+column.ColumnName; + string typePrefix = column.ColumnMapping == MappingType.Attribute ? "@" : ""; + field.XPath = typePrefix + constraintPrefix + column.ColumnName; keyRef.Fields.Add(field); } @@ -1753,8 +1767,20 @@ namespace System.Data { // FIXME: Handle prefix mapping correctly. schemaToAdd.Namespaces.Add (prefix, col.Namespace); } - att.SchemaTypeName = MapType (col.DataType); + if (!col.AllowDBNull) + att.Use = XmlSchemaUse.Required; + + if (col.MaxLength > -1) + att.SchemaType = GetTableSimpleType (doc, col); + else + att.SchemaTypeName = MapType (col.DataType); // FIXME: what happens if extended properties are set on attribute columns?? + if (!col.AllowDBNull) + att.Use = XmlSchemaUse.Required; + if (col.MaxLength > -1) + att.SchemaType = GetTableSimpleType (doc, col); + else + att.SchemaTypeName = MapType (col.DataType); schemaAttributes.Add (att); } diff --git a/mcs/class/System.Data/System.Data/DataTable.cs b/mcs/class/System.Data/System.Data/DataTable.cs index c8f06e7ec0b..344d928f2ec 100644 --- a/mcs/class/System.Data/System.Data/DataTable.cs +++ b/mcs/class/System.Data/System.Data/DataTable.cs @@ -677,37 +677,7 @@ namespace System.Data { /// Clears the DataTable of all data. /// </summary> public void Clear () { - // TODO: thow an exception if any rows that - // have enforced child relations - // that would result in child rows being orphaned - // now we check if any ForeignKeyConstraint is referncing 'table'. - if (DataSet != null) - { - if (DataSet._xmlDataDocument != null) - throw new NotSupportedException ("Clear function on dataset and datatable is not supported on XmlDataDocument."); - - IEnumerator tableEnumerator = DataSet.Tables.GetEnumerator(); - - // loop on all tables in dataset - while (tableEnumerator.MoveNext()) - { - IEnumerator constraintEnumerator = ((DataTable) tableEnumerator.Current).Constraints.GetEnumerator(); - // loop on all constrains in the current table - while (constraintEnumerator.MoveNext()) - { - Object o = constraintEnumerator.Current; - // we only check ForeignKeyConstraint - if (o is ForeignKeyConstraint) - { - ForeignKeyConstraint fc = (ForeignKeyConstraint) o; - if(fc.RelatedTable == this && fc.Table.Rows.Count > 0) - throw new InvalidConstraintException("Cannot clear table " + fc.RelatedTable + " because ForeignKeyConstraint " + fc.ConstraintName + " enforces constraints and there are child rows in " + fc.Table); - } - } - } - } - - + // Foriegn key constraints are checked in _rows.Clear method _rows.Clear (); } diff --git a/mcs/class/System.Data/Test/ChangeLog b/mcs/class/System.Data/Test/ChangeLog index f519b6dce99..65c8719353a 100644 --- a/mcs/class/System.Data/Test/ChangeLog +++ b/mcs/class/System.Data/Test/ChangeLog @@ -1,3 +1,6 @@ +2004-08-26 Sureshkumar T <TSureshkumar@novell.com> + * MySqlTestBed.cs - Added few more fields for DateTime testing + 2004-08-13 Umadevi S <sumadevi@novell.com> * Added standalone nunit testcases for datacontainer class. * Currently will use MSSQL server diff --git a/mcs/class/System.Data/Test/MySqlTestBed.cs b/mcs/class/System.Data/Test/MySqlTestBed.cs index a923c0d326d..1f8fef70c89 100644 --- a/mcs/class/System.Data/Test/MySqlTestBed.cs +++ b/mcs/class/System.Data/Test/MySqlTestBed.cs @@ -95,23 +95,26 @@ namespace MonoTests.System.Data "pk_tint TINYINT NOT NULL PRIMARY KEY," + "col_char CHAR(20)," + "col_int INT," + - "col_blob TINYBLOB" + + "col_blob TINYBLOB," + + "col_datetime DATETIME," + + "col_date DATE," + + "col_time TIME" + ");"; ExecuteQuery (createQuery); createQuery = "INSERT INTO test VALUES (1, 'mono test" + - "#1', 255, 127123645917568585638457243856234985 );" ; + "#1', 255, 127123645917568585638457243856234985, '2004-08-22', '2004-08-22', '12:00:00' );" ; ExecuteQuery (createQuery); createQuery = "INSERT INTO test VALUES (2, 'mono test" + - "#2', 256, NULL );" ; + "#2', 256, NULL, NULL, NULL, NULL );"; ExecuteQuery (createQuery); createQuery = "INSERT INTO test VALUES (3, 'mono test" + - "#3', 257 , 127123645917568585638457243856234985);" ; + "#3', 257 , 127123645917568585638457243856234985, '2004-08-22', '2004-08-22', '12:00:00');" ; ExecuteQuery (createQuery); createQuery = "INSERT INTO test VALUES (4, 'mono test" + - "#4', 258 , 127123645917568585638457243856234985);" ; + "#4', 258 , 127123645917568585638457243856234985, '2004-08-22', '2004-08-22', '12:00:00');" ; ExecuteQuery (createQuery); createQuery = "INSERT INTO test VALUES (5, 'mono test" + - "#5', 259, 127123645917568585638457243856234985 );" ; + "#5', 259, 127123645917568585638457243856234985, '2004-08-22', '2004-08-22', '12:00:00' );" ; ExecuteQuery (createQuery); } diff --git a/mcs/class/System.Data/Test/System.Data.Odbc/ChangeLog b/mcs/class/System.Data/Test/System.Data.Odbc/ChangeLog index 0e26247cecd..7ecb34c9d29 100644 --- a/mcs/class/System.Data/Test/System.Data.Odbc/ChangeLog +++ b/mcs/class/System.Data/Test/System.Data.Odbc/ChangeLog @@ -1,3 +1,13 @@ +2004-08-31 Umadevi S <sumadevi@novell.com> + * OdbcDataReaderTest.cs - Added a test for Numeric Type + +2004-08-27 Sureshkumar T <tsureshkumar@novell.com> + * OdbcDataReaderTest.cs - Added a test for TinyInt + +2004-08-26 Sureshkumar T <tsureshkumar@novell.com> + * OdbcDataReaderTest.cs - Added a test for DateTime - GetDateTimeTest + * OdbcCommandTest.cs - Syntax Error Fix + 2004-07-29 Umadevi S <sumadevi@novell.com> * OdbcCommandTest.cs - Added testcase for bug 62046. ExecuteNonQuery diff --git a/mcs/class/System.Data/Test/System.Data.Odbc/OdbcCommandTest.cs b/mcs/class/System.Data/Test/System.Data.Odbc/OdbcCommandTest.cs index 42702295065..f46cf29c6c7 100644 --- a/mcs/class/System.Data/Test/System.Data.Odbc/OdbcCommandTest.cs +++ b/mcs/class/System.Data/Test/System.Data.Odbc/OdbcCommandTest.cs @@ -107,7 +107,7 @@ namespace MonoTests.System.Data.Odbc dbcmd.CommandType = CommandType.Text;
dbcmd.CommandText = "delete from test where (col_int >257);";
ret = dbcmd.ExecuteNonQuery();
- Assertion.AssertEquals("ExecuteNonQuery not working", 2, ret);}
+ Assertion.AssertEquals("ExecuteNonQuery not working", 2, ret);
+ }
- }
}
diff --git a/mcs/class/System.Data/Test/System.Data.Odbc/OdbcDataReaderTest.cs b/mcs/class/System.Data/Test/System.Data.Odbc/OdbcDataReaderTest.cs index 0017b818681..b8ceeafbbbb 100644 --- a/mcs/class/System.Data/Test/System.Data.Odbc/OdbcDataReaderTest.cs +++ b/mcs/class/System.Data/Test/System.Data.Odbc/OdbcDataReaderTest.cs @@ -231,5 +231,106 @@ namespace MonoTests.System.Data.Odbc CloseConnection ();
}
}
+
+ [Test]
+ public void GetDateTimeTest ()
+ {
+ OdbcCommand cmd = conn.CreateCommand ();
+ string sql = "SELECT * FROM test";
+ cmd.CommandText = sql;
+ OdbcDataReader reader = cmd.ExecuteReader (CommandBehavior.Default);
+ try {
+ if (reader.Read ()) {
+ object ob = reader["col_datetime"];
+ Assertion.AssertEquals ("Type of datetime column is wrong!",
+ "System.DateTime", ob.GetType ().ToString () );
+ ob = reader["col_date"];
+ Assertion.AssertEquals ("Type of date column is wrong!",
+ "System.DateTime", ob.GetType ().ToString () );
+ // FIXME : Once TIME data type is fixed, enable this check
+ //ob = reader["col_time"];
+ //Assertion.AssertEquals ("Type of time column is wrong!",
+ //"System.DateTime", ob.GetType ().ToString () );
+
+ DateTime dt = reader.GetDateTime (4);
+ Assertion.AssertEquals ("DateValue (SQL_TIMESTAMP) is wrong", new DateTime (2004, 8, 22, 0, 0, 0), dt);
+ dt = reader.GetDateTime (5);
+ Assertion.AssertEquals ("DateValue (SQL_DATE) is wrong", new DateTime (2004, 8, 22, 0, 0, 0), dt);
+ // FIXME : Once TIME data type is fixed, enable this check
+ //dt = reader.GetDateTime (7);
+ //Assertion.AssertEquals ("DateValue is wrong", "2004-08-22", dt.ToString ());
+ }
+ } finally {
+ // clean up
+ if (reader != null && !reader.IsClosed )
+ reader.Close ();
+ reader = null;
+ CleanTestSetup ();
+ CloseConnection ();
+ }
+ }
+
+
+ /// <summary>
+ /// This test for the return type & value for GetValue
+ /// in case of Odbc Data type TINYINT
+ /// </summary>
+ [Test]
+ public void TinyIntTest ()
+ {
+ OdbcCommand cmd = conn.CreateCommand ();
+ string sql = "SELECT * FROM test";
+ cmd.CommandText = sql;
+ OdbcDataReader reader = cmd.ExecuteReader (CommandBehavior.SequentialAccess);
+ try {
+ if (reader.Read ()) {
+ object ob = reader.GetValue (0);
+ Assertion.AssertEquals ("Type of tinyInt column is wrong!",
+ "System.Byte", ob.GetType ().ToString () );
+ Assertion.AssertEquals ("Value of tinyInt column is wrong!",
+ 1, System.Convert.ToInt16(ob) );
+ }
+ } finally {
+ // clean up
+ if (reader != null && !reader.IsClosed )
+ reader.Close ();
+ reader = null;
+ CleanTestSetup ();
+ CloseConnection ();
+ }
+ }
+
+ [Test]
+ public void NumericTest()
+ {
+ using(IDbConnection dbConnection = new OdbcConnection(connectionString))
+ {
+ dbConnection.Open();
+ IDbCommand dbCommand = dbConnection.CreateCommand();
+ //note this will fail if the table already exists, ie if the test has failed.
+ dbCommand.CommandText = "CREATE TABLE NumericTable (NumericField NUMERIC(10) NOT NULL)";
+ dbCommand.ExecuteNonQuery();
+ dbCommand.CommandText = "INSERT INTO NumericTable (NumericField) VALUES (125)";
+ dbCommand.ExecuteNonQuery();
+ dbCommand.CommandText = "SELECT * FROM NumericTable";
+ using(IDataReader reader = dbCommand.ExecuteReader())
+ {
+ while(reader.Read())
+ {
+ for(int index = 0; index < reader.FieldCount; index++)
+ {
+ Object dataValue = reader.GetValue(index);
+ Assert.AreEqual("System.Decimal",dataValue.GetType().ToString());
+ Assert.AreEqual("125", dataValue.ToString());
+ }
+ }
+ }
+ dbCommand.CommandText = "DROP TABLE NumericTable";
+ dbCommand.ExecuteNonQuery();
+ }
+ }
+
+
+
}
}
diff --git a/mcs/class/System.Data/Test/System.Data.SqlClient/SqlCommandTest.cs b/mcs/class/System.Data/Test/System.Data.SqlClient/SqlCommandTest.cs new file mode 100644 index 00000000000..9d58e4c977a --- /dev/null +++ b/mcs/class/System.Data/Test/System.Data.SqlClient/SqlCommandTest.cs @@ -0,0 +1,99 @@ +//
+// SqlCommandTest.cs - NUnit Test Cases for testing the
+// SqlCommand class
+// Author:
+// Umadevi S (sumadevi@novell.com)
+//
+// Copyright (c) 2004 Novell Inc., and the individuals listed
+// on the ChangeLog entries.
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using System.Data;
+using System.Data.Common; +using System.Data.SqlClient;
+
+using NUnit.Framework;
+
+namespace MonoTests.System.Data.SqlClient +{
+
+ [TestFixture]
+ public class SqlCommandTest : MSSqlTestClient {
+
+ [SetUp]
+ public void GetReady () {
+ OpenConnection ();
+ }
+
+ [TearDown]
+ public void Clean () {
+ CloseConnection ();
+ } + + /** + This is required to be run only once, call this from the GetReady. + **/ + private void setup(){ + string createquery = "CREATE PROCEDURE sp_insert @TestPar1 varchar(50),@BirthDate datetime as insert into Employees(LastName,FirstName) VALUES('SSS','uuuu') "; + SqlCommand cmd = new SqlCommand(); + cmd.Connection = conn; + cmd.CommandText = createquery; + int ret =cmd.ExecuteNonQuery(); + } + + + [Test]
+ /** + The below test expects the stored procedure sp_insert in the database. + **/ + public void ExecuteNonQueryTest () { + try { + SqlCommand cmd = new SqlCommand(); + cmd.Connection = conn; + cmd.CommandText = "sp_insert"; + cmd.CommandType = CommandType.StoredProcedure; + Object TestPar = System.DBNull.Value; + cmd.Parameters.Add("@TestPar1",SqlDbType.Int); + cmd.Parameters["@TestPar1"].Value = TestPar; + cmd.Parameters.Add("@BirthDate",DateTime.Now); + Assert.AreEqual(-1,cmd.ExecuteNonQuery()); + }
+ catch (Exception e) { + Assert.Fail("A#01 Got an exception"); + Console.WriteLine(e.Message); + Console.WriteLine(e.StackTrace); + + } + + finally { // try/catch is necessary to gracefully close connections
+ + CloseConnection ();
+ }
+ }
+ + + + + + }
+}
diff --git a/mcs/class/System.Data/Test/System.Data.SqlClient/SqlTransactionTest.cs b/mcs/class/System.Data/Test/System.Data.SqlClient/SqlTransactionTest.cs new file mode 100644 index 00000000000..c91e27631cc --- /dev/null +++ b/mcs/class/System.Data/Test/System.Data.SqlClient/SqlTransactionTest.cs @@ -0,0 +1,85 @@ +//
+// SqlTransactionTest.cs - NUnit Test Cases for testing the
+// SqlTransaction class
+// Author:
+// Umadevi S (sumadevi@novell.com)
+//
+// Copyright (c) 2004 Novell Inc., and the individuals listed
+// on the ChangeLog entries.
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using System.Data;
+using System.Data.Common; +using System.Data.SqlClient;
+
+using NUnit.Framework;
+
+namespace MonoTests.System.Data.SqlClient +{
+
+ [TestFixture]
+ public class SqlTransactionTest : MSSqlTestClient {
+
+ [SetUp]
+ public void GetReady () {
+ OpenConnection ();
+ }
+
+ [TearDown]
+ public void Clean () {
+ CloseConnection ();
+ } + + [Test]
+ /** + The below test expects a table table4 with a bigint column. + **/ + public void TransactionCommitTest () { + + using (SqlTransaction transaction = conn.BeginTransaction()) + { + try + { + string sSql = "Insert into Region(RegionID,RegionDescription) Values ('10112', 'NovellBangalore')"; + SqlCommand command = new SqlCommand(); + command.Connection = conn; + command.CommandText = sSql; + command.Transaction = transaction; + command.CommandType = CommandType.Text; + command.ExecuteNonQuery(); + transaction.Commit(); + } + catch (System.Exception ex) + { + transaction.Rollback(); + } + finally + { + conn.Close(); + } + + } + } + + }
+}
diff --git a/mcs/class/System.Data/Test/System.Data/ChangeLog b/mcs/class/System.Data/Test/System.Data/ChangeLog index 48ffde727ce..07f46872aea 100644 --- a/mcs/class/System.Data/Test/System.Data/ChangeLog +++ b/mcs/class/System.Data/Test/System.Data/ChangeLog @@ -1,3 +1,15 @@ +2004-09-24 Umadevi S <sumadevi@novell.com> + * DataRowTest.cs : Added a test for EnforceConstraints with relations defined. + +2004-09-24 Sureshkumar T <tsureshkumar@novell.com> + + * DataSetTest.cs (DataSetClearTest): Added a test for DataSet.Clear. This should not + throw any exception and should override constraints. + +2004-09-21 Sureshkumar T <tsureshkumar@novell.com> + + * DataSetTest.cs : Added a test for Deserialization of dataset : DeserializeModifiedDataSet + 2004-06-23 Umadevi S <sumadevi@novell.com> * DataTableTest.cs :Corrected Testcases to .net 1.1 specifications diff --git a/mcs/class/System.Data/Test/System.Data/DataRowTest.cs b/mcs/class/System.Data/Test/System.Data/DataRowTest.cs index a82637dc9cd..2f347ddd005 100644 --- a/mcs/class/System.Data/Test/System.Data/DataRowTest.cs +++ b/mcs/class/System.Data/Test/System.Data/DataRowTest.cs @@ -756,5 +756,42 @@ namespace MonoTests.System.Data dt.Columns.Add (col);
dt.Rows [0] [0] = "test"; } + + [Test] + public void EnforceConstraint () + { + int id = 100; + // Setup stuff + DataSet ds = new DataSet(); + DataTable parent = ds.Tables.Add("parent"); + parent.Columns.Add("id", typeof(int)); + DataTable child = ds.Tables.Add("child"); + child.Columns.Add("idref", typeof(int)); + Constraint uniqueId = null; + parent.Constraints.Add(uniqueId = new UniqueConstraint("uniqueId", + new DataColumn[] {parent.Columns["id"]}, true)); + ForeignKeyConstraint fkc = new ForeignKeyConstraint("ParentChildConstraint", new DataColumn[] { parent.Columns["id"] }, + new DataColumn[] { child.Columns["idref"]}); + + child.Constraints.Add(fkc); + + DataRelation relateParentChild = new DataRelation("relateParentChild", + new DataColumn[] {parent.Columns["id"] }, + new DataColumn[] {child.Columns["idref"] }, + false); + ds.Relations.Add(relateParentChild); + + ds.EnforceConstraints = false; + DataRow parentRow = parent.Rows.Add(new object[] { id }); + DataRow childRow = child.Rows.Add(new object[] { id }); + if (parentRow == childRow.GetParentRow(relateParentChild)) { + foreach(DataColumn dc in parent.Columns) + AssertEquals(100,parentRow[dc]); + + } + + + } + } } diff --git a/mcs/class/System.Data/Test/System.Data/DataSetTest.cs b/mcs/class/System.Data/Test/System.Data/DataSetTest.cs index 766f0e86863..95c6c3061a7 100644 --- a/mcs/class/System.Data/Test/System.Data/DataSetTest.cs +++ b/mcs/class/System.Data/Test/System.Data/DataSetTest.cs @@ -1235,5 +1235,74 @@ namespace MonoTests.System.Data ds.WriteXml (xtw); AssertEquals (xml, sw.ToString ()); } + + [Test] + public void DeserializeModifiedDataSet () + { + // Serialization begins + DataSet prevDs = new DataSet (); + DataTable dt = prevDs.Tables.Add (); + dt.Columns.Add(new DataColumn("Id", typeof(string))); + + DataRow dr = dt.NewRow(); + dr [0] = "a"; + dt.Rows.Add (dr); + prevDs.AcceptChanges (); + dr = prevDs.Tables[0].Rows[0]; + dr [0] = "b"; + + XmlSerializer serializer = new XmlSerializer (typeof (DataSet)); + StringWriter sw = new StringWriter (); + XmlTextWriter xw = new XmlTextWriter (sw); + xw.QuoteChar = '\''; + serializer.Serialize (xw, prevDs); + + // Deserialization begins + StringReader sr = new StringReader (sw.ToString ()); + XmlTextReader reader = new XmlTextReader (sr); + XmlSerializer serializer1 = new XmlSerializer (typeof (DataSet)); + DataSet ds = serializer1.Deserialize (reader) as DataSet; + AssertEquals ("deserialization after modification does not give original values", + prevDs.Tables[0].Rows [0][0,DataRowVersion.Original].ToString (), + ds.Tables[0].Rows [0][0,DataRowVersion.Original].ToString ()); + AssertEquals ("deserialization after modification does not give current values", + prevDs.Tables[0].Rows [0][0,DataRowVersion.Current].ToString (), + ds.Tables[0].Rows [0][0,DataRowVersion.Current].ToString ()); + } + + /// <summary> + /// Test for testing DataSet.Clear method with foriegn key relations + /// This is expected to clear all the related datatable rows also + /// </summary> + [Test] + public void DataSetClearTest () + { + DataSet ds = new DataSet (); + DataTable parent = ds.Tables.Add ("Parent"); + DataTable child = ds.Tables.Add ("Child"); + + parent.Columns.Add ("id", typeof (int)); + child.Columns.Add ("ref_id", typeof(int)); + + child.Constraints.Add (new ForeignKeyConstraint ("fk_constraint", parent.Columns [0], child.Columns [0])); + + DataRow dr = parent.NewRow (); + dr [0] = 1; + parent.Rows.Add (dr); + dr.AcceptChanges (); + + dr = child.NewRow (); + dr [0] = 1; + child.Rows.Add (dr); + dr.AcceptChanges (); + + try { + ds.Clear (); // this should clear all the rows in parent & child tables + } catch (Exception e) { + throw (new Exception ("Exception should not have been thrown at Clear method" + e.ToString ())); + } + Assertion.AssertEquals ("parent table rows should not exist!", 0, parent.Rows.Count); + Assertion.AssertEquals ("child table rows should not exist!", 0, child.Rows.Count); + } } } |