MySql.Data.MySqlClient.SchemaProvider.GetForeignKeysOnTable C# (CSharp) Method

GetForeignKeysOnTable() private method

GetForeignKeysOnTable retrieves the foreign keys on the given table. Since MySQL supports foreign keys on versions prior to 5.0, we can't use information schema. MySQL also does not include any type of SHOW command for foreign keys so we have to resort to use SHOW CREATE TABLE and parsing the output.
private GetForeignKeysOnTable ( DataTable fkTable, DataRow tableToParse, string filterName, bool includeColumns ) : void
fkTable System.Data.DataTable The table to store the key info in.
tableToParse System.Data.DataRow The table to get the foeign key info for.
filterName string Only get foreign keys that match this name.
includeColumns bool Should column information be included in the table.
return void
        private void GetForeignKeysOnTable(DataTable fkTable, DataRow tableToParse,
                                           string filterName, bool includeColumns)
        {
            string sqlMode = GetSqlMode();

            if (filterName != null)
                filterName = filterName.ToLower(CultureInfo.InvariantCulture);

            string sql = string.Format("SHOW CREATE TABLE `{0}`.`{1}`",
                                       tableToParse["TABLE_SCHEMA"], tableToParse["TABLE_NAME"]);
            string lowerBody = null, body = null;
            MySqlCommand cmd = new MySqlCommand(sql, connection);
            using (MySqlDataReader reader = cmd.ExecuteReader())
            {
                reader.Read();
                body = reader.GetString(1);
                lowerBody = body.ToLower(CultureInfo.InvariantCulture);
            }

            MySqlTokenizer tokenizer = new MySqlTokenizer(lowerBody);
            tokenizer.AnsiQuotes = sqlMode.IndexOf("ANSI_QUOTES") != -1;
            tokenizer.BackslashEscapes = sqlMode.IndexOf("NO_BACKSLASH_ESCAPES") != -1;
            
            while (true)
            {
                string token = tokenizer.NextToken();
                // look for a starting contraint
                while (token != null && (token != "constraint" || tokenizer.Quoted))
                    token = tokenizer.NextToken();
                if (token == null) break;

                ParseConstraint(fkTable, tableToParse, tokenizer, includeColumns);
            }
        }