From 444f8ff97a0d3dccec932c07fb5db1414389f25d Mon Sep 17 00:00:00 2001 From: inga-lovinde <52715130+inga-lovinde@users.noreply.github.com> Date: Sun, 6 Jun 2010 17:36:24 +0000 Subject: [PATCH] MySQLConnector implemented; not tested --- Common/Common.csproj | 4 + Core/Core.csproj | 1 + Core/DB/ColumnOrValue.cs | 2 +- Core/DB/Diapasone.cs | 4 +- Core/DB/IDBConnection.cs | 38 +++- Core/DB/JoinSpec.cs | 2 +- Core/DB/SortSpec.cs | 2 +- Core/DB/{ITransaction.cs => Transaction.cs} | 13 +- Core/DB/conditions/ComparisonCondition.cs | 2 +- Core/DB/conditions/ComparisonType.cs | 2 +- Core/DB/conditions/ComplexCondition.cs | 2 +- Core/DB/conditions/ConditionsJoinType.cs | 2 +- Core/DB/conditions/MultiValueCondition.cs | 2 +- Core/exceptions/NotFoundInDBException.cs | 14 ++ FLocal.sln | 6 + IISMainHandler/IISMainHandler.csproj | 4 + MySQLConnector/ConditionCompiler.cs | 114 ++++++++++ MySQLConnector/Connection.cs | 217 ++++++++++++++++++++ MySQLConnector/Extensions.cs | 19 ++ MySQLConnector/MySQLConnector.csproj | 70 +++++++ MySQLConnector/ParamsHolder.cs | 23 +++ MySQLConnector/Properties/AssemblyInfo.cs | 36 ++++ MySQLConnector/Transaction.cs | 52 +++++ 23 files changed, 608 insertions(+), 23 deletions(-) rename Core/DB/{ITransaction.cs => Transaction.cs} (60%) create mode 100644 Core/exceptions/NotFoundInDBException.cs create mode 100644 MySQLConnector/ConditionCompiler.cs create mode 100644 MySQLConnector/Connection.cs create mode 100644 MySQLConnector/Extensions.cs create mode 100644 MySQLConnector/MySQLConnector.csproj create mode 100644 MySQLConnector/ParamsHolder.cs create mode 100644 MySQLConnector/Properties/AssemblyInfo.cs create mode 100644 MySQLConnector/Transaction.cs diff --git a/Common/Common.csproj b/Common/Common.csproj index b276843..af20f39 100644 --- a/Common/Common.csproj +++ b/Common/Common.csproj @@ -53,6 +53,10 @@ {6F532626-E9F8-498E-9683-1538E7CD62CB} Core + + {E38DE5B1-F9C2-43BA-A5DF-0743ABD4DFC7} + MySQLConnector + + \ No newline at end of file diff --git a/MySQLConnector/ParamsHolder.cs b/MySQLConnector/ParamsHolder.cs new file mode 100644 index 0000000..08c9511 --- /dev/null +++ b/MySQLConnector/ParamsHolder.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace FLocal.MySQLConnector { + class ParamsHolder { + + public Dictionary data = new Dictionary(); + + private int index = 1; + + public string Add(string value) { + lock(this) { + string name = "param" + index; + this.data.Add(name, value); + this.index++; + return name; + } + } + + } +} diff --git a/MySQLConnector/Properties/AssemblyInfo.cs b/MySQLConnector/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..e67fbbe --- /dev/null +++ b/MySQLConnector/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("MySQLConnector")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Microsoft")] +[assembly: AssemblyProduct("MySQLConnector")] +[assembly: AssemblyCopyright("Copyright © Microsoft 2010")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("b1f8928c-947d-45e1-a6e8-e758c1985a5c")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/MySQLConnector/Transaction.cs b/MySQLConnector/Transaction.cs new file mode 100644 index 0000000..0fe0c45 --- /dev/null +++ b/MySQLConnector/Transaction.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data.MySqlClient; +using FLocal.Core; + +namespace FLocal.MySQLConnector { + class Transaction : Core.DB.Transaction { + + internal MySqlConnection sqlconnection; + internal MySqlTransaction sqltransaction; + + public bool finalizedImpl { + get; + private set; + } + + public Transaction(Connection connection, System.Data.IsolationLevel iso) : base() { + this.sqlconnection = connection.createConnection(); + try { + this.sqltransaction = this.sqlconnection.BeginTransaction(iso); + } catch(Exception e) { + this.close(); + throw e; + } + } + + protected override void do_Commit() { + lock(this) { + if(this.finalizedImpl) throw new CriticalException("Already finalized"); + this.sqltransaction.Commit(); + this.close(); + } + } + + protected override void do_Rollback() { + lock(this) { + if(this.finalizedImpl) throw new CriticalException("Already finalized"); + this.sqltransaction.Rollback(); + this.close(); + } + } + + private void close() { + this.sqlconnection.Close(); + this.sqlconnection.Dispose(); + this.finalizedImpl = true; + } + + } +}