[Mono-bugs] [Bug 53081][Blo] New - 'DbDataProvider' implementaion doesn't properly handle the

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Mon, 19 Jan 2004 20:55:59 -0500 (EST)


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by smalinin@amurnet.ru.

http://bugzilla.ximian.com/show_bug.cgi?id=53081

--- shadow/53081	2004-01-19 20:55:59.000000000 -0500
+++ shadow/53081.tmp.12122	2004-01-19 20:55:59.000000000 -0500
@@ -0,0 +1,779 @@
+Bug#: 53081
+Product: Mono/Class Libraries
+Version: unspecified
+OS: All
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Blocker
+Component: Sys.Data
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: smalinin@amurnet.ru               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: 'DbDataProvider' implementaion doesn't properly handle the
+
+'DbDataProvider' implementaion doesn't properly handle the
+
+
+'MissingSchemaAction' property, when MissingSchemaAction == 
+MissingSchemaAction.AddWithKey
+
+
+ When I call the DbDataAdapter.Fill(DataSet, string); method, it doesn't 
+properly
+
+
+ add the primary key information. 
+
+
+
+
+Sample:
+
+
+  Tables:
+
+
+=========================================================
+
+
+if exists (select * from sysobjects where id = object_id('dbo.
+UCSCustomers') and sysstat & 0xf = 3)
+
+
+	drop table "dbo"."UCSCustomers"
+
+
+
+
+CREATE TABLE "UCSCustomers" (
+
+
+	"CustomerID" nchar (5) NOT NULL ,
+
+
+	"CompanyName" nvarchar (40) NOT NULL ,
+
+
+	"ContactName" nvarchar (30) NULL ,
+
+
+	"ContactTitle" nvarchar (30) NULL ,
+
+
+	"Address" nvarchar (60) NULL ,
+
+
+	"City" nvarchar (15) NULL ,
+
+
+	"Region" nvarchar (15) NULL ,
+
+
+	"PostalCode" nvarchar (10) NULL ,
+
+
+	"Country" nvarchar (15) NULL ,
+
+
+	"Phone" nvarchar (24) NULL ,
+
+
+	"Fax" nvarchar (24) NULL ,
+
+
+	CONSTRAINT "PK_Customers" PRIMARY KEY  CLUSTERED 
+
+
+	(
+
+
+		"CustomerID"
+
+
+	)
+
+
+)
+
+
+GO
+
+
+
+
+
+
+INSERT UCSCustomers VALUES('ALFKI','Alfreds Futterkiste','Maria Anders',
+'Sales Representative','Obere Str. 57','Berlin',NULL,'12209','Germany',
+'030-0074321','030-0076545')
+
+
+INSERT UCSCustomers VALUES('ANATR','Ana Trujillo Emparedados y helados',
+'Ana Trujillo','Owner','Avda. de la Constitucion 2222','Mexico D.F.',NULL,
+'05021','Mexico','(5) 555-4729','(5) 555-3745')
+
+
+INSERT UCSCustomers VALUES('VINET','Vins et alcools Chevalier','Paul 
+Henriot','Accounting Manager','59 rue de l''Abbaye','Reims',NULL,'51100',
+'France','26.47.15.10','26.47.15.11')
+
+
+INSERT UCSCustomers VALUES('TOMSP','Toms Spezialitaten','Karin Josephs',
+'Marketing Manager','Luisenstr. 48','Munster',NULL,'44087','Germany',
+'0251-031259','0251-035695')
+
+
+INSERT UCSCustomers VALUES('HANAR','Hanari Carnes','Mario Pontes',
+'Accounting Manager','Rua do Paco, 67','Rio de Janeiro','RJ','05454-876',
+'Brazil','(21) 555-0091','(21) 555-8765')
+
+
+INSERT UCSCustomers VALUES('VICTE','Victuailles en stock','Mary Saveley',
+'Sales Agent','2, rue du Commerce','Lyon',NULL,'69004','France','78.32.54.
+86','78.32.54.87')
+
+
+INSERT UCSCustomers VALUES('SUPRD','Supremes delices','Pascale Cartrain',
+'Accounting Manager','Boulevard Tirou, 255','Charleroi',NULL,'B-6000',
+'Belgium','(071) 23 67 22 20','(071) 23 67 22 21')
+
+
+GO
+
+
+
+
+
+
+
+
+
+
+if exists (select * from sysobjects where id = object_id('dbo.UCSOrders') 
+and sysstat & 0xf = 3)
+
+
+	drop table "dbo"."UCSOrders"
+
+
+
+
+CREATE TABLE "UCSOrders" (
+
+
+	"OrderID" "int" NOT NULL ,
+
+
+	"CustomerID" nchar (5) NULL ,
+
+
+	"EmployeeID" "int" NULL ,
+
+
+	"OrderDate" "datetime" NULL ,
+
+
+	"RequiredDate" "datetime" NULL ,
+
+
+	"ShippedDate" "datetime" NULL ,
+
+
+	"ShipVia" "int" NULL ,
+
+
+	"Freight" "money" NULL ,
+
+
+	"ShipName" nvarchar (40) NULL ,
+
+
+	"ShipAddress" nvarchar (60) NULL ,
+
+
+	"ShipCity" nvarchar (15) NULL ,
+
+
+	"ShipRegion" nvarchar (15) NULL ,
+
+
+	"ShipPostalCode" nvarchar (10) NULL ,
+
+
+	"ShipCountry" nvarchar (15) NULL ,
+
+
+	CONSTRAINT "PK_Orders" PRIMARY KEY  CLUSTERED 
+
+
+	(
+
+
+		"OrderID"
+
+
+	),
+
+
+)
+
+
+GO
+
+
+
+
+
+
+
+
+
+
+INSERT UCSOrders VALUES(10248, 'VINET', 5, '4/7/1996',  '8/1/1996',  
+'7/16/1996', 3, 32.38, 'Vins et alcools Chevalier', '59 rue de l'Abbaye', 
+'Reims', null, '51100', 'France')
+
+
+INSERT UCSOrders VALUES(10274, 'VINET', 6, '8/6/1996',  '9/3/1996',  
+'8/16/1996', 1, 6.01, 'Vins et alcools Chevalier', '59 rue de l'Abbaye', 
+'Reims', null, '51100', 'France')
+
+
+INSERT UCSOrders VALUES(10249, 'TOMSP', 6, '7/5/1996',  '8/16/1996', 
+'7/10/1996', 1, 11.61, 'Toms Spezialitaten', 'Luisenstr. 48', 'Munster', 
+null, '44087', 'Germany')
+
+
+INSERT UCSOrders VALUES(10438, 'TOMSP', 3, '2/6/1997',  '3/6/1997',  
+'2/14/1997', 2, 8.24, 'Toms Spezialitaten', 'Luisenstr. 48', 'Munster', 
+null, '44087', 'Germany')
+
+
+INSERT UCSOrders VALUES(10446, 'TOMSP', 6, '2/14/1996', '3/14/1996', 
+'2/19/1996', 1, 14.68, 'Toms Spezialitaten', 'Luisenstr. 48', 'Munster', 
+null, '44087', 'Germany')
+
+
+INSERT UCSOrders VALUES(10250, 'HANAR', 4, '7/8/1996',  '8/5/1996',  
+'7/12/1996', 2, 65.83, 'Hanari Carnes', 'Rua do Paco, 67', 'Rio de 
+Janeiro', 'RJ', '05454-876', 'Brazil')
+
+
+INSERT UCSOrders VALUES(10251, 'VICTE', 3, '7/8/1996',  '8/5/1996',  
+'7/15/1996', 1, 41.34, 'Victuailles en stock', '2, rue du Commerce', 
+'Lyon', null, '69004', 'France')
+
+
+INSERT UCSOrders VALUES(10334, 'VICTE', 8, '10/21/1996','11/18/1996',
+'10/28/1996', 2, 8.56, 'Victuailles en stock', '2, rue du Commerce', 
+'Lyon', null, '69004', 'France')
+
+
+INSERT UCSOrders VALUES(10252, 'SUPRD', 4, '7/9/1996',  '8/6/1996',  
+'7/11/1996', 2, 51.30, 'Supremes delices', 'Boulevard Triou, 255', 
+'Charleroi', null, 'B-6000', 'Belgium')
+
+
+INSERT UCSOrders VALUES(10643, 'ALFKI', 6, '8/25/1997', '9/22/1997', 
+'9/2/1997', 1, 29.46, 'Alfreds Futterkiste', 'Obere Str. 57', 'Berlin', 
+null, '12208', 'Germany')
+
+
+INSERT UCSOrders VALUES(10692, 'ALFKI', 4, '10/3/1997', '10/31/1997',
+'10/13/1997', 2, 61.02, 'Alfreds Futterkiste', 'Obere Str. 57', 'Berlin', 
+null, '12208', 'Germany')
+
+
+INSERT UCSOrders VALUES(10702, 'ALFKI', 4, '10/13/1997','11/24/1997',
+'10/21/1997', 1, 23.94, 'Alfreds Futterkiste', 'Obere Str. 57', 'Berlin', 
+null, '12208', 'Germany')
+
+
+INSERT UCSOrders VALUES(10835, 'ALFKI', 1, '1/15/1998', '2/12/1998', 
+'1/21/1998', 3, 69.53, 'Alfreds Futterkiste', 'Obere Str. 57', 'Berlin', 
+null, '12208', 'Germany')
+
+
+INSERT UCSOrders VALUES(10952, 'ALFKI', 1, '3/16/1998', '4/27/1998', 
+'3/24/1998', 1, 40.42, 'Alfreds Futterkiste', 'Obere Str. 57', 'Berlin', 
+null, '12208', 'Germany')
+
+
+INSERT UCSOrders VALUES(11011, 'ALFKI', 3, '4/9/1998',  '5/7/1998',  
+'4/13/1998', 1, 1.21, 'Alfreds Futterkiste', 'Obere Str. 57', 'Berlin', 
+null, '12208', 'Germany')
+
+
+INSERT UCSOrders VALUES(10926, 'ANATR', 4, '3/4/1998',  '4/1/1998',  
+'3/11/1998', 3, 39.92, 'Ana Trujillo Emparedados y ...', 'Avda. de la 
+Constitucion 2222', 'Mexico D.F.', null, '05021', 'Mexico')
+
+
+INSERT UCSOrders VALUES(10759, 'ANATR', 3, '11/28/1997','12/26/1997',
+'12/12/1997', 3, 11.99, 'Ana Trujillo Emparedados y ...', 'Avda. de la 
+Constitucion 2222', 'Mexico D.F.', null, '05021', 'Mexico')
+
+
+INSERT UCSOrders VALUES(10625, 'ANATR', 3, '8/8/1997',  '9/5/1997',  
+'8/14/1997', 1, 43.90, 'Ana Trujillo Emparedados y ...', 'Avda. de la 
+Constitucion 2222', 'Mexico D.F.', null, '05021', 'Mexico')
+
+
+INSERT UCSOrders VALUES(10308, 'ANATR', 7, '9/18/1996', '10/16/1996',
+'9/24/1996', 3, 1.61, 'Ana Trujillo Emparedados y ...', 'Avda. de la 
+Constitucion 2222', 'Mexico D.F.', null, '05021', 'Mexico')
+
+
+GO
+
+
+
+
+
+
+
+
+if exists (select * from sysobjects where id = object_id('dbo.UCSRegions') 
+and sysstat & 0xf = 3)
+
+
+	drop table "dbo"."UCSRegions"
+
+
+
+
+CREATE TABLE "UCSRegions" (
+
+
+	"RegionID" "int" NOT NULL ,
+
+
+	"RegionDescription" nvarchar (50) NULL ,
+
+
+	CONSTRAINT "PK_Regions" PRIMARY KEY  CLUSTERED 
+
+
+	(
+
+
+		"RegionID"
+
+
+	),
+
+
+)
+
+
+GO
+
+
+
+
+
+
+INSERT INTO UCSRegions VALUES(1, 'Eastern')
+
+
+INSERT INTO UCSRegions VALUES(2, 'Western')
+
+
+INSERT INTO UCSRegions VALUES(3, 'Northern')
+
+
+INSERT INTO UCSRegions VALUES(4, 'Southern')
+
+
+INSERT INTO UCSRegions VALUES(901, 'Alaskan wastelands')
+
+
+INSERT INTO UCSRegions VALUES(100, 'MidWestern')
+
+
+INSERT INTO UCSRegions VALUES(101, 'MidEastern')
+
+
+GO
+
+
+
+
+==========================================================
+
+
+   Program:
+
+
+==========================================================
+
+
+namespace Tests
+
+
+{
+
+
+
+
+using System;
+
+
+using System.Data;
+
+
+using System.Data.Common;
+
+
+using SQLServer = OpenLink.Data.SQLServer;
+
+
+
+
+public class DataAdapterUpdate1
+
+
+{
+
+
+  static string connStr = "SVT=SQLServer2000;DATABASE=pubs;UID=sa;
+Server=pcwin;PWD=;";
+
+
+
+
+  public static void Main ()
+
+
+  {
+
+
+    DataAdapterUpdate1 myDataAdapter = new DataAdapterUpdate1 ();
+
+
+    myDataAdapter.Run ();
+
+
+  }
+
+
+
+
+  public void Run ()
+
+
+  {
+
+
+    IDbConnection myConnection;
+
+
+    DbDataAdapter myDataAdapter;
+
+
+
+
+    myConnection = new SQLServer.OPLConnection (connStr);
+
+
+    myDataAdapter = new SQLServer.OPLDataAdapter(
+
+
+    	    "Select * from UCSRegions", (SQLServer.OPLConnection) 
+myConnection);
+
+
+
+
+    IDataParameter workParam = null;
+
+
+
+
+    // Restore database to it's original condition so sample will work 
+correctly.
+
+
+    Cleanup ();
+
+
+
+
+    // Build the insert Command
+
+
+    ((IDbDataAdapter)myDataAdapter).InsertCommand = myConnection.
+CreateCommand ();
+
+
+    ((IDbDataAdapter)myDataAdapter).InsertCommand.CommandText = "insert 
+into UCSRegions (RegionID, RegionDescription) VALUES (?, ?)";
+
+
+
+
+    workParam = ((IDbDataAdapter)myDataAdapter).InsertCommand.
+CreateParameter ();
+
+
+    workParam.ParameterName = "RegionID";
+
+
+    workParam.DbType = DbType.Int32;
+
+
+    workParam.SourceColumn = "RegionID";
+
+
+    workParam.SourceVersion = DataRowVersion.Current;
+
+
+    ((IDbDataAdapter)myDataAdapter).InsertCommand.Parameters.Add(workParam)
+; 
+
+
+
+
+
+
+    workParam = ((IDbDataAdapter)myDataAdapter).InsertCommand.
+CreateParameter ();
+
+
+    workParam.ParameterName = "RegionDescription";
+
+
+    workParam.DbType = DbType.String;
+
+
+    workParam.SourceColumn = "RegionDescription";
+
+
+    workParam.SourceVersion = DataRowVersion.Current;
+
+
+    ((IDbDataAdapter)myDataAdapter).InsertCommand.Parameters.Add 
+(workParam);
+
+
+
+
+    // Build the update command
+
+
+    ((IDbDataAdapter)myDataAdapter).UpdateCommand = myConnection.
+CreateCommand ();
+
+
+    ((IDbDataAdapter)myDataAdapter).UpdateCommand.CommandText = "update 
+UCSRegions set RegionDescription = ? WHERE RegionID = ?" ; 
+
+
+
+
+    workParam = ((IDbDataAdapter)myDataAdapter).UpdateCommand.
+CreateParameter ();
+
+
+    workParam.ParameterName = "RegionDescription";
+
+
+    workParam.DbType = DbType.String;
+
+
+    workParam.SourceVersion = DataRowVersion.Current;
+
+
+    workParam.SourceColumn = "RegionDescription";
+
+
+    ((IDbDataAdapter)myDataAdapter).UpdateCommand.Parameters.Add 
+(workParam);
+
+
+		
+
+
+    workParam = ((IDbDataAdapter)myDataAdapter).UpdateCommand.
+CreateParameter ();
+
+
+    workParam.ParameterName = "RegionID";
+
+
+    workParam.DbType = DbType.Int32;
+
+
+    workParam.SourceColumn = "RegionID";
+
+
+    workParam.SourceVersion = DataRowVersion.Original;
+
+
+    ((IDbDataAdapter)myDataAdapter).UpdateCommand.Parameters.Add 
+(workParam);
+
+
+
+
+    DataSet myDataSet = new DataSet();
+
+
+
+
+    // Set the MissingSchemaAction property to AddWithKey because Fill will
+
+
+    // not cause primary key & unique key information to be retrieved 
+unless
+
+
+    // AddWithKey is specified.
+
+
+    myDataAdapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;
+
+
+    myDataAdapter.Fill (myDataSet, "UCSRegions");
+
+
+
+
+    DataRow myDataRow1 = myDataSet.Tables["UCSRegions"].Rows.Find (2);
+
+
+    myDataRow1[1] = "Changed this region desc";
+
+
+
+
+    DataRow myDataRow2 = myDataSet.Tables["UCSRegions"].NewRow ();
+
+
+    myDataRow2[0] = 901;
+
+
+    myDataRow2[1] = "A new region";
+
+
+    myDataSet.Tables["UCSRegions"].Rows.Add (myDataRow2);
+
+
+
+
+    try
+
+
+    {
+
+
+      myDataAdapter.Update(myDataSet, "UCSRegions");
+
+
+      Console.Write("Updating DataSet succeeded!");
+
+
+    }
+
+
+    catch(Exception e)
+
+
+    {
+
+
+      Console.Write(e.ToString());
+
+
+    }
+
+
+  }
+
+
+
+
+  public void Cleanup()
+
+
+  {
+
+
+    IDbConnection myConnection;
+
+
+
+
+    myConnection = new SQLServer.OPLConnection (connStr);
+
+
+
+
+    try
+
+
+    {
+
+
+      // Restore database to it's original condition so test app will work 
+
+
+      // correctly.
+
+
+      myConnection.Open ();
+
+
+      IDbCommand CleanupCommand = myConnection.CreateCommand ();
+
+
+      CleanupCommand.CommandText = 
+
+
+	"DELETE FROM UCSRegions WHERE RegionID = 901";
+
+
+      CleanupCommand.ExecuteNonQuery();
+
+
+    }
+
+
+    catch (Exception e)
+
+
+    {
+
+
+      Console.Write(e.ToString());
+
+
+    }
+
+
+    finally
+
+
+    {
+
+
+      myConnection.Close();
+
+
+    }
+
+
+  }
+
+
+}
+
+
+
+
+}