Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
OleDbDatabase.cs
1using System;
2using System.Collections.Generic;
3using System.Data;
4using System.Data.Common;
5using System.Data.OleDb;
6using System.Threading.Tasks;
10
12{
17 {
18 private readonly Dictionary<string, OleDbStoredProcedure> procedures = new Dictionary<string, OleDbStoredProcedure>();
19 private readonly MultiReadSingleWriteObject synchObject;
20 private OleDbConnection connection;
21
26 public OleDbDatabase(OleDbConnection Connection)
27 {
28 this.synchObject = new MultiReadSingleWriteObject(this);
29 this.connection = Connection;
30 }
31
35 public override void Dispose()
36 {
37 this.connection?.Close();
38 this.connection?.Dispose();
39 this.connection = null;
40 }
41
47 public override async Task<IElement> ExecuteSqlStatement(string Statement)
48 {
49 using (OleDbCommand Command = this.connection.CreateCommand())
50 {
51 Command.CommandType = CommandType.Text;
52 Command.CommandText = Statement;
53 DbDataReader Reader = await Command.ExecuteReaderAsync();
54
55 return await Reader.ParseAndClose();
56 }
57 }
58
65 public override Task<IElement> GetSchema(string Name)
66 {
67 DataTable Table = this.connection.GetSchema(Name);
68 return Task.FromResult<IElement>(Table.ToMatrix());
69 }
70
76 public override async Task<ILambdaExpression> GetProcedure(string Name)
77 {
78 await this.synchObject.BeginWrite();
79 try
80 {
81 if (this.procedures.TryGetValue(Name, out OleDbStoredProcedure Result))
82 return Result;
83
84 OleDbCommand Command = this.connection.CreateCommand();
85 Command.CommandType = CommandType.StoredProcedure;
86 Command.CommandText = this.connection.Database + "." + Name;
87
88 OleDbCommandBuilder.DeriveParameters(Command);
89
90 Result = new OleDbStoredProcedure(Command);
91 this.procedures[Name] = Result;
92
93 return Result;
94 }
95 finally
96 {
97 await this.synchObject.EndWrite();
98 }
99 }
100 }
101}
Represents an object that allows single concurrent writers but multiple concurrent readers....
Abstract base class for external databases
Manages an OLE DB SQL Server connection
override void Dispose()
IDisposable.Dispose
OleDbDatabase(OleDbConnection Connection)
Manages an OLE DB SQL Server connection
override async Task< IElement > ExecuteSqlStatement(string Statement)
Executes an SQL Statement on the database.
override Task< IElement > GetSchema(string Name)
Gets a Schema table, given its collection name. For a list of collections: https://mysqlconnector....
override async Task< ILambdaExpression > GetProcedure(string Name)
Creates a lambda expression for accessing a stored procedure.
Represents a stored precedure in an OLE DB Database.
Basic interface for all types of elements.
Definition: IElement.cs:20