Skip to content

Commit

Permalink
fix broken tests from dbms-specific escape identifier in hardcoded st…
Browse files Browse the repository at this point in the history
…ring

add quotes in postgres build script

fix syntax error in MS Access (INNER JOIN, not JOIN)
  • Loading branch information
Ste1io committed Sep 25, 2023
1 parent 6b66918 commit f7b2470
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
11 changes: 6 additions & 5 deletions PetaPoco.Tests.Integration/Databases/BaseQueryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -324,13 +324,14 @@ public void Query_ForPocoGivenDbColumnPocoOverlapSqlStringAndParameters_ShouldRe
DB.Insert(new PocoOverlapPoco1 { Column1 = "A", Column2 = "B" });
DB.Insert(new PocoOverlapPoco2 { Column1 = "B", Column2 = "A" });

var sql = @"FROM BugInvestigation_64O6LT8U
JOIN BugInvestigation_5TN5C4U4 ON BugInvestigation_64O6LT8U.[ColumnA] = BugInvestigation_5TN5C4U4.[Column2]";

var sql = $@"FROM {DB.Provider.EscapeTableName("BugInvestigation_64O6LT8U")}
INNER JOIN {DB.Provider.EscapeTableName("BugInvestigation_5TN5C4U4")}
ON {DB.Provider.EscapeSqlIdentifier("BugInvestigation_64O6LT8U")}.{DB.Provider.EscapeSqlIdentifier("ColumnA")} = {DB.Provider.EscapeSqlIdentifier("BugInvestigation_5TN5C4U4")}.{DB.Provider.EscapeSqlIdentifier("Column2")}";
var poco1 = DB.Query<PocoOverlapPoco1>(sql).ToList().Single();

sql = @"FROM BugInvestigation_5TN5C4U4
JOIN BugInvestigation_64O6LT8U ON BugInvestigation_64O6LT8U.[ColumnA] = BugInvestigation_5TN5C4U4.[Column2]";
sql = $@"FROM {DB.Provider.EscapeTableName("BugInvestigation_5TN5C4U4")}
INNER JOIN {DB.Provider.EscapeTableName("BugInvestigation_64O6LT8U")}
ON {DB.Provider.EscapeSqlIdentifier("BugInvestigation_64O6LT8U")}.{DB.Provider.EscapeSqlIdentifier("ColumnA")} = {DB.Provider.EscapeSqlIdentifier("BugInvestigation_5TN5C4U4")}.{DB.Provider.EscapeSqlIdentifier("Column2")}";
var poco2 = DB.Query<PocoOverlapPoco2>(sql).ToList().Single();

poco1.Column1.ShouldBe("A");
Expand Down
8 changes: 4 additions & 4 deletions PetaPoco.Tests.Integration/Scripts/PostgresBuildDatabase.sql
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,16 @@ CREATE TABLE "BugInvestigation_3F489XV0" (
"TC4" INT NOT NULL
);

DROP TABLE IF EXISTS BugInvestigation_64O6LT8U;
DROP TABLE IF EXISTS "BugInvestigation_64O6LT8U";

CREATE TABLE BugInvestigation_64O6LT8U (
CREATE TABLE "BugInvestigation_64O6LT8U" (
"ColumnA" VARCHAR(20),
"Column2" VARCHAR(20)
);

DROP TABLE IF EXISTS BugInvestigation_5TN5C4U4;
DROP TABLE IF EXISTS "BugInvestigation_5TN5C4U4";

CREATE TABLE BugInvestigation_5TN5C4U4 (
CREATE TABLE "BugInvestigation_5TN5C4U4" (
"ColumnA" VARCHAR(20),
"Column2" VARCHAR(20)
);
Expand Down

0 comments on commit f7b2470

Please sign in to comment.