Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit 82d1352

Browse files
committed
Fix for the postgres table creation error.
1 parent ec58a09 commit 82d1352

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

src/ServiceStack.OrmLite.PostgreSQL.Tests/CreatePostgreSQLTablesTests.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,14 @@ public void can_create_tables_after_UseUnicode_or_DefaultStringLenght_changed()
1919
//first one passes
2020
_reCreateTheTable();
2121

22-
//table creation fails after either of these:
23-
//OrmLiteConfig.DialectProvider.UseUnicode = true;
24-
//OrmLiteConfig.DialectProvider.UseUnicode = false;
25-
OrmLiteConfig.DialectProvider.DefaultStringLength = 123;
22+
//all of these pass now:
23+
OrmLiteConfig.DialectProvider.UseUnicode = true;
24+
_reCreateTheTable();
25+
26+
OrmLiteConfig.DialectProvider.UseUnicode = false;
27+
_reCreateTheTable();
28+
29+
OrmLiteConfig.DialectProvider.DefaultStringLength = 98765;
2630

2731
_reCreateTheTable();
2832
}

src/ServiceStack.OrmLite.PostgreSQL/PostgreSQLDialectProvider.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ namespace ServiceStack.OrmLite.PostgreSQL
99
public class PostgreSQLDialectProvider : OrmLiteDialectProviderBase<PostgreSQLDialectProvider>
1010
{
1111
public static PostgreSQLDialectProvider Instance = new PostgreSQLDialectProvider();
12+
const string textColumnDefinition = "text";
1213

1314
private PostgreSQLDialectProvider()
1415
{
@@ -22,7 +23,10 @@ private PostgreSQLDialectProvider()
2223
base.ParamString = ":";
2324
base.BlobColumnDefinition = "bytea";
2425
base.RealColumnDefinition = "double precision";
25-
base.StringLengthColumnDefinitionFormat = "text";
26+
base.StringLengthColumnDefinitionFormat = textColumnDefinition;
27+
//there is no "n"varchar in postgres. All strings are either unicode or non-unicode, inherited from the database.
28+
base.StringLengthUnicodeColumnDefinitionFormat = "character varying({0})";
29+
base.StringLengthNonUnicodeColumnDefinitionFormat = "character varying({0})";
2630
base.InitColumnTypeMap();
2731

2832
DbTypeMap.Set<TimeSpan>(DbType.Time, "Interval");
@@ -44,13 +48,11 @@ public override string GetColumnDefinition(
4448
{
4549
if (fieldLength != null)
4650
{
47-
fieldDefinition = UseUnicode
48-
? string.Format(base.StringLengthUnicodeColumnDefinitionFormat, fieldLength)
49-
: string.Format(base.StringLengthNonUnicodeColumnDefinitionFormat, fieldLength);
51+
fieldDefinition = string.Format(base.StringLengthColumnDefinitionFormat, fieldLength);
5052
}
5153
else
5254
{
53-
fieldDefinition = StringLengthColumnDefinitionFormat;
55+
fieldDefinition = textColumnDefinition;
5456
}
5557
}
5658
else

0 commit comments

Comments
 (0)