Skip to content

Commit

Permalink
Added support for MonoTouch. Closes #45.
Browse files Browse the repository at this point in the history
  • Loading branch information
hisystems committed Jul 26, 2012
1 parent 065ea42 commit 452508f
Show file tree
Hide file tree
Showing 5 changed files with 218 additions and 2 deletions.
18 changes: 16 additions & 2 deletions Database/Database.cs
Expand Up @@ -33,13 +33,17 @@ public class Database
{
public enum ConnectionType
{
#if MONO_TOUCH
SQLite
#else
SQLServer,
MicrosoftAccess,
MySQL,
Pervasive,
SQLServerCompactEdition,
HyperSQL,
SQLite
#endif
}

private ConnectionController pobjConnection;
Expand Down Expand Up @@ -1816,6 +1820,7 @@ internal void BeginTransaction(System.Data.IsolationLevel eIsolationLevel)

switch (peConnectionType)
{
#if !MONO
case ConnectionType.SQLServerCompactEdition:
IDbTransaction objTransaction = pobjConnection.BeginTransaction(eIsolationLevel);
//Simulate that SET TRANSACTION ISOLATION LEVEL has been called
Expand All @@ -1827,7 +1832,8 @@ internal void BeginTransaction(System.Data.IsolationLevel eIsolationLevel)
//Simulate that BEGIN TRANSACTION has been called
OnStatementExecuted(new SQL.SQLBeginTransaction());
break;
default:
#endif
default:
if (eIsolationLevel != System.Data.IsolationLevel.Unspecified)
{
ExecuteNonQuery(new SQL.SQLSetTransactionIsolationLevel(eIsolationLevel));
Expand All @@ -1843,14 +1849,16 @@ internal void CommitTransaction()
{
switch (peConnectionType)
{
#if !MONO
case ConnectionType.SQLServerCompactEdition:
// Compact edition does not directly support use of COMMIT TRANSACTION
IDbTransaction objTransaction = pobjTransactions.Pop();
objTransaction.Commit();
//Simulate that COMMIT TRANSACTION has been called
OnStatementExecuted(new SQL.SQLCommitTransaction());
break;
default:
#endif
default:
ExecuteNonQuery(new SQL.SQLCommitTransaction());
break;
}
Expand All @@ -1866,13 +1874,15 @@ internal void RollbackTransaction()

switch (peConnectionType)
{
#if !MONO
case ConnectionType.SQLServerCompactEdition:
// Compact edition does not directly support use of ROLLBACK TRANSACTION
IDbTransaction objTransaction = pobjTransactions.Pop();
objTransaction.Rollback();
//Simulate that COMMIT TRANSACTION has been called
OnStatementExecuted(new SQL.SQLRollbackTransaction());
break;
#endif
default:
ExecuteNonQuery(new SQL.SQLRollbackTransaction());
break;
Expand Down Expand Up @@ -2079,12 +2089,16 @@ protected virtual int ExecuteNonQueryInternal(IDbConnection objConnection, SQL.I

private static IDbConnection CreateConnection(string strConnectionString)
{
#if MONO
throw new NotImplementedException("Pass an IDbConnection object to the constructor");
#else
//Searches for an occurance of 'Provider='
//If found then it is assumed to be an OLEDB connection otherwise an ODBC connection
if (GetDictionaryFromConnectionString(strConnectionString).ContainsKey("provider"))
return new System.Data.OleDb.OleDbConnection(strConnectionString);
else
return new System.Data.Odbc.OdbcConnection(strConnectionString);
#endif
}
}
}
Expand Down
170 changes: 170 additions & 0 deletions DatabaseObjects.MonoTouch.csproj
@@ -0,0 +1,170 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>10.0.0</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{7958EB2F-0396-4E39-BE78-F44EC7E8088A}</ProjectGuid>
<ProjectTypeGuids>{6BC8ED88-2882-458C-8E55-DFD12B67127B};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<OutputType>Library</OutputType>
<RootNamespace>DatabaseObjects</RootNamespace>
<AssemblyName>DatabaseObjects</AssemblyName>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug</OutputPath>
<DefineConstants>DEBUG;MONO;MONO_TOUCH</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>none</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Xml" />
<Reference Include="System.Core" />
<Reference Include="monotouch" />
<Reference Include="System.Data" />
<Reference Include="System.Transactions" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>
<Compile Include="Attributes\DistinctFieldAttribute.cs" />
<Compile Include="Attributes\FieldMappingAttribute.cs" />
<Compile Include="Attributes\FieldMappingObjectHookAttribute.cs" />
<Compile Include="Attributes\ItemInstanceAttribute.cs" />
<Compile Include="Attributes\KeyFieldAttribute.cs" />
<Compile Include="Attributes\ObjectReferenceEarlyBindingAttribute.cs" />
<Compile Include="Attributes\OrderByAttribute.cs" />
<Compile Include="Attributes\SubsetAttribute.cs" />
<Compile Include="Attributes\TableAttribute.cs" />
<Compile Include="Attributes\TableJoinAttribute.cs" />
<Compile Include="Contraints\Constraint.cs" />
<Compile Include="Contraints\ConstraintBinding.cs" />
<Compile Include="Contraints\DateIsSetConstraint.cs" />
<Compile Include="Contraints\DateIsTodayOrFutureForNewObjectConstraint.cs" />
<Compile Include="Contraints\IConstraint.cs" />
<Compile Include="Contraints\KeyFieldIsUniqueInCollectionConstraint.cs" />
<Compile Include="Contraints\ObjectIsSetConstraint.cs" />
<Compile Include="Contraints\RegExConstraint.cs" />
<Compile Include="Contraints\StringIsSetConstraint.cs" />
<Compile Include="Contraints\StringMaxLengthConstraint.cs" />
<Compile Include="Database\ConnectionScope.cs" />
<Compile Include="Database\Database.cs" />
<Compile Include="Database\DatabaseObject.cs" />
<Compile Include="Database\DatabaseObjectLockController.cs" />
<Compile Include="Database\DatabaseObjectLockable.cs" />
<Compile Include="Database\DatabaseObjectUsingAttributesHelper.cs" />
<Compile Include="Database\DatabaseObjects.cs" />
<Compile Include="Database\DatabaseObjectsEnumerable.cs" />
<Compile Include="Database\DatabaseObjectsItemInstance.cs" />
<Compile Include="Database\DatabaseObjectsUsingAttributesHelper.cs" />
<Compile Include="Database\DatabaseObjectsVolatile.cs" />
<Compile Include="Database\IDatabaseObject.cs" />
<Compile Include="Database\IDatabaseObjectLockable.cs" />
<Compile Include="Database\IDatabaseObjectVolatile.cs" />
<Compile Include="Database\IDatabaseObjects.cs" />
<Compile Include="Database\IDatabaseObjectsMultipleSubclass.cs" />
<Compile Include="Database\IGlobalDatabaseObjects.cs" />
<Compile Include="Database\LocalTransactionScope.cs" />
<Compile Include="Database\ObjectReference.cs" />
<Compile Include="Database\ObjectReferenceEarlyBinding.cs" />
<Compile Include="Database\RootContainer.cs" />
<Compile Include="Generic\DatabaseObjects.cs" />
<Compile Include="Generic\DatabaseObjectsEnumerable.cs" />
<Compile Include="Generic\DatabaseObjectsList.cs" />
<Compile Include="Generic\DatabaseObjectsListKeyed.cs" />
<Compile Include="Generic\DatabaseObjectsMultipleSubclass.cs" />
<Compile Include="Generic\DatabaseObjectsVolatile.cs" />
<Compile Include="Generic\DatabaseObjectsVolatileList.cs" />
<Compile Include="Generic\ObjectReference.cs" />
<Compile Include="Misc\AssemblyInfo.cs" />
<Compile Include="Misc\Exceptions.cs" />
<Compile Include="Misc\SystemReflectionExtensions.cs" />
<Compile Include="SQL\ISQLStatement.cs" />
<Compile Include="SQL\SQL.cs" />
<Compile Include="SQL\SQLStatement.cs" />
<Compile Include="SQL\SQLStatements.cs" />
<Compile Include="SQL\Amend\SQLDelete.cs" />
<Compile Include="SQL\Amend\SQLFieldValue.cs" />
<Compile Include="SQL\Amend\SQLFieldValues.cs" />
<Compile Include="SQL\Amend\SQLInsert.cs" />
<Compile Include="SQL\Amend\SQLInsertFromSelect.cs" />
<Compile Include="SQL\Amend\SQLUpdate.cs" />
<Compile Include="SQL\Amend\SQLUpdateField.cs" />
<Compile Include="SQL\Amend\SQLUpdateFields.cs" />
<Compile Include="SQL\Expressions\SQLAggregateExpression.cs" />
<Compile Include="SQL\Expressions\SQLAllFieldsExpression.cs" />
<Compile Include="SQL\Expressions\SQLArithmeticExpression.cs" />
<Compile Include="SQL\Expressions\SQLBitwiseExpression.cs" />
<Compile Include="SQL\Expressions\SQLCaseExpression.cs" />
<Compile Include="SQL\Expressions\SQLCastFieldExpression.cs" />
<Compile Include="SQL\Expressions\SQLExpression.cs" />
<Compile Include="SQL\Expressions\SQLFieldAggregateExpression.cs" />
<Compile Include="SQL\Expressions\SQLFieldExpression.cs" />
<Compile Include="SQL\Expressions\SQLFunctionExpression.cs" />
<Compile Include="SQL\Expressions\SQLGetDateFunctionExpression.cs" />
<Compile Include="SQL\Expressions\SQLLeftFunctionExpression.cs" />
<Compile Include="SQL\Expressions\SQLLengthFunctionExpression.cs" />
<Compile Include="SQL\Expressions\SQLRightFunctionExpression.cs" />
<Compile Include="SQL\Expressions\SQLStringConcatExpression.cs" />
<Compile Include="SQL\Expressions\SQLValueExpression.cs" />
<Compile Include="SQL\Select\SQLAutoIncrementValue.cs" />
<Compile Include="SQL\Select\SQLCondition.cs" />
<Compile Include="SQL\Select\SQLConditionExpression.cs" />
<Compile Include="SQL\Select\SQLConditionFieldCompare.cs" />
<Compile Include="SQL\Select\SQLConditionInSelect.cs" />
<Compile Include="SQL\Select\SQLConditionSelect.cs" />
<Compile Include="SQL\Select\SQLConditions.cs" />
<Compile Include="SQL\Select\SQLSelect.cs" />
<Compile Include="SQL\Select\SQLSelectExpression.cs" />
<Compile Include="SQL\Select\SQLSelectField.cs" />
<Compile Include="SQL\Select\SQLSelectFields.cs" />
<Compile Include="SQL\Select\SQLSelectGetDate.cs" />
<Compile Include="SQL\Select\SQLSelectGroupByField.cs" />
<Compile Include="SQL\Select\SQLSelectGroupByFields.cs" />
<Compile Include="SQL\Select\SQLSelectHavingCondition.cs" />
<Compile Include="SQL\Select\SQLSelectHavingConditions.cs" />
<Compile Include="SQL\Select\SQLSelectOrderByField.cs" />
<Compile Include="SQL\Select\SQLSelectOrderByFields.cs" />
<Compile Include="SQL\Select\SQLSelectTable.cs" />
<Compile Include="SQL\Select\SQLSelectTableBase.cs" />
<Compile Include="SQL\Select\SQLSelectTableFromSelect.cs" />
<Compile Include="SQL\Select\SQLSelectTableJoin.cs" />
<Compile Include="SQL\Select\SQLSelectTableJoinCondition.cs" />
<Compile Include="SQL\Select\SQLSelectTableJoinConditions.cs" />
<Compile Include="SQL\Select\SQLSelectTableJoins.cs" />
<Compile Include="SQL\Select\SQLSelectTables.cs" />
<Compile Include="SQL\Select\SQLUnion.cs" />
<Compile Include="SQL\Serializers\SQLiteSerializer.cs" />
<Compile Include="SQL\Serializers\Serializer.cs" />
<Compile Include="SQL\Serializers\Serializers.cs" />
<Compile Include="SQL\TableDefinition\SQLAlterTable.cs" />
<Compile Include="SQL\TableDefinition\SQLCreateIndex.cs" />
<Compile Include="SQL\TableDefinition\SQLCreateTable.cs" />
<Compile Include="SQL\TableDefinition\SQLDropIndex.cs" />
<Compile Include="SQL\TableDefinition\SQLDropTable.cs" />
<Compile Include="SQL\TableDefinition\SQLTableExists.cs" />
<Compile Include="SQL\TableDefinition\SQLTableFields.cs" />
<Compile Include="SQL\Transactions\SQLBeginTransaction.cs" />
<Compile Include="SQL\Transactions\SQLCommitTransaction.cs" />
<Compile Include="SQL\Transactions\SQLRollbackTransaction.cs" />
<Compile Include="SQL\Transactions\SQLSetTransactionIsolationLevel.cs" />
<Compile Include="SQL\Views\SQLCreateView.cs" />
<Compile Include="SQL\Views\SQLDropView.cs" />
<Compile Include="SQL\Views\SQLViewExists.cs" />
</ItemGroup>
<ItemGroup>
<None Include="README.md" />
</ItemGroup>
</Project>
20 changes: 20 additions & 0 deletions DatabaseObjects.MonoTouch.sln
@@ -0,0 +1,20 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DatabaseObjects.MonoTouch", "DatabaseObjects.MonoTouch.csproj", "{7958EB2F-0396-4E39-BE78-F44EC7E8088A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{7958EB2F-0396-4E39-BE78-F44EC7E8088A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7958EB2F-0396-4E39-BE78-F44EC7E8088A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7958EB2F-0396-4E39-BE78-F44EC7E8088A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7958EB2F-0396-4E39-BE78-F44EC7E8088A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
StartupItem = DatabaseObjects.MonoTouch.csproj
EndGlobalSection
EndGlobal
8 changes: 8 additions & 0 deletions DatabaseObjects.MonoTouch.userprefs
@@ -0,0 +1,8 @@
<Properties>
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" />
<MonoDevelop.Ide.Workbench />
<MonoDevelop.Ide.DebuggingService.Breakpoints>
<BreakpointStore />
</MonoDevelop.Ide.DebuggingService.Breakpoints>
<MonoDevelop.Ide.DebuggingService.PinnedWatches />
</Properties>
4 changes: 4 additions & 0 deletions SQL/Serializers/Serializers.cs
Expand Up @@ -18,13 +18,17 @@ internal static class Serializers

static Serializers()
{
#if MONO_TOUCH
Items.Add(Database.ConnectionType.SQLite, new SQLiteSerializer());
#else
Items.Add(Database.ConnectionType.SQLServer, new MicrosoftSqlServerSerializer());
Items.Add(Database.ConnectionType.SQLServerCompactEdition, new MicrosoftSqlServerCompactEditionSerializer());
Items.Add(Database.ConnectionType.MicrosoftAccess, new MicrosoftAccessSerializer());
Items.Add(Database.ConnectionType.MySQL, new MySqlSerializer());
Items.Add(Database.ConnectionType.HyperSQL, new HyperSqlSerializer());
Items.Add(Database.ConnectionType.Pervasive, new PervasiveSerializer());
Items.Add(Database.ConnectionType.SQLite, new SQLiteSerializer());
#endif
}
}
}

0 comments on commit 452508f

Please sign in to comment.