Skip to content

Commit

Permalink
Supports SQLLogicalExpression. Closes #66.
Browse files Browse the repository at this point in the history
  • Loading branch information
hisystems committed Aug 14, 2012
1 parent 54c38d9 commit e1c97ef
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 6 deletions.
1 change: 1 addition & 0 deletions DatabaseObjects.MonoTouch.csproj
Expand Up @@ -163,6 +163,7 @@
<Compile Include="SQL\Views\SQLCreateView.cs" />
<Compile Include="SQL\Views\SQLDropView.cs" />
<Compile Include="SQL\Views\SQLViewExists.cs" />
<Compile Include="SQL\Expressions\SQLLogicalExpression.cs" />
</ItemGroup>
<ItemGroup>
<None Include="README.md" />
Expand Down
1 change: 1 addition & 0 deletions DatabaseObjects.csproj
Expand Up @@ -192,6 +192,7 @@
<Compile Include="Misc\AssemblyInfo.cs" />
<Compile Include="SQL\Amend\SQLInsertFromSelect.cs" />
<Compile Include="SQL\Amend\SQLUpdateField.cs" />
<Compile Include="SQL\Expressions\SQLLogicalExpression.cs" />
<Compile Include="SQL\Expressions\SQLStringConcatExpression.cs" />
<Compile Include="SQL\Expressions\SQLAggregateExpression.cs" />
<Compile Include="SQL\Expressions\SQLAllFieldsExpression.cs" />
Expand Down
87 changes: 87 additions & 0 deletions SQL/Expressions/SQLLogicalExpression.cs
@@ -0,0 +1,87 @@
// ___________________________________________________
//
// © Hi-Integrity Systems 2010. All rights reserved.
// www.hisystems.com.au - Toby Wicks
// ___________________________________________________
//

using System.Collections;
using System;
using System.Data;

namespace DatabaseObjects.SQL
{
public enum LogicalOperator
{
@And,
@Or
}

public class SQLLogicalExpression : SQLExpression
{
private SQLExpression left;
private LogicalOperator @operator;
private SQLExpression right;

public SQLLogicalExpression()
{
}

public SQLLogicalExpression(SQLExpression leftExpression, LogicalOperator @operator, SQLExpression rightExpression)
{
this.LeftExpression = leftExpression;
this.@operator = @operator;
this.RightExpression = rightExpression;
}

public SQLExpression LeftExpression
{
get
{
return this.left;
}

set
{
if (value == null)
throw new ArgumentNullException();

this.left = value;
}
}

public SQLExpression RightExpression
{
get
{
return this.right;
}

set
{
if (value == null)
throw new ArgumentNullException();

this.right = value;
}
}

public LogicalOperator Operator
{
get
{
return this.@operator;
}

set
{
this.@operator = value;
}
}

internal override string SQL(Serializers.Serializer serializer)
{
return serializer.SerializeLogicalExpression(this);
}
}
}
6 changes: 0 additions & 6 deletions SQL/SQL.cs
Expand Up @@ -256,12 +256,6 @@ public enum ComparisonOperator
NotLike
}

public enum LogicalOperator
{
@And,
@Or
}

public enum FieldValueAutoAssignmentType
{
/// <summary>
Expand Down
10 changes: 10 additions & 0 deletions SQL/Serializers/Serializer.cs
Expand Up @@ -387,6 +387,16 @@ public virtual string SerializeArithmeticExpression(SQLArithmeticExpression arit

return "(" + arithmeticExpression.LeftExpression.SQL(this) + " " + SerializeArithmeticOperator(arithmeticExpression.Operator) + " " + arithmeticExpression.RightExpression.SQL(this) + ")";
}

public virtual string SerializeLogicalExpression(SQLLogicalExpression logicalExpression)
{
if (logicalExpression.LeftExpression == null)
throw new ArgumentNullException(logicalExpression.GetType().Name + ".LeftExpression");
else if (logicalExpression.RightExpression == null)
throw new ArgumentNullException(logicalExpression.GetType().Name + ".RightExpression");

return "(" + logicalExpression.LeftExpression.SQL(this) + " " + SerializeLogicalOperator(logicalExpression.Operator) + " " + logicalExpression.RightExpression.SQL(this) + ")";
}

public virtual string SerializeAggregateExpression(SQLAggregateExpression aggregateExpression)
{
Expand Down

0 comments on commit e1c97ef

Please sign in to comment.