Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix npgsql/EntityFramework6.Npgsql#78 support citext type #79

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/EntityFramework6.Npgsql/EntityFramework6.Npgsql.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@
<EmbeddedResource Include="NpgsqlSchema.msl" />
<EmbeddedResource Include="NpgsqlSchema.ssdl" />
<EmbeddedResource Include="NpgsqlSchemaV3.ssdl" />
<EmbeddedResource Include="NpgsqlProviderManifest.Manifest.xml" />
<EmbeddedResource Include="NpgsqlProviderManifest.Manifest.xml">
<SubType>Designer</SubType>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<Compile Include="NpgsqlConnectionFactory.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@
<Unicode DefaultValue="true" Constant="true" />
</FacetDescriptions>
</Type>
<Type Name="citext" PrimitiveTypeKind="String">
<FacetDescriptions>
<FixedLength DefaultValue="false" Constant="true" />
<!-- TODO: Need a good value for MaxLength -->
<MaxLength DefaultValue="1073741823" Constant="true" />
<Unicode DefaultValue="true" Constant="true" />
</FacetDescriptions>
</Type>
<Type Name="xml" PrimitiveTypeKind="String">
<FacetDescriptions>
<FixedLength DefaultValue="false" Constant="true" />
Expand Down
3 changes: 2 additions & 1 deletion src/EntityFramework6.Npgsql/NpgsqlProviderManifest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ public override TypeUsage GetEdmType([NotNull] TypeUsage storeType)
return TypeUsage.CreateStringTypeUsage(primitiveType, isUnicode, false);
case "text":
case "xml":
return TypeUsage.CreateStringTypeUsage(primitiveType, isUnicode, false);
case "citext":
return TypeUsage.CreateStringTypeUsage(primitiveType, isUnicode, false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: indentation

case "timestamp":
// TODO: make sure the arguments are correct here
if (storeType.Facets.TryGetValue(PrecisionFacet, false, out facet) &&
Expand Down
15 changes: 14 additions & 1 deletion src/EntityFramework6.Npgsql/SqlGenerators/SqlBaseGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1094,7 +1094,9 @@ VisitedExpression VisitFunction(EdmFunction function, IList<DbExpression> args,
return new FunctionExpression("uuid_generate_v4");
case "TruncateTime":
return new TruncateTimeExpression("day", args[0].Accept(this));

case "CreateTime":
return new MakeTimeExpression(args[0].Accept(this), args[1].Accept(this), args[2].Accept(this));
//return MakeTime(args[0].Accept(this), args[1].Accept(this), args[2].Accept(this));
default:
throw new NotSupportedException("NotSupported " + function.Name);
}
Expand Down Expand Up @@ -1287,6 +1289,17 @@ VisitedExpression Substring(VisitedExpression source, VisitedExpression start, V
return substring;
}

//hour int, min int, sec double precision
VisitedExpression MakeTime(VisitedExpression hour, VisitedExpression min, VisitedExpression sec)
{
var substring = new FunctionExpression("make_interval");
//make_interval(hours => 9,minutes=>);
substring.AddArgument(hour);
substring.AddArgument(min);
substring.AddArgument(sec);
return substring;
}

VisitedExpression Substring(VisitedExpression source, VisitedExpression start)
{
var substring = new FunctionExpression("substr");
Expand Down
30 changes: 30 additions & 0 deletions src/EntityFramework6.Npgsql/SqlGenerators/VisitedExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1108,4 +1108,34 @@ internal override void WriteSql(StringBuilder sqlText)
base.WriteSql(sqlText);
}
}

internal class MakeTimeExpression : VisitedExpression
{
readonly VisitedExpression _hours;
readonly VisitedExpression _minutes;
readonly VisitedExpression _seconds;

public MakeTimeExpression(VisitedExpression hours, VisitedExpression minutes, VisitedExpression seconds)
{
_hours = hours;
_minutes = minutes;
_seconds = seconds;
}

internal override void WriteSql(StringBuilder sqlText)
{
sqlText.Append("make_interval");
sqlText.Append("(");
sqlText.Append("hours => ");
_hours.WriteSql(sqlText);
sqlText.Append(",");
sqlText.Append("mins => ");
_minutes.WriteSql(sqlText);
sqlText.Append(",");
sqlText.Append("secs => ");
_seconds.WriteSql(sqlText);
sqlText.Append(")");
base.WriteSql(sqlText);
}
}
}