public virtual DataTable GetDatabases(string[] restrictions)
{
Regex regex = null;
int caseSetting = Int32.Parse(connection.driver.Property("lower_case_table_names"));
string sql = "SHOW DATABASES";
// if lower_case_table_names is zero, then case lookup should be sensitive
// so we can use LIKE to do the matching.
if (caseSetting == 0)
{
if (restrictions != null && restrictions.Length >= 1)
sql = sql + " LIKE '" + restrictions[0] + "'";
}
else if (restrictions != null && restrictions.Length >= 1 && restrictions[0] != null)
regex = new Regex(restrictions[0], RegexOptions.IgnoreCase);
MySqlDataAdapter da = new MySqlDataAdapter(sql, connection);
DataTable dt = new DataTable();
da.Fill(dt);
DataTable table = new DataTable("Databases");
table.Columns.Add("CATALOG_NAME", typeof (string));
table.Columns.Add("SCHEMA_NAME", typeof (string));
foreach (DataRow row in dt.Rows)
{
if (caseSetting != 0 && regex != null &&
!regex.Match(row[0].ToString()).Success) continue;
DataRow newRow = table.NewRow();
newRow[1] = row[0];
table.Rows.Add(newRow);
}
return table;
}