Skip to content

Commit

Permalink
Automatically wrap Query objects when specified in a column
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgindi committed Dec 18, 2015
1 parent 9aef66e commit 09f7ae0
Showing 1 changed file with 30 additions and 10 deletions.
40 changes: 30 additions & 10 deletions dg.Sql/Sql/Query/Query.cs
Original file line number Diff line number Diff line change
Expand Up @@ -263,17 +263,41 @@ public static string PrepareColumnValue(TableSchema.Column ColumnDefinition, obj
/// <param name="Connection">A connector to use. Mandatory.</param>
public static void PrepareColumnValue(TableSchema.Column ColumnDefinition, object Value, StringBuilder OutputBuilder, ConnectorBase Connection)
{
if (ColumnDefinition == null)
if (Value == null)
{
OutputBuilder.Append(Connection.PrepareValue(Value));
OutputBuilder.Append(@"NULL");
return;
}
if (Value == null)

if (Value is dg.Sql.IPhrase)
{
OutputBuilder.Append(@"NULL");
// Output the complete phrase

OutputBuilder.Append(((dg.Sql.IPhrase)Value).BuildPhrase(Connection));

return;
}

if (Value is dg.Sql.Query)
{
// Output a properly wrapped query

OutputBuilder.Append("(" + ((dg.Sql.Query)Value).BuildCommand(Connection) + ")");

return;
}

if (ColumnDefinition == null)
{
// No definition to match against,
// so just prepare the value as it is, output it and return

OutputBuilder.Append(Connection.PrepareValue(Value));

return;
}
else if (Value.GetType() != ColumnDefinition.Type)

if (Value.GetType() != ColumnDefinition.Type)
{
if (Value is string)
{
Expand Down Expand Up @@ -374,11 +398,6 @@ public static void PrepareColumnValue(TableSchema.Column ColumnDefinition, objec
}
catch { }
}
else if (Value is dg.Sql.IPhrase)
{
OutputBuilder.Append(((dg.Sql.IPhrase)Value).BuildPhrase(Connection));
return;
}
}
}
else if (Value is string)
Expand All @@ -405,6 +424,7 @@ public static void PrepareColumnValue(TableSchema.Column ColumnDefinition, objec
}
catch { }
}

OutputBuilder.Append(Connection.PrepareValue(Value));
}

Expand Down

0 comments on commit 09f7ae0

Please sign in to comment.