private DataTable GetViewColumns(string[] restrictions)
{
StringBuilder where = new StringBuilder();
StringBuilder sql = new StringBuilder(
"SELECT C.* FROM information_schema.columns C");
sql.Append(" JOIN information_schema.views V ");
sql.Append("ON C.table_schema=V.table_schema AND C.table_name=V.table_name ");
if (restrictions != null && restrictions.Length >= 2 &&
restrictions[1] != null)
where.AppendFormat(CultureInfo.InvariantCulture, "C.table_schema='{0}' ", restrictions[1]);
if (restrictions != null && restrictions.Length >= 3 &&
restrictions[2] != null)
{
if (where.Length > 0)
where.Append("AND ");
where.AppendFormat(CultureInfo.InvariantCulture, "C.table_name='{0}' ", restrictions[2]);
}
if (restrictions != null && restrictions.Length == 4 &&
restrictions[3] != null)
{
if (where.Length > 0)
where.Append("AND ");
where.AppendFormat(CultureInfo.InvariantCulture, "C.column_name='{0}' ", restrictions[3]);
}
if (where.Length > 0)
sql.AppendFormat(CultureInfo.InvariantCulture, " WHERE {0}", where);
DataTable dt = GetTable(sql.ToString());
dt.TableName = "ViewColumns";
dt.Columns[0].ColumnName = "VIEW_CATALOG";
dt.Columns[1].ColumnName = "VIEW_SCHEMA";
dt.Columns[2].ColumnName = "VIEW_NAME";
return dt;
}