|
|
|
|
@ -2,29 +2,26 @@
|
|
|
|
|
|
|
|
|
|
namespace System.Data.Jet.JetStoreSchemaDefinition
|
|
|
|
|
{
|
|
|
|
|
class JetRenameHandling
|
|
|
|
|
internal class JetRenameHandling
|
|
|
|
|
{
|
|
|
|
|
private static Regex _renameTableRegex = new Regex(
|
|
|
|
|
$@"^\s*rename\s+table\s+{GetQuotedOrUnquotedNamePattern("tableName")}\s+to\s+{GetQuotedOrUnquotedNamePattern("newTableName")}\s*$",
|
|
|
|
|
private static readonly Regex _renameTableRegex = new Regex(
|
|
|
|
|
$@"^\s*rename\s+table\s+{GetIdentifierPattern("OldTableName")}\s+to\s+{GetIdentifierPattern("NewTableName")}\s*$",
|
|
|
|
|
RegexOptions.IgnoreCase);
|
|
|
|
|
|
|
|
|
|
private static Regex _renameTableColumnRegex = new Regex(
|
|
|
|
|
$@"^\s*rename\s+column\s+{GetQuotedOrUnquotedNamePattern("tableName")}\.{GetQuotedOrUnquotedNamePattern("columnName")}\s+to\s+{GetQuotedOrUnquotedNamePattern("newColumnName")}\s*$",
|
|
|
|
|
private static readonly Regex _renameTableColumnRegex = new Regex(
|
|
|
|
|
$@"^\s*rename\s+column\s+{GetIdentifierPattern("TableName")}\s*\.\s*{GetIdentifierPattern("OldColumnName")}\s+to\s+{GetIdentifierPattern("NewColumnName")}\s*$",
|
|
|
|
|
RegexOptions.IgnoreCase);
|
|
|
|
|
|
|
|
|
|
public static bool TryDatabaseOperation(string connectionString, string commandText)
|
|
|
|
|
{
|
|
|
|
|
Match match;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
match = _renameTableRegex.Match(commandText);
|
|
|
|
|
var match = _renameTableRegex.Match(commandText);
|
|
|
|
|
if (match.Success)
|
|
|
|
|
{
|
|
|
|
|
string tableName = match.Groups["tableName"].Value;
|
|
|
|
|
string newTableName = match.Groups["newTableName"].Value;
|
|
|
|
|
var oldTableName = match.Groups["OldTableName"].Value;
|
|
|
|
|
var newTableName = match.Groups["NewTableName"].Value;
|
|
|
|
|
|
|
|
|
|
// TODO: Only use ADOX in an OLE DB context. Use DAO in an ODBC context.
|
|
|
|
|
AdoxWrapper.RenameTable(connectionString, RemoveBrackets(tableName), RemoveBrackets(newTableName));
|
|
|
|
|
AdoxWrapper.RenameTable(connectionString, oldTableName, newTableName);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
@ -32,28 +29,20 @@ namespace System.Data.Jet.JetStoreSchemaDefinition
|
|
|
|
|
match = _renameTableColumnRegex.Match(commandText);
|
|
|
|
|
if (match.Success)
|
|
|
|
|
{
|
|
|
|
|
string tableName = match.Groups["tableName"].Value;
|
|
|
|
|
string columnName = match.Groups["columnName"].Value;
|
|
|
|
|
string newColumnName = match.Groups["newColumnName"].Value;
|
|
|
|
|
AdoxWrapper.RenameColumn(connectionString, RemoveBrackets(tableName), RemoveBrackets(columnName), RemoveBrackets(newColumnName));
|
|
|
|
|
var tableName = match.Groups["TableName"].Value;
|
|
|
|
|
var oldColumnName = match.Groups["OldColumnName"].Value;
|
|
|
|
|
var newColumnName = match.Groups["NewColumnName"].Value;
|
|
|
|
|
|
|
|
|
|
// TODO: Only use ADOX in an OLE DB context. Use DAO in an ODBC context.
|
|
|
|
|
AdoxWrapper.RenameColumn(connectionString, tableName, oldColumnName, newColumnName);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static string RemoveBrackets(string name)
|
|
|
|
|
{
|
|
|
|
|
if (name.StartsWith("[") && name.EndsWith("]"))
|
|
|
|
|
return name.Substring(1, name.Length - 2);
|
|
|
|
|
else
|
|
|
|
|
return name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static string GetQuotedOrUnquotedNamePattern(string key)
|
|
|
|
|
{
|
|
|
|
|
return $@"((?<{key}>\S*)|\[(?<{key}>.*)\])";
|
|
|
|
|
}
|
|
|
|
|
private static string GetIdentifierPattern(string key)
|
|
|
|
|
=> $@"(?:`(?<{key}>.*?)`|\[(?<{key}>.*?)\]|(?<{key}>\S*))";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|