MySQLConnector implemented; not tested

main
Inga 🏳‍🌈 15 years ago
parent 7542f5737d
commit 444f8ff97a
  1. 4
      Common/Common.csproj
  2. 1
      Core/Core.csproj
  3. 2
      Core/DB/ColumnOrValue.cs
  4. 4
      Core/DB/Diapasone.cs
  5. 38
      Core/DB/IDBConnection.cs
  6. 2
      Core/DB/JoinSpec.cs
  7. 2
      Core/DB/SortSpec.cs
  8. 13
      Core/DB/Transaction.cs
  9. 2
      Core/DB/conditions/ComparisonCondition.cs
  10. 2
      Core/DB/conditions/ComparisonType.cs
  11. 2
      Core/DB/conditions/ComplexCondition.cs
  12. 2
      Core/DB/conditions/ConditionsJoinType.cs
  13. 2
      Core/DB/conditions/MultiValueCondition.cs
  14. 14
      Core/exceptions/NotFoundInDBException.cs
  15. 6
      FLocal.sln
  16. 4
      IISMainHandler/IISMainHandler.csproj
  17. 114
      MySQLConnector/ConditionCompiler.cs
  18. 217
      MySQLConnector/Connection.cs
  19. 19
      MySQLConnector/Extensions.cs
  20. 70
      MySQLConnector/MySQLConnector.csproj
  21. 23
      MySQLConnector/ParamsHolder.cs
  22. 36
      MySQLConnector/Properties/AssemblyInfo.cs
  23. 52
      MySQLConnector/Transaction.cs

@ -53,6 +53,10 @@
<Project>{6F532626-E9F8-498E-9683-1538E7CD62CB}</Project>
<Name>Core</Name>
</ProjectReference>
<ProjectReference Include="..\MySQLConnector\MySQLConnector.csproj">
<Project>{E38DE5B1-F9C2-43BA-A5DF-0743ABD4DFC7}</Project>
<Name>MySQLConnector</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.

@ -69,6 +69,7 @@
<Compile Include="delegates\Predicate.cs" />
<Compile Include="exceptions\CriticalException.cs" />
<Compile Include="exceptions\FLocalException.cs" />
<Compile Include="exceptions\NotFoundInDBException.cs" />
<Compile Include="exceptions\ObjectDoesntHaveAnIdException.cs" />
<Compile Include="extensions\Delegate.cs" />
<Compile Include="extensions\Extensions.cs" />

@ -4,7 +4,7 @@ using System.Linq;
using System.Text;
namespace FLocal.Core.DB {
class ColumnOrValue {
public class ColumnOrValue {
private bool _isColumn;

@ -4,13 +4,13 @@ using System.Linq;
using System.Text;
namespace FLocal.Core.DB {
class Diapasone {
public class Diapasone {
public readonly int start;
public readonly int count;
public int total {
get;
private set;
set;
}
public Diapasone(int start, int count) {

@ -4,31 +4,47 @@ using System.Linq;
using System.Text;
namespace FLocal.Core.DB {
interface IDBConnection {
public interface IDBConnection : IDisposable {
Dictionary<string, string> LoadById(ITableSpec table, int id);
Dictionary<string, string>[] LoadByIds(ITableSpec table, int[] ids);
List<Dictionary<string, string>> LoadByIds(ITableSpec table, List<string> ids);
int[] LoadIdsByConditions(ITableSpec table, conditions.AbstractCondition conditions, Diapasone diapasone, JoinSpec[] joins, SortSpec[] sorts);
List<string> LoadIdsByConditions(ITableSpec table, conditions.AbstractCondition conditions, Diapasone diapasone, JoinSpec[] joins, SortSpec[] sorts);
Transaction beginTransaction();
Transaction beginTransaction(System.Data.IsolationLevel iso);
ILock lockTable(Transaction transaction, ITableSpec table);
void lockTable(Transaction transaction, ITableSpec table);
ILock lockRow(Transaction transaction, ITableSpec table, int id);
void lockRow(Transaction transaction, ITableSpec table, string id);
void update(Transaction transaction, ITableSpec table, int id, Dictionary<string, string> data);
void update(Transaction transaction, ITableSpec table, string id, Dictionary<string, string> data);
void delete(Transaction transaction, ITableSpec table, int id); //do we really need this?
string insert(Transaction transaction, ITableSpec table, Dictionary<string, string> data);
void delete(Transaction transaction, ITableSpec table, string id); //do we really need this?
}
static class IDBConnectionExtensions {
public static class IDBConnectionExtensions {
public static int[] LoadIdsByConditions(this IDBConnection connection, ITableSpec table, conditions.AbstractCondition conditions, Diapasone diapasone, params JoinSpec[] joins) {
public static List<string> LoadIdsByConditions(this IDBConnection connection, ITableSpec table, conditions.AbstractCondition conditions, Diapasone diapasone, params JoinSpec[] joins) {
return connection.LoadIdsByConditions(table, conditions, diapasone, joins, new SortSpec[] { new SortSpec(table.getIdSpec(), true) });
}
public static Transaction beginTransaction(this IDBConnection connection) {
return connection.beginTransaction(System.Data.IsolationLevel.Snapshot);
}
public static Dictionary<string, string> LoadById(this IDBConnection connection, ITableSpec table, string id) {
List<Dictionary<string, string>> rows = connection.LoadByIds(table, new List<string> { id });
if(rows.Count < 1) {
throw new NotFoundInDBException();
}
if(rows.Count > 1) {
throw new CriticalException(rows.Count + " objects with specified id");
}
return rows[0];
}
}
}

@ -4,7 +4,7 @@ using System.Linq;
using System.Text;
namespace FLocal.Core.DB {
class JoinSpec {
public class JoinSpec {
public readonly ColumnSpec mainColumn;

@ -4,7 +4,7 @@ using System.Linq;
using System.Text;
namespace FLocal.Core.DB {
class SortSpec {
public class SortSpec {
public readonly ColumnSpec column;

@ -5,16 +5,24 @@ using System.Text;
namespace FLocal.Core.DB {
abstract class Transaction : IDisposable {
abstract public class Transaction : IDisposable {
protected Transaction() {
this.finalized = false;
}
abstract protected void do_Commit();
abstract protected void do_Rollback();
private bool finalized = false;
public bool finalized {
get;
private set;
}
public void Commit() {
lock(this) {
if(this.finalized) throw new CriticalException("Already finalized");
this.do_Commit();
this.finalized = true;
}
@ -22,6 +30,7 @@ namespace FLocal.Core.DB {
public void Rollback() {
lock(this) {
if(this.finalized) throw new CriticalException("Already finalized");
this.do_Rollback();
this.finalized = true;
}

@ -4,7 +4,7 @@ using System.Linq;
using System.Text;
namespace FLocal.Core.DB.conditions {
class ComparisonCondition : SimpleCondition {
public class ComparisonCondition : SimpleCondition {
public readonly ColumnSpec left;
public readonly ComparisonType comparison;

@ -4,7 +4,7 @@ using System.Linq;
using System.Text;
namespace FLocal.Core.DB.conditions {
enum ComparisonType {
public enum ComparisonType {
EQUAL,
NOTEQUAL,
LESSTHAN,

@ -4,7 +4,7 @@ using System.Linq;
using System.Text;
namespace FLocal.Core.DB.conditions {
class ComplexCondition : AbstractCondition {
public class ComplexCondition : AbstractCondition {
public readonly ConditionsJoinType type;

@ -4,7 +4,7 @@ using System.Linq;
using System.Text;
namespace FLocal.Core.DB.conditions {
enum ConditionsJoinType {
public enum ConditionsJoinType {
AND,
OR,
}

@ -4,7 +4,7 @@ using System.Linq;
using System.Text;
namespace FLocal.Core.DB.conditions {
class MultiValueCondition : SimpleCondition {
public class MultiValueCondition : SimpleCondition {
public readonly ColumnSpec column;

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace FLocal.Core {
public partial class NotFoundInDBException : FLocalException {
public NotFoundInDBException() : base("Object not found in DB") { }
}
}

@ -7,6 +7,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Core", "Core\Core.csproj",
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Common", "Common\Common.csproj", "{CE888859-9E46-41F7-91CE-8EC106F3A625}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MySQLConnector", "MySQLConnector\MySQLConnector.csproj", "{E38DE5B1-F9C2-43BA-A5DF-0743ABD4DFC7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -25,6 +27,10 @@ Global
{CE888859-9E46-41F7-91CE-8EC106F3A625}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CE888859-9E46-41F7-91CE-8EC106F3A625}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CE888859-9E46-41F7-91CE-8EC106F3A625}.Release|Any CPU.Build.0 = Release|Any CPU
{E38DE5B1-F9C2-43BA-A5DF-0743ABD4DFC7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E38DE5B1-F9C2-43BA-A5DF-0743ABD4DFC7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E38DE5B1-F9C2-43BA-A5DF-0743ABD4DFC7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E38DE5B1-F9C2-43BA-A5DF-0743ABD4DFC7}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

@ -74,6 +74,10 @@
<Project>{6F532626-E9F8-498E-9683-1538E7CD62CB}</Project>
<Name>Core</Name>
</ProjectReference>
<ProjectReference Include="..\MySQLConnector\MySQLConnector.csproj">
<Project>{E38DE5B1-F9C2-43BA-A5DF-0743ABD4DFC7}</Project>
<Name>MySQLConnector</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.

@ -0,0 +1,114 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FLocal.Core.DB;
using FLocal.Core.DB.conditions;
namespace FLocal.MySQLConnector {
class ConditionCompiler {
private readonly ParamsHolder paramsholder;
private ConditionCompiler() {
this.paramsholder = new ParamsHolder();
}
private string getName(ColumnOrValue cov) {
if(cov.isColumn) {
return cov.column.compile();
} else {
return "@" + this.paramsholder.Add(cov.value);
}
}
private string CompileCondition(ComparisonCondition condition) {
string left = condition.left.compile();
string right = getName(condition.right);
switch(condition.comparison) {
case ComparisonType.EQUAL:
return left + " = " + right;
case ComparisonType.GREATEROREQUAL:
return left + " >= " + right;
case ComparisonType.GREATERTHAN:
return left + " > " + right;
case ComparisonType.LESSOREQUAL:
return left + " <= " + right;
case ComparisonType.LESSTHAN:
return left + " < " + right;
case ComparisonType.NOTEQUAL:
return left + " != " + right;
default:
throw new NotImplementedException();
}
}
private string CompileCondition(IsNullCondition condition) {
return condition.column.compile() + " IS NULL";
}
private string CompileCondition(NotIsNullCondition condition) {
return condition.column.compile() + " NOT IS NULL";
}
private string CompileCondition(MultiValueCondition condition) {
List<string> valueParams = new List<string>();
foreach(string value in condition.values) {
valueParams.Add(this.paramsholder.Add(value));
}
if(condition.inclusive) {
return condition.column.compile() + " IN (" + string.Join(", ", valueParams.ToArray()) + ")";
} else {
return condition.column.compile() + " IN (" + string.Join(", ", valueParams.ToArray()) + ")";
}
}
private string CompileCondition(SimpleCondition condition) {
if(condition is ComparisonCondition) {
return CompileCondition((ComparisonCondition)condition);
} else if(condition is IsNullCondition) {
return CompileCondition((IsNullCondition)condition);
} else if(condition is NotIsNullCondition) {
return CompileCondition((NotIsNullCondition)condition);
} else if(condition is MultiValueCondition) {
return CompileCondition((MultiValueCondition)condition);
} else {
throw new NotImplementedException();
}
}
private string CompileCondition(ComplexCondition condition) {
List<string> parts = new List<string>();
foreach(AbstractCondition innerCondition in condition.innerConditions) {
parts.Add("(" + CompileCondition(innerCondition) + ")");
}
switch(condition.type) {
case ConditionsJoinType.AND:
return string.Join(" AND ", parts.ToArray());
case ConditionsJoinType.OR:
return string.Join(" OR ", parts.ToArray());
default:
throw new NotImplementedException();
}
}
private string CompileCondition(AbstractCondition condition) {
if(condition is ComplexCondition) {
return CompileCondition((ComplexCondition)condition);
} else if(condition is SimpleCondition) {
return CompileCondition((SimpleCondition)condition);
} else {
throw new NotImplementedException();
}
}
public static KeyValuePair<string, ParamsHolder> Compile(AbstractCondition condition) {
ConditionCompiler compiler = new ConditionCompiler();
string compiled = compiler.CompileCondition(condition);
return new KeyValuePair<string,ParamsHolder>(compiled, compiler.paramsholder);
}
}
}

@ -0,0 +1,217 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySql.Data.MySqlClient;
using FLocal.Core;
using FLocal.Core.DB;
namespace FLocal.MySQLConnector {
class Connection : IDBConnection {
private MySqlConnection connection;
private string connectionString;
private HashSet<Transaction> transactions;
public Connection(string connectionString) {
this.connection = new MySqlConnection(connectionString);
this.connection.Open();
this.connectionString = connectionString;
}
internal MySqlConnection createConnection() {
MySqlConnection connection = new MySqlConnection(this.connectionString);
return connection;
}
public List<Dictionary<string, string>> LoadByIds(ITableSpec table, List<string> ids) {
using(MySqlCommand command = this.connection.CreateCommand()) {
command.CommandType = System.Data.CommandType.Text;
ParamsHolder paramsHolder = new ParamsHolder();
List<string> placeholder = new List<string>();
foreach(string id in ids) {
placeholder.Add("@" + paramsHolder.Add(id));
}
command.CommandText = "SELECT * FROM " + table.compile() + " WHERE " + table.getIdSpec().compile() + " IN (" + string.Join(", ", placeholder.ToArray()) + ")";
foreach(KeyValuePair<string, string> kvp in paramsHolder.data) {
command.Parameters.AddWithValue(kvp.Key, kvp.Value);
}
Dictionary<string, Dictionary<string, string>> rawResult = new Dictionary<string, Dictionary<string, string>>();
using(MySqlDataReader reader = command.ExecuteReader()) {
while(reader.Read()) {
Dictionary<string, string> row = new Dictionary<string,string>();
for(int i=0; i<reader.FieldCount; i++) {
row.Add(reader.GetName(i), reader.GetString(i));
}
rawResult.Add(row[table.idName], row);
}
}
List<Dictionary<string, string>> result = new List<Dictionary<string,string>>();
foreach(string id in ids) {
if(rawResult.ContainsKey(id)) {
result.Add(rawResult[id]);
}
}
return result;
}
}
public List<string> LoadIdsByConditions(ITableSpec table, FLocal.Core.DB.conditions.AbstractCondition conditions, Diapasone diapasone, JoinSpec[] joins, SortSpec[] sorts) {
using(MySqlCommand command = this.connection.CreateCommand()) {
command.CommandType = System.Data.CommandType.Text;
var conditionsCompiled = ConditionCompiler.Compile(conditions);
string queryConditions = conditionsCompiled.Key;
ParamsHolder paramsHolder = conditionsCompiled.Value;
string queryJoins = "";
string querySorts = "";
{
}
string queryMain = "FROM " + table.compile() + " " + queryJoins + " WHERE " + queryConditions;
foreach(KeyValuePair<string, string> kvp in paramsHolder.data) {
command.Parameters.AddWithValue(kvp.Key, kvp.Value);
}
command.CommandText = "SELECT COUNT(*) " + queryMain;
object rawCount = command.ExecuteScalar();
int count = (int)rawCount;
if(count < 1) {
diapasone.total = 0;
return new List<string>();
} else {
diapasone.total = count;
string queryLimits = "";
if(diapasone.count >= 0) {
queryLimits = "LIMIT " + diapasone.count + " OFFSET " + diapasone.start;
}
command.CommandText = "SELECT " + table.compile() + ".* " + queryMain + " " + querySorts + " " + queryLimits;
List<string> result = new List<string>();
using(MySqlDataReader reader = command.ExecuteReader()) {
while(reader.Read()) {
result.Add(reader.GetString(0));
}
}
return result;
}
}
}
public FLocal.Core.DB.Transaction beginTransaction(System.Data.IsolationLevel iso) {
lock(this) {
Transaction transaction = new Transaction(this, iso);
try {
this.transactions.Add(transaction);
} catch(Exception e) {
transaction.Dispose();
throw e;
}
return transaction;
}
}
public void lockTable(FLocal.Core.DB.Transaction _transaction, ITableSpec table) {
Transaction transaction = (Transaction)_transaction;
lock(transaction) {
using(MySqlCommand command = transaction.sqlconnection.CreateCommand()) {
command.Transaction = transaction.sqltransaction;
command.CommandType = System.Data.CommandType.Text;
command.CommandText = "LOCK TABLES `" + MySqlHelper.EscapeString(table.name) + "`";
command.ExecuteNonQuery();
}
}
}
public void lockRow(FLocal.Core.DB.Transaction _transaction, ITableSpec table, string id) {
Transaction transaction = (Transaction)_transaction;
lock(transaction) {
using(MySqlCommand command = transaction.sqlconnection.CreateCommand()) {
command.Transaction = transaction.sqltransaction;
command.CommandType = System.Data.CommandType.Text;
command.CommandText = "SELECT * FROM `" + MySqlHelper.EscapeString(table.name) + "` where `" + MySqlHelper.EscapeString(table.idName) + "` = @id FOR UPDATE";
command.Parameters.Add(new MySqlParameter("id", id));
command.ExecuteNonQuery();
}
}
}
public void update(FLocal.Core.DB.Transaction _transaction, ITableSpec table, string id, Dictionary<string, string> data) {
Transaction transaction = (Transaction)_transaction;
lock(transaction) {
using(MySqlCommand command = transaction.sqlconnection.CreateCommand()) {
List<string> updates = new List<string>();
ParamsHolder paramsholder = new ParamsHolder();
foreach(KeyValuePair<string, string> kvp in data) {
string paramname = paramsholder.Add(kvp.Value);
updates.Add("`" + MySqlHelper.EscapeString(kvp.Key) + "` = @" + paramname);
}
command.Transaction = transaction.sqltransaction;
command.CommandType = System.Data.CommandType.Text;
command.CommandText = "UPDATE `" + MySqlHelper.EscapeString(table.name) + "` set " + String.Join(", ", updates.ToArray()) + " where `" + MySqlHelper.EscapeString(table.idName) + "` = @id";
command.Parameters.AddWithValue("id", id);
foreach(KeyValuePair<string, string> kvp in paramsholder.data) {
command.Parameters.AddWithValue(kvp.Key, kvp.Value);
}
command.ExecuteNonQuery();
}
}
}
public string insert(FLocal.Core.DB.Transaction _transaction, ITableSpec table, Dictionary<string, string> data) {
Transaction transaction = (Transaction)_transaction;
lock(transaction) {
using(MySqlCommand command = transaction.sqlconnection.CreateCommand()) {
List<string> updates = new List<string>();
ParamsHolder paramsholder = new ParamsHolder();
foreach(KeyValuePair<string, string> kvp in data) {
string paramname = paramsholder.Add(kvp.Value);
updates.Add("`" + MySqlHelper.EscapeString(kvp.Key) + "` = @" + paramname);
}
command.Transaction = transaction.sqltransaction;
command.CommandType = System.Data.CommandType.Text;
command.CommandText = "INSERT INTO `" + MySqlHelper.EscapeString(table.name) + "` SET " + String.Join(", ", updates.ToArray());
foreach(KeyValuePair<string, string> kvp in paramsholder.data) {
command.Parameters.AddWithValue(kvp.Key, kvp.Value);
}
command.ExecuteNonQuery();
return command.LastInsertedId.ToString();
}
}
}
public void delete(FLocal.Core.DB.Transaction transaction, ITableSpec table, string id) {
throw new NotImplementedException();
}
public void Dispose() {
lock(this) {
foreach(Transaction transaction in this.transactions) {
if(!transaction.finalizedImpl) {
throw new CriticalException("Trying to close db connection while there are open transactions");
}
}
this.transactions.Clear();
this.transactions = null;
this.connection.Close();
this.connection.Dispose();
this.connection = null;
}
}
}
}

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FLocal.Core.DB;
using MySql.Data.MySqlClient;
namespace FLocal.MySQLConnector {
static class Extensions {
public static string compile(this ITableSpec table) {
return "`" + MySqlHelper.EscapeString(table.name) + "`";
}
public static string compile(this ColumnSpec column) {
return column.table.compile() + ".`" + MySqlHelper.EscapeString(column.name) + "`";
}
}
}

@ -0,0 +1,70 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{E38DE5B1-F9C2-43BA-A5DF-0743ABD4DFC7}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>FLocal.MySQLConnector</RootNamespace>
<AssemblyName>MySQLConnector</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="MySql.Data, Version=6.2.3.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d, processorArchitecture=MSIL" />
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Xml.Linq">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data.DataSetExtensions">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="ConditionCompiler.cs" />
<Compile Include="Connection.cs" />
<Compile Include="Extensions.cs" />
<Compile Include="ParamsHolder.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Transaction.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Core\Core.csproj">
<Project>{6F532626-E9F8-498E-9683-1538E7CD62CB}</Project>
<Name>Core</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace FLocal.MySQLConnector {
class ParamsHolder {
public Dictionary<string, string> data = new Dictionary<string,string>();
private int index = 1;
public string Add(string value) {
lock(this) {
string name = "param" + index;
this.data.Add(name, value);
this.index++;
return name;
}
}
}
}

@ -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")]

@ -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;
}
}
}
Loading…
Cancel
Save