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

7.0.x provider compatibility #194

Open
wants to merge 3 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
7 changes: 4 additions & 3 deletions EF6.PG/NpgsqlMigrationSqlGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -725,14 +725,14 @@ void AppendValue(bool value, StringBuilder sql)
void AppendValue(DateTime value, StringBuilder sql)
{
sql.Append("'");
sql.Append(new NpgsqlTypes.NpgsqlDateTime(value));
sql.Append(value.ToString("yyyy-MM-dd HH:mm:ss.fffffff"));
sql.Append("'");
}

void AppendValue(DateTimeOffset value, StringBuilder sql)
{
sql.Append("'");
sql.Append(new NpgsqlTypes.NpgsqlDateTime(value.UtcDateTime));
sql.Append(value.UtcDateTime.ToString("yyyy-MM-dd HH:mm:ss.fffffff"));
sql.Append("'");
}

Expand All @@ -753,7 +753,8 @@ void AppendValue(string value, StringBuilder sql)
void AppendValue(TimeSpan value, StringBuilder sql)
{
sql.Append("'");
sql.Append(new NpgsqlTypes.NpgsqlTimeSpan(value));
sql.Append(value < TimeSpan.Zero ? "-" : "");
sql.Append(value.ToString(@"\P%d\D\T%h\H%m\M%s\S", CultureInfo.InvariantCulture));
sql.Append("'");
}

Expand Down
5 changes: 4 additions & 1 deletion EF6.PG/NpgsqlServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ internal void TranslateCommandTree(Version serverVersion, DbCommandTree commandT
sqlGenerator.BuildCommand(command);
}

//Some server instances/npgsql provider versions return additional information after the server version.
//This regex is used to extract only version at the beginning of the string
private static Regex VersionRx = new Regex(@"^[0-9]+(?:\.[0-9]+){0,3}", RegexOptions.Compiled);
protected override string GetDbProviderManifestToken([NotNull] DbConnection connection)
{
if (connection == null)
Expand All @@ -116,7 +119,7 @@ protected override string GetDbProviderManifestToken([NotNull] DbConnection conn
UsingPostgresDbConnection((NpgsqlConnection)connection, conn => {
serverVersion = conn.ServerVersion;
});
return serverVersion;
return VersionRx.Match(serverVersion ?? "").ToString();
}

protected override DbProviderManifest GetDbProviderManifest([NotNull] string versionHint)
Expand Down
5 changes: 4 additions & 1 deletion EF6.PG/SqlGenerators/VisitedExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,10 @@ internal override void WriteSql(StringBuilder sqlText)
sqlText.Append("E'").Append(((string)_value).Replace(@"\", @"\\").Replace("'", @"\'")).Append("'");
break;
case PrimitiveTypeKind.Time:
sqlText.AppendFormat(ni, "INTERVAL '{0}'", (NpgsqlTimeSpan)(TimeSpan)_value);
sqlText.Append("INTERVAL '");
if ((TimeSpan)_value < TimeSpan.Zero) sqlText.Append("-");
sqlText.Append(((TimeSpan)_value).ToString(@"\P%d\D\T%h\H%m\M%s\S", CultureInfo.InvariantCulture));
sqlText.Append('\'');
break;
default:
// TODO: must support more constant value types.
Expand Down