dotConnect Universal Documentation
Devart.Data.Universal Namespace / UniMacroCollection Class
Members Example

In This Topic
    UniMacroCollection Class
    In This Topic
    Represents set of UniSQL macros.
    Syntax
    Remarks

    The UniMacroCollection class represents set of custom macros that can be used while executing UniSQL statements. For information on UniSQL and using macros please refer to article UniSQL.

    Individual macros are accessed through UniConnection.Macros property of UniConnection. Each UniConnection object has its own collection of macros.

    Example
    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
    Inheritance Hierarchy

    System.Object
       System.Collections.CollectionBase
          Devart.Data.Universal.UniMacroCollection

    Requirements

    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

    See Also