Value Property (UniMacro)
On this page
Gets or sets macro value.
Syntax
|
|---|
'Declaration
Public Property Value As String |
|
|---|
public string Value {get; set;} |
Property Value
A string expression that macro evaluates to, if
Condition is enabled.
Example
This example shows how to build a complex FROM clause depending on what DBMS is used.
|
|---|
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 |
See Also