I have an unknown connection being passed in, through the base DbConnection
, it could be MySQL, SQLite, Oracle, SQL Server, Access, I don't know.
I need to pull the quoted identifiers out of the schema information, I've figured out how to get the quoted identifiers, but it comes back in a RegEx, and I'm not familiar enough with RegEx to be able to parse these dynamically.
Given the C# code:
public class DatabaseHelper
{
internal char LeftIdentifier { get; private set; }
internal char RightIdentifier { get; private set; }
private void SetQuotedIdentifiers(DbConnection connection)
{
string quotedIdentifier = connection.GetSchema("DataSourceInformation").Rows[0]["QuotedIdentifierPattern"].ToString();
LeftIdentifier = null; // some code I have to figure out
RightIdentifier = null; // some code I have to figure out
}
}
I need help setting the values of LeftIdentifier
, and RightIdentifier
.
If I run that code, with an Oracle connection, quotedIdentifier
comes back with the following result:
(([^\"]\"\")*)
I want to set LeftIdentifier
in this case equal to " and RightIdentifier
also to "
If I run that code, with a SQL Server connection, quotedIdentifier
comes back with the following result:
(([^\\[]|\\]\\])*)
In this case, I want to set LeftIdentifier
to [ and RightIdentifier equal to ]
Can anyone help with the code needed for this? I'm hitting a stumbling block with everything I'm trying.
Note: I got the information for the function from this MSDN article.
Turn on Ignore Pattern whitespace for this pattern. Here I have escaped the identifiers as the hex values.
or as a single line without the ignore
Will match
"abc" [abc] (ab)
and returns the text abc in the named capture group named Text.