From: Date: February 27 2007 9:06pm Subject: Connector/NET commit: r613 - in branches/5.0: . Driver/Source TestSuite List-Archive: http://lists.mysql.com/commits/20687 X-Bug: 26660 Message-Id: <200702272006.l1RK67Vi008847@bk-internal.mysql.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Modified: branches/5.0/CHANGES branches/5.0/Driver/Source/SchemaProvider.cs branches/5.0/TestSuite/GetSchemaTests.cs Log: Bug #26660 MySqlConnection.GetSchema fails with NullReferenceException for Foreign Keys Added code to protect against the situation where the user passes in either a null restriction array or an array that is not long enough. Modified: branches/5.0/CHANGES =================================================================== --- branches/5.0/CHANGES 2007-02-27 19:47:59 UTC (rev 612) +++ branches/5.0/CHANGES 2007-02-27 20:06:06 UTC (rev 613) @@ -21,6 +21,7 @@ Bug #24373 High CPU utilization when no idle connection Bug #24957 MySql.Data.Types.MySqlConversionException is not marked as Serializable. Bug #25603 Critial ConnectionPool Error in Connector.Net 5.03 + Bug #26660 MySqlConnection.GetSchema fails with NullReferenceException for Foreign Keys Other changes ------------- Modified: branches/5.0/Driver/Source/SchemaProvider.cs =================================================================== --- branches/5.0/Driver/Source/SchemaProvider.cs 2007-02-27 19:47:59 UTC (rev 612) +++ branches/5.0/Driver/Source/SchemaProvider.cs 2007-02-27 20:06:06 UTC (rev 613) @@ -360,8 +360,12 @@ // first we use our restrictions to get a list of tables that should be // consulted. We save the keyname restriction since GetTables doesn't // understand that. - string keyName = restrictions[3]; - restrictions[3] = null; + string keyName = null; + if (restrictions != null && restrictions.Length >= 4) + { + keyName = restrictions[3]; + restrictions[3] = null; + } DataTable tables = GetTables(restrictions); // now for each table retrieved, we call our helper function to @@ -579,7 +583,7 @@ connection.Settings.UseOldSyntax ? "@" : "?"); row["ParameterNameMaxLength"] = 128; row["ParameterNamePattern"] = @"^[\p{Lo}\p{Lu}\p{Ll}\p{Lm}_@#][\p{Lo}\p{Lu}\p{Ll}\p{Lm}\p{Nd}\uff3f_@#\$]*(?=\s+|$)"; - row["QuotedIdentifierPattern"] = @"(([^\[]|\]\])*)"; + row["QuotedIdentifierPattern"] = @"(([^\`]|\`\`)*)"; row["QuotedIdentifierCase"] = IdentifierCase.Insensitive; row["StatementSeparatorPattern"] = ";"; row["StringLiteralPattern"] = "'(([^']|'')*)'"; Modified: branches/5.0/TestSuite/GetSchemaTests.cs =================================================================== --- branches/5.0/TestSuite/GetSchemaTests.cs 2007-02-27 19:47:59 UTC (rev 612) +++ branches/5.0/TestSuite/GetSchemaTests.cs 2007-02-27 20:06:06 UTC (rev 613) @@ -499,7 +499,36 @@ Assert.AreEqual("id", row["REFERENCED_COLUMN_NAME"]); } + /// + /// Bug #26660 MySqlConnection.GetSchema fails with NullReferenceException for Foreign Keys + /// [Test] + public void ForeignKeys() + { + execSQL("DROP TABLE IF EXISTS product_order"); + execSQL("DROP TABLE IF EXISTS product"); + execSQL("DROP TABLE IF EXISTS customer"); + execSQL("CREATE TABLE product (category INT NOT NULL, id INT NOT NULL, " + + "price DECIMAL, PRIMARY KEY(category, id)) TYPE=INNODB"); + execSQL("CREATE TABLE customer (id INT NOT NULL, PRIMARY KEY (id)) TYPE=INNODB"); + execSQL("CREATE TABLE product_order (no INT NOT NULL AUTO_INCREMENT, " + + "product_category INT NOT NULL, product_id INT NOT NULL, customer_id INT NOT NULL, " + + "PRIMARY KEY(no), INDEX (product_category, product_id), " + + "FOREIGN KEY (product_category, product_id) REFERENCES product(category, id) " + + "ON UPDATE CASCADE ON DELETE RESTRICT, INDEX (customer_id), " + + "FOREIGN KEY (customer_id) REFERENCES customer(id)) TYPE=INNODB"); + + try + { + DataTable dt = conn.GetSchema("Foreign Keys"); + } + catch (Exception ex) + { + Assert.Fail(ex.Message); + } + } + + [Test] public void MultiSingleForeignKey() { execSQL("DROP TABLE IF EXISTS product_order");