Represents set of UniSQL macros.
The following example demonstrates how to make table name dependent on current connection. This goal is achieved by declaring collection of two macros, one for Oracle and another for MySQL.
UniConnection conn = new UniConnection();
//Connecting to Oracle server through OraDirect .NET
conn.ConnectionString = "provider=OraDirect;Password=tiger;User Id=Scott;Host=ora920;";
//Define macros for tables dept
UniMacro mac = new UniMacro("tablename", "test.dept", "MySQL");
conn.Macros.Add(mac);
UniMacro mac2 = new UniMacro("tablename", "dept", "Oracle");
conn.Macros.Add(mac2);
//Define query that uses the macro
UniCommand cmd = new UniCommand("SELECT Count(*) FROM {tablename}");
cmd.Connection = conn;
conn.Open();
try {
//Run the query and make sure it is executed correctly
string response = cmd.ExecuteScalar().ToString();
MessageBox.Show(response);
}
finally {
conn.Close();
}
Dim conn As New UniConnection()
'Connecting to Oracle server through OraDirect .NET
conn.ConnectionString = "provider=OraDirect;Password=tiger;User Id=Scott;Host=ora920;"
'Define macro for table dept
Dim mac As New UniMacro("tablename", "test.dept", "MySQL")
conn.Macros.Add(mac)
Dim mac2 As New UniMacro("tablename", "dept", "Oracle")
conn.Macros.Add(mac2)
'Define query that uses the macro
Dim cmd As New UniCommand("SELECT Count(*) FROM {tablename}")
cmd.Connection = conn
conn.Open()
Try
'Run the query and make sure it is executed correctly
Dim response As String = cmd.ExecuteScalar().ToString()
MessageBox.Show(response)
Finally
conn.Close()
End Try
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2