UniConnection conn = new UniConnection(); //Connecting to MySQL server through MySQLDirect .NET conn.ConnectionString = "provider=MySQL;Password=root;User Id=root;Host=localhost;Port=3307;"; //Define table name for all databases (blank condition) //Note the single-line macro creation in the collection conn.Macros.Add("tablename", "emp"); //For MySQL, prepend database name conn.Macros.Add("tablename", "test.emp", "MySQL"); //Limit records count where it is easy (MySQL and PostgreSQL) conn.Macros.Add("limit", "LIMIT 0,5", "mysql"); conn.Macros.Add("limit", "LIMIT 5 OFFSET 0", "PostgreSQL"); //Define default FROM clause conn.Macros.Add("from", "FROM {tablename}"); //If the limit macro is defined, add extra clause conn.Macros.Add("from", "FROM {tablename} {limit}", "limit"); //Define query that uses the macro UniCommand cmd = new UniCommand("SELECT EName, Job, Sal {from}"); cmd.Connection = conn; conn.Open(); try { UniDataReader dataReader = cmd.ExecuteReader(); ... dataReader.Close(); } finally { conn.Close(); }
Dim conn As New UniConnection() 'Connecting to MySQL server through MySQLDirect .NET conn.ConnectionString = "provider=MySQL;Password=root;User Id=root;Host=localhost;Port=3307;" 'Define table name for all databases (blank condition) 'Note the single-line macro creation in the collection conn.Macros.Add("tablename", "emp") 'For MySQL, prepend database name conn.Macros.Add("tablename", "test.emp", "MySQL") 'Limit records count where it is easy (MySQL and PostgreSQL) conn.Macros.Add("limit", "LIMIT 0,5", "mysql") conn.Macros.Add("limit", "LIMIT 5 OFFSET 0", "PostgreSQL") 'Define default FROM clause conn.Macros.Add("from", "FROM {tablename}") 'If the limit macro is defined, add extra clause conn.Macros.Add("from", "FROM {tablename} {limit}", "limit") 'Define query that uses the macro Dim cmd As New UniCommand("SELECT EName, Job, Sal {from}") 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() Dim dataReader As UniDataReader = cmd.ExecuteReader() ... dataReader.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