Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
ConnectOdbc.cs
1using System;
2using System.Data.Odbc;
3using System.Security;
4using System.Threading.Tasks;
9
11{
16 {
24 public ConnectOdbc(ScriptNode ConnectionString, int Start, int Length, Expression Expression)
25 : base(new ScriptNode[] { ConnectionString }, argumentTypes1Scalar, Start, Length, Expression)
26 {
27 }
28
38 public ConnectOdbc(ScriptNode ConnectionString, ScriptNode UserName, ScriptNode Password, int Start, int Length, Expression Expression)
39 : base(new ScriptNode[] { ConnectionString, UserName, Password }, argumentTypes3Scalar, Start, Length, Expression)
40 {
41 }
42
46 public override string FunctionName => nameof(ConnectOdbc);
47
51 public override string[] DefaultArgumentNames => new string[] { "ConnectionString", "UserName", "Password" };
52
57 public override bool IsAsynchronous => true;
58
66 {
67 return this.EvaluateAsync(Arguments, Variables).Result;
68 }
69
76 public override async Task<IElement> EvaluateAsync(IElement[] Arguments, Variables Variables)
77 {
78 string ConnectionString = Arguments[0].AssociatedObjectValue?.ToString() ?? string.Empty;
79 OdbcConnection Connection;
80
81 switch (Arguments.Length)
82 {
83 case 1:
84 default:
85 Connection = new OdbcConnection(ConnectionString);
86 break;
87
88 case 3:
89 string UserName = Arguments[1].AssociatedObjectValue?.ToString() ?? string.Empty;
90 string Password = Arguments[2].AssociatedObjectValue?.ToString() ?? string.Empty;
91
92 ConnectionString = ConnectionString.Trim();
93 if (!ConnectionString.EndsWith(";"))
94 ConnectionString += ";";
95
96 ConnectionString += "User Id=" + UserName + ";Password=" + Password + ";";
97 Connection = new OdbcConnection(ConnectionString);
98 break;
99 }
100
101 await Connection.OpenAsync();
102
103 return new ObjectValue(new OdbcDatabase(Connection));
104 }
105 }
106}
Creates a connection to an external ODBC database.
Definition: ConnectOdbc.cs:16
ConnectOdbc(ScriptNode ConnectionString, ScriptNode UserName, ScriptNode Password, int Start, int Length, Expression Expression)
Creates a connection to an external ODBC database.
Definition: ConnectOdbc.cs:38
override async Task< IElement > EvaluateAsync(IElement[] Arguments, Variables Variables)
Evaluates the function.
Definition: ConnectOdbc.cs:76
override string[] DefaultArgumentNames
Default Argument names
Definition: ConnectOdbc.cs:51
override bool IsAsynchronous
If the node (or its decendants) include asynchronous evaluation. Asynchronous nodes should be evaluat...
Definition: ConnectOdbc.cs:57
ConnectOdbc(ScriptNode ConnectionString, int Start, int Length, Expression Expression)
Creates a connection to an external ODBC database.
Definition: ConnectOdbc.cs:24
override IElement Evaluate(IElement[] Arguments, Variables Variables)
Evaluates the function.
Definition: ConnectOdbc.cs:65
override string FunctionName
Name of the function
Definition: ConnectOdbc.cs:46
Manages an ODBC SQL connection
Definition: OdbcDatabase.cs:17
Class managing a script expression.
Definition: Expression.cs:39
Base class for multivariate funcions.
ScriptNode[] Arguments
Function arguments.
static readonly ArgumentType[] argumentTypes3Scalar
Three scalar parameters.
static readonly ArgumentType[] argumentTypes1Scalar
One scalar parameter.
Base class for all nodes in a parsed script tree.
Definition: ScriptNode.cs:69
int Length
Length of expression covered by node.
Definition: ScriptNode.cs:101
override string ToString()
Definition: ScriptNode.cs:359
Expression Expression
Expression of which the node is a part.
Definition: ScriptNode.cs:177
int Start
Start position in script expression.
Definition: ScriptNode.cs:92
Collection of variables.
Definition: Variables.cs:25
Basic interface for all types of elements.
Definition: IElement.cs:20